Handle event to change key binding for selected line. A selection of a key/binding in the list of current bindings pops up a dialog to enter a new binding. If the current key set is builtin and a binding has changed, then a name for a custom key set needs to be
(self)
| 1369 | self.button_delete_custom_keys.state(('!disabled',)) |
| 1370 | |
| 1371 | def get_new_keys(self): |
| 1372 | """Handle event to change key binding for selected line. |
| 1373 | |
| 1374 | A selection of a key/binding in the list of current |
| 1375 | bindings pops up a dialog to enter a new binding. If |
| 1376 | the current key set is builtin and a binding has |
| 1377 | changed, then a name for a custom key set needs to be |
| 1378 | entered for the change to be applied. |
| 1379 | """ |
| 1380 | list_index = self.bindingslist.index(ANCHOR) |
| 1381 | binding = self.bindingslist.get(list_index) |
| 1382 | bind_name = binding.split()[0] |
| 1383 | if self.keyset_source.get(): |
| 1384 | current_key_set_name = self.builtin_name.get() |
| 1385 | else: |
| 1386 | current_key_set_name = self.custom_name.get() |
| 1387 | current_bindings = idleConf.GetCurrentKeySet() |
| 1388 | if current_key_set_name in changes['keys']: # unsaved changes |
| 1389 | key_set_changes = changes['keys'][current_key_set_name] |
| 1390 | for event in key_set_changes: |
| 1391 | current_bindings[event] = key_set_changes[event].split() |
| 1392 | current_key_sequences = list(current_bindings.values()) |
| 1393 | new_keys = GetKeysWindow(self, 'Get New Keys', bind_name, |
| 1394 | current_key_sequences).result |
| 1395 | if new_keys: |
| 1396 | if self.keyset_source.get(): # Current key set is a built-in. |
| 1397 | message = ('Your changes will be saved as a new Custom Key Set.' |
| 1398 | ' Enter a name for your new Custom Key Set below.') |
| 1399 | new_keyset = self.get_new_keys_name(message) |
| 1400 | if not new_keyset: # User cancelled custom key set creation. |
| 1401 | self.bindingslist.select_set(list_index) |
| 1402 | self.bindingslist.select_anchor(list_index) |
| 1403 | return |
| 1404 | else: # Create new custom key set based on previously active key set. |
| 1405 | self.create_new_key_set(new_keyset) |
| 1406 | self.bindingslist.delete(list_index) |
| 1407 | self.bindingslist.insert(list_index, bind_name+' - '+new_keys) |
| 1408 | self.bindingslist.select_set(list_index) |
| 1409 | self.bindingslist.select_anchor(list_index) |
| 1410 | self.keybinding.set(new_keys) |
| 1411 | else: |
| 1412 | self.bindingslist.select_set(list_index) |
| 1413 | self.bindingslist.select_anchor(list_index) |
| 1414 | |
| 1415 | def get_new_keys_name(self, message): |
| 1416 | "Return new key set name from query popup." |
nothing calls this directly
no test coverage detected