def ApplyKeybindings(self): """Update the keybindings after they are changed""" self.Bindings.default_keydefs = keydefs = idleConf.GetCurrentKeySet() self.apply_bindings() for extensionName in self.get_standard_extension_names(): xkeydefs = idleConf.GetExtensionBindings(extensionName) if xkeydefs: self.apply_bindings(xkeydefs) menuEventDict = {} for menu in self.Bindings.menudefs: menuEventDict[menu[0]] = {} for item in menu[1]: if item: menuEventDict[menu[0]][prepstr(item[0])[1]] = item[1] for menubarItem in self.menudict.keys(): menu = self.menudict[menubarItem] end = menu.index(END) + 1 for index in range(0, end): if menu.type(index) == 'command': accel = menu.entrycget(index, 'accelerator') if accel: itemName = menu.entrycget(index, 'label') event = '' if menubarItem in menuEventDict: if itemName in menuEventDict[menubarItem]: event = menuEventDict[menubarItem][itemName] if event: accel = get_accelerator(keydefs, event) menu.entryconfig(index, accelerator=accel)
def RemoveKeybindings(self): # SUBCLASS to catch errors "Remove the keybindings before they are changed." EditorWindow._invalid_keybindings = [] # Called from configDialog.py self.Bindings.default_keydefs = keydefs = idleConf.GetCurrentKeySet() for event, keylist in keydefs.items(): for key in keylist: try: self.text.event_delete(event, key) except Exception as err: print(' Caught event_delete error:', err) print(' For %s, %s' % (event, key)) pass for extensionName in self.get_standard_extension_names(): xkeydefs = idleConf.GetExtensionBindings(extensionName) if xkeydefs: for event, keylist in xkeydefs.items(): for key in keylist: try: self.text.event_delete(event, key) except Exception as err: print(' Caught event_delete error:', err) print(' For %s, %s' % (event, key)) pass
def transfer_cfg(self, extName, confparse, keys=True): """ Transfer the configuration from the extension into IDLE's configuration. Returns True if successful. """ if confparse is None: return False # copy the user extension configuration in IDLE retval = self.copy_options(extName, idleConf.userCfg, confparse) if 0: # DEVELOPERS - this takes a long time to process # Report Any keybinding conflicts the user extension may have keyset = idleConf.GetCurrentKeySet() name_cfg = extName + '_cfgBindings' optionlist = confparse.GetOptionList(name_cfg) for option in optionlist: b = '<<%s>>' % option value = confparse.get(name_cfg, option) if value == '<Control-Key-l>': continue # WORKAROUND: skip clear window binding for event, binding in list(keyset.items()): if value in binding and event != b and value: print( '\n Warning: [%s] has an event binding conflict with' % name_cfg) print(' ', event, value) # idleConf.GetExtensionBindings pulls only from the default configuration. # Must transfer bindings to defaultCfg dictionary instead. if keys: self.copy_options(extName + '_cfgBindings', idleConf.defaultCfg, confparse) return retval
def GetNewKeys(self): listIndex = self.listBindings.index(ANCHOR) binding = self.listBindings.get(listIndex) bindName = binding.split()[0] if self.keysAreBuiltin.get(): currentKeySetName = self.builtinKeys.get() else: currentKeySetName = self.customKeys.get() currentBindings = idleConf.GetCurrentKeySet() if currentKeySetName in self.changedItems['keys'].keys(): keySetChanges = self.changedItems['keys'][currentKeySetName] for event in keySetChanges.keys(): currentBindings[event] = keySetChanges[event].split() currentKeySequences = currentBindings.values() newKeys = GetKeysDialog(self, 'Get New Keys', bindName, currentKeySequences).result if newKeys: if self.keysAreBuiltin.get(): message = 'Your changes will be saved as a new Custom Key Set. ' + 'Enter a name for your new Custom Key Set below.' newKeySet = self.GetNewKeysName(message) if not newKeySet: self.listBindings.select_set(listIndex) self.listBindings.select_anchor(listIndex) return self.CreateNewKeySet(newKeySet) self.listBindings.delete(listIndex) self.listBindings.insert(listIndex, bindName + ' - ' + newKeys) self.listBindings.select_set(listIndex) self.listBindings.select_anchor(listIndex) self.keyBinding.set(newKeys) else: self.listBindings.select_set(listIndex) self.listBindings.select_anchor(listIndex)
def RemoveKeybindings(self): """Remove the keybindings before they are changed.""" self.Bindings.default_keydefs = keydefs = idleConf.GetCurrentKeySet() for event, keylist in keydefs.items(): self.text.event_delete(event, *keylist) for extensionName in self.get_standard_extension_names(): xkeydefs = idleConf.GetExtensionBindings(extensionName) if xkeydefs: for event, keylist in xkeydefs.items(): self.text.event_delete(event, *keylist)
def initialise(): import sys global menudefs global default_keydefs if menudefs is not None: return menudefs = [ # underscore prefixes character to underscore #('file', [ # ]), ('edit', [ ('_Undo', '<<undo>>'), ('_Redo', '<<redo>>'), None, ('Cu_t', '<<cut>>'), ('_Copy', '<<copy>>'), ('_Paste', '<<paste>>'), ('Select _All', '<<select-all>>'), None, ('_Find...', '<<find>>'), ('Find A_gain', '<<find-again>>'), ('Find _Selection', '<<find-selection>>'), ('Find in Files...', '<<find-in-files>>'), ('R_eplace...', '<<replace>>'), ('Go to _Line', '<<goto-line>>'), ]), ('format', [ ('_Indent Region', '<<indent-region>>'), ('_Dedent Region', '<<dedent-region>>'), ('Comment _Out Region', '<<comment-region>>'), ('U_ncomment Region', '<<uncomment-region>>'), ('Tabify Region', '<<tabify-region>>'), ('Untabify Region', '<<untabify-region>>'), ('Toggle Tabs', '<<toggle-tabs>>'), ('New Indent Width', '<<change-indentwidth>>'), ]), ] if macosxSupport.runningAsOSXApp(): # Running as a proper MacOS application bundle. This block restructures # the menus a little to make them conform better to the HIG. quitItem = menudefs[0][1][-1] closeItem = menudefs[0][1][-2] default_keydefs = idleConf.GetCurrentKeySet()
def main(): handle_ipython_argv(sys.argv) pythonw_workaround() _hotpatch() macosx_workaround() install_idlex_manager() extensionManager.load_idlex_extensions() # Force a reset on Bindings... # Without this, user reconfiguration of the key bindings within IDLE may # generate an error on MultiCall unbind. import idlelib.Bindings idlelib.Bindings.default_keydefs = idleConf.GetCurrentKeySet() import idlelib.PyShell idlelib.PyShell.main()
def main(): pythonw_workaround() _hotpatch() fix_tk86() try: macosx_workaround() except: pass # Tk on OSX should not be this fragile... install_idlex_manager() extensionManager.load_idlex_extensions() # Force a reset on Bindings... # Without this, user reconfiguration of the key bindings within IDLE may # generate an error on MultiCall unbind. import idlelib.Bindings idlelib.Bindings.default_keydefs = idleConf.GetCurrentKeySet() import idlelib.PyShell idlelib.PyShell.main()
('Python _Docs', '<<python-docs>>'), ]), ] if macosxSupport.runningAsOSXApp(): # Running as a proper MacOS application bundle. This block restructures # the menus a little to make them conform better to the HIG. quitItem = menudefs[0][1][-1] closeItem = menudefs[0][1][-2] # Remove the last 3 items of the file menu: a separator, close window and # quit. Close window will be reinserted just above the save item, where # it should be according to the HIG. Quit is in the application menu. del menudefs[0][1][-3:] menudefs[0][1].insert(6, closeItem) # Remove the 'About' entry from the help menu, it is in the application # menu del menudefs[-1][1][0:2] menudefs.insert(0, ('application', [ ('About IDLE', '<<about-idle>>'), None, ('_Preferences....', '<<open-config-dialog>>'), ])) default_keydefs = idleConf.GetCurrentKeySet() del sys
def initialise(): import sys global menudefs global default_keydefs if menudefs is not None: return menudefs = [ # underscore prefixes character to underscore ( 'file', [ ('Load From...', '<<load-from>>'), ('Revert', '<<revert>>'), None, ('_Save', '<<save-window>>'), #('Save _As...', '<<save-window-as-file>>'), ('Save Cop_y As...', '<<save-copy-of-window-as-file>>'), None, ('Prin_t Window', '<<print-window>>'), None, ('_Close', '<<close-window>>'), ('E_xit', '<<close-all-windows>>'), ]), ('edit', [ ('_Undo', '<<undo>>'), ('_Redo', '<<redo>>'), None, ('Cu_t', '<<cut>>'), ('_Copy', '<<copy>>'), ('_Paste', '<<paste>>'), ('Select _All', '<<select-all>>'), None, ('_Find...', '<<find>>'), ('Find A_gain', '<<find-again>>'), ('Find _Selection', '<<find-selection>>'), ('Find in Files...', '<<find-in-files>>'), ('R_eplace...', '<<replace>>'), ('Go to _Line', '<<goto-line>>'), ]), ('format', [ ('_Indent Region', '<<indent-region>>'), ('_Dedent Region', '<<dedent-region>>'), ('Comment _Out Region', '<<comment-region>>'), ('U_ncomment Region', '<<uncomment-region>>'), ('Tabify Region', '<<tabify-region>>'), ('Untabify Region', '<<untabify-region>>'), ('Toggle Tabs', '<<toggle-tabs>>'), ('New Indent Width', '<<change-indentwidth>>'), ]), ('options', [ ('_Configure IDLE...', '<<open-config-dialog>>'), None, ]), ("check", [("Check F5", '<<check>>')]), ("online", [("Login", '<<login>>'), ("Logout", '<<logout>>'), ("Change Password", '<<change_password>>'), None, ("Upload Problem Answer", '<<upload_answer>>'), ("Download Problem Answer", '<<download_answer>>'), None, ("Submit Answer F6", '<<submit_answer>>'), ("Show Submissions", '<<show_submit>>')]), ('help', [ ('_About IDLE', '<<about-idle>>'), None, ('_IDLE Help', '<<help>>'), ('Python _Docs', '<<python-docs>>'), None, ('About _Tutor', '<<about-tutor>>'), ('Tutor Help', '<<help-tutor>>'), ]), ] if macosxSupport.runningAsOSXApp(): # Running as a proper MacOS application bundle. This block restructures # the menus a little to make them conform better to the HIG. quitItem = menudefs[0][1][-1] closeItem = menudefs[0][1][-2] # Remove the last 3 items of the file menu: a separator, close window and # quit. Close window will be reinserted just above the save item, where # it should be according to the HIG. Quit is in the application menu. del menudefs[0][1][-3:] menudefs[0][1].insert(6, closeItem) # Remove the 'About' entry from the help menu, it is in the application # menu del menudefs[-1][1][0:2] menudefs.insert(0, ('application', [ ('About IDLE', '<<about-idle>>'), None, ('_Preferences....', '<<open-config-dialog>>'), ])) default_keydefs = idleConf.GetCurrentKeySet()