Add a key to the key map.
(self, key: str, command: str, contexts: Sequence[str], help="")
| 87 | self.binding_for_help.cache_clear() |
| 88 | |
| 89 | def add(self, key: str, command: str, contexts: Sequence[str], help="") -> None: |
| 90 | """ |
| 91 | Add a key to the key map. |
| 92 | """ |
| 93 | self._check_contexts(contexts) |
| 94 | |
| 95 | for b in self.bindings: |
| 96 | if b.key == key and b.command.strip() == command.strip(): |
| 97 | b.contexts = sorted(list(set(b.contexts + contexts))) |
| 98 | if help: |
| 99 | b.help = help |
| 100 | self.bind(b) |
| 101 | break |
| 102 | else: |
| 103 | self.remove(key, contexts) |
| 104 | b = Binding(key=key, command=command, contexts=contexts, help=help) |
| 105 | self.bindings.append(b) |
| 106 | self.bind(b) |
| 107 | self._on_change() |
| 108 | |
| 109 | def remove(self, key: str, contexts: Sequence[str]) -> None: |
| 110 | """ |