def postwindowsmenu(menu=menu): end = menu.index('end') if end is None: end = -1 if end > 0: menu.delete(0, end) WindowList.add_windows_to_menu(menu)
def postwindowsmenu(menu=menu): end = menu.index("end") if end is None: end = -1 if end > 0: menu.delete(0, end) WindowList.add_windows_to_menu(menu)
def postwindowsmenu(self): # Only called when Windows menu exists menu = self.menudict['windows'] end = menu.index("end") if end is None: end = -1 if end > self.wmenu_end: menu.delete(self.wmenu_end + 1, end) WindowList.add_windows_to_menu(menu)
def postwindowsmenu(self): # Only called when Windows menu exists menu = self.menudict['windows'] end = menu.index("end") if end is None: end = -1 if end > self.wmenu_end: menu.delete(self.wmenu_end+1, end) WindowList.add_windows_to_menu(menu)
def _close(self): WindowList.unregister_callback(self.postwindowsmenu) self._unload_extensions() self.tkinter_vars = None for page in self.text_notebook.pages.itervalues(): page.editpage.close() self.top.destroy() if self.close_hook: # unless override: unregister from flist, terminate if last window self.close_hook()
def postwindowsmenu(self): # Only called when Windows menu exists # XXX Actually, this Just-In-Time updating interferes badly # XXX with the tear-off feature. It would be better to update # XXX all Windows menus whenever the list of windows changes. menu = self.menudict['windows'] end = menu.index("end") if end is None: end = -1 if end > self.wmenu_end: menu.delete(self.wmenu_end + 1, end) WindowList.add_windows_to_menu(menu)
def postwindowsmenu(self): # Only called when Windows menu exists # XXX Actually, this Just-In-Time updating interferes badly # XXX with the tear-off feature. It would be better to update # XXX all Windows menus whenever the list of windows changes. menu = self.menudict['windows'] end = menu.index("end") if end is None: end = -1 if end > self.wmenu_end: menu.delete(self.wmenu_end+1, end) WindowList.add_windows_to_menu(menu)
def close(self): self.top.wm_deiconify() self.top.tkraise() reply = self.maybesave() if reply != "cancel": WindowList.unregister_callback(self.postwindowsmenu) if self.close_hook: self.close_hook() colorizing = 0 if self.color: colorizing = self.color.colorizing doh = colorizing and self.top self.color.close(doh) # Cancel colorization if not colorizing: self.top.destroy() return reply
def _close(self): WindowList.unregister_callback(self.postwindowsmenu) if self.close_hook: self.close_hook() self.flist = None colorizing = 0 self.unload_extensions() self.io.close(); self.io = None self.undo = None # XXX if self.color: colorizing = self.color.colorizing doh = colorizing and self.top self.color.close(doh) # Cancel colorization self.text = None self.vars = None self.per.close(); self.per = None if not colorizing: self.top.destroy()
def _close(self): WindowList.unregister_callback(self.postwindowsmenu) if self.close_hook: self.close_hook() self.flist = None colorizing = 0 self.unload_extensions() self.io.close() self.io = None self.undo = None # XXX if self.color: colorizing = self.color.colorizing doh = colorizing and self.top self.color.close(doh) # Cancel colorization self.text = None self.vars = None self.per.close() self.per = None if not colorizing: self.top.destroy()
def __init__(self, window_in, root_in): self.window = window_in self.root = root_in self.assets = AssetHandler.ImageHandler( os.path.join(os.environ['PAS_BASE'], 'UIControl/assets')) self.windows = WindowList.WindowList(self.window.windowList) self.glWindowWid = 1011 self.glWindowHei = 681 self.glWindowX = 240 self.glWindowY = 10 self.ConfigureTkWidgets()
def __init__(self, flist=None, filename=None, key=None, root=None): edconf = idleconf.getsection('EditorWindow') coconf = idleconf.getsection('Colors') self.flist = flist root = root or flist.root self.root = root if flist: self.vars = flist.vars self.menubar = Menu(root) self.top = top = self.Toplevel(root, menu=self.menubar) self.vbar = vbar = Scrollbar(top, name='vbar') self.text_frame = text_frame = Frame(top) self.text = text = Text(text_frame, name='text', padx=5, foreground=coconf.getdef('normal-foreground'), background=coconf.getdef('normal-background'), highlightcolor=coconf.getdef('hilite-foreground'), highlightbackground=coconf.getdef('hilite-background'), insertbackground=coconf.getdef('cursor-background'), width=edconf.getint('width'), height=edconf.getint('height'), wrap="none") self.createmenubar() self.apply_bindings() self.top.protocol("WM_DELETE_WINDOW", self.close) self.top.bind("<<close-window>>", self.close_event) text.bind("<<center-insert>>", self.center_insert_event) text.bind("<<help>>", self.help_dialog) text.bind("<<python-docs>>", self.python_docs) text.bind("<<about-idle>>", self.about_dialog) text.bind("<<open-module>>", self.open_module) text.bind("<<do-nothing>>", lambda event: "break") text.bind("<<select-all>>", self.select_all) text.bind("<<remove-selection>>", self.remove_selection) text.bind("<3>", self.right_menu_event) if flist: flist.inversedict[self] = key if key: flist.dict[key] = self text.bind("<<open-new-window>>", self.flist.new_callback) text.bind("<<close-all-windows>>", self.flist.close_all_callback) text.bind("<<open-class-browser>>", self.open_class_browser) text.bind("<<open-path-browser>>", self.open_path_browser) vbar['command'] = text.yview vbar.pack(side=RIGHT, fill=Y) text['yscrollcommand'] = vbar.set text['font'] = edconf.get('font-name'), edconf.get('font-size') text_frame.pack(side=LEFT, fill=BOTH, expand=1) text.pack(side=TOP, fill=BOTH, expand=1) text.focus_set() self.per = per = self.Percolator(text) if self.ispythonsource(filename): self.color = color = self.ColorDelegator(); per.insertfilter(color) ##print "Initial colorizer" else: ##print "No initial colorizer" self.color = None self.undo = undo = self.UndoDelegator(); per.insertfilter(undo) self.io = io = self.IOBinding(self) text.undo_block_start = undo.undo_block_start text.undo_block_stop = undo.undo_block_stop undo.set_saved_change_hook(self.saved_change_hook) io.set_filename_change_hook(self.filename_change_hook) if filename: if os.path.exists(filename): io.loadfile(filename) else: io.set_filename(filename) self.saved_change_hook() self.load_extensions() menu = self.menudict.get('windows') if menu: end = menu.index("end") if end is None: end = -1 if end >= 0: menu.add_separator() end = end + 1 self.wmenu_end = end WindowList.register_callback(self.postwindowsmenu) # Some abstractions so IDLE extensions are cross-IDE self.askyesno = tkMessageBox.askyesno self.askinteger = tkSimpleDialog.askinteger self.showerror = tkMessageBox.showerror if self.extensions.has_key('AutoIndent'): self.extensions['AutoIndent'].set_indentation_params( self.ispythonsource(filename)) self.set_status_bar()
def overrideRootMenu(root, flist): """ Replace the Tk root menu by something that is more appropriate for IDLE with an Aqua Tk. """ # The menu that is attached to the Tk root (".") is also used by AquaTk for # all windows that don't specify a menu of their own. The default menubar # contains a number of menus, none of which are appropriate for IDLE. The # Most annoying of those is an 'About Tck/Tk...' menu in the application # menu. # # This function replaces the default menubar by a mostly empty one, it # should only contain the correct application menu and the window menu. # # Due to a (mis-)feature of TkAqua the user will also see an empty Help # menu. from tkinter import Menu import Bindings import WindowList closeItem = Bindings.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 Bindings.menudefs[0][1][-3:] Bindings.menudefs[0][1].insert(6, closeItem) # Remove the 'About' entry from the help menu, it is in the application # menu del Bindings.menudefs[-1][1][0:2] # Remove the 'Configure Idle' entry from the options menu, it is in the # application menu as 'Preferences' del Bindings.menudefs[-2][1][0] menubar = Menu(root) root.configure(menu=menubar) menudict = {} menudict['windows'] = menu = Menu(menubar, name='windows', tearoff=0) menubar.add_cascade(label='Window', menu=menu, underline=0) def postwindowsmenu(menu=menu): end = menu.index('end') if end is None: end = -1 if end > 0: menu.delete(0, end) WindowList.add_windows_to_menu(menu) WindowList.register_callback(postwindowsmenu) def about_dialog(event=None): "Handle Help 'About IDLE' event." # Synchronize with EditorWindow.EditorWindow.about_dialog. import aboutDialog aboutDialog.AboutDialog(root, 'About IDLE') def config_dialog(event=None): "Handle Options 'Configure IDLE' event." # Synchronize with EditorWindow.EditorWindow.config_dialog. import configDialog # Ensure that the root object has an instance_dict attribute, # mirrors code in EditorWindow (although that sets the attribute # on an EditorWindow instance that is then passed as the first # argument to ConfigDialog) root.instance_dict = flist.inversedict configDialog.ConfigDialog(root, 'Settings') def help_dialog(event=None): "Handle Help 'IDLE Help' event." # Synchronize with EditorWindow.EditorWindow.help_dialog. import help help.show_idlehelp(root) root.bind('<<about-idle>>', about_dialog) root.bind('<<open-config-dialog>>', config_dialog) root.createcommand('::tk::mac::ShowPreferences', config_dialog) if flist: root.bind('<<close-all-windows>>', flist.close_all_callback) # The binding above doesn't reliably work on all versions of Tk # on MacOSX. Adding command definition below does seem to do the # right thing for now. root.createcommand('exit', flist.close_all_callback) if isCarbonTk(): # for Carbon AquaTk, replace the default Tk apple menu menudict['application'] = menu = Menu(menubar, name='apple', tearoff=0) menubar.add_cascade(label='IDLE', menu=menu) Bindings.menudefs.insert(0, ('application', [ ('About IDLE', '<<about-idle>>'), None, ])) tkversion = root.tk.eval('info patchlevel') if tuple(map(int, tkversion.split('.'))) < (8, 4, 14): # for earlier AquaTk versions, supply a Preferences menu item Bindings.menudefs[0][1].append( ('_Preferences....', '<<open-config-dialog>>'), ) if isCocoaTk(): # replace default About dialog with About IDLE one root.createcommand('tkAboutDialog', about_dialog) # replace default "Help" item in Help menu root.createcommand('::tk::mac::ShowHelp', help_dialog) # remove redundant "IDLE Help" from menu del Bindings.menudefs[-1][1][0]
def __init__(self, flist=None, filename=None, key=None, root=None): self.flist = flist root = root or flist.root self.root = root if flist: self.vars = flist.vars self.menubar = Menu(root) self.top = top = self.Toplevel(root, menu=self.menubar) self.vbar = vbar = Scrollbar(top, name='vbar') self.text = text = Text(top, name='text', padx=5, background="white", wrap="none") self.createmenubar() self.apply_bindings() self.top.protocol("WM_DELETE_WINDOW", self.close) self.top.bind("<<close-window>>", self.close_event) text.bind("<<center-insert>>", self.center_insert_event) text.bind("<<help>>", self.help_dialog) text.bind("<<about-idle>>", self.about_dialog) text.bind("<<open-module>>", self.open_module) text.bind("<<do-nothing>>", lambda event: "break") text.bind("<<select-all>>", self.select_all) text.bind("<<remove-selection>>", self.remove_selection) text.bind("<3>", self.right_menu_event) if flist: flist.inversedict[self] = key if key: flist.dict[key] = self text.bind("<<open-new-window>>", self.flist.new_callback) text.bind("<<close-all-windows>>", self.flist.close_all_callback) text.bind("<<open-class-browser>>", self.open_class_browser) text.bind("<<open-path-browser>>", self.open_path_browser) vbar['command'] = text.yview vbar.pack(side=RIGHT, fill=Y) text['yscrollcommand'] = vbar.set if sys.platform[:3] == 'win': text['font'] = ("lucida console", 8) text.pack(side=LEFT, fill=BOTH, expand=1) text.focus_set() self.per = per = self.Percolator(text) if self.ispythonsource(filename): self.color = color = self.ColorDelegator(); per.insertfilter(color) ##print "Initial colorizer" else: ##print "No initial colorizer" self.color = None self.undo = undo = self.UndoDelegator(); per.insertfilter(undo) self.io = io = self.IOBinding(self) undo.set_saved_change_hook(self.saved_change_hook) io.set_filename_change_hook(self.filename_change_hook) if filename: if os.path.exists(filename): io.loadfile(filename) else: io.set_filename(filename) self.saved_change_hook() self.load_extensions() menu = self.menudict.get('windows') if menu: end = menu.index("end") if end is None: end = -1 if end >= 0: menu.add_separator() end = end + 1 self.wmenu_end = end WindowList.register_callback(self.postwindowsmenu)
def overrideRootMenu(root, flist): """ Replace the Tk root menu by something that's more appropriate for IDLE. """ # The menu that is attached to the Tk root (".") is also used by AquaTk for # all windows that don't specify a menu of their own. The default menubar # contains a number of menus, none of which are appropriate for IDLE. The # Most annoying of those is an 'About Tck/Tk...' menu in the application # menu. # # This function replaces the default menubar by a mostly empty one, it # should only contain the correct application menu and the window menu. # # Due to a (mis-)feature of TkAqua the user will also see an empty Help # menu. from Tkinter import Menu, Text, Text from EditorWindow import prepstr, get_accelerator import Bindings import WindowList from MultiCall import MultiCallCreator menubar = Menu(root) root.configure(menu=menubar) menudict = {} menudict["windows"] = menu = Menu(menubar, name="windows") menubar.add_cascade(label="Window", menu=menu, underline=0) def postwindowsmenu(menu=menu): end = menu.index("end") if end is None: end = -1 if end > 0: menu.delete(0, end) WindowList.add_windows_to_menu(menu) WindowList.register_callback(postwindowsmenu) menudict["application"] = menu = Menu(menubar, name="apple") menubar.add_cascade(label="IDLE", menu=menu) def about_dialog(event=None): import aboutDialog aboutDialog.AboutDialog(root, "About IDLE") def config_dialog(event=None): import configDialog root.instance_dict = flist.inversedict configDialog.ConfigDialog(root, "Settings") root.bind("<<about-idle>>", about_dialog) root.bind("<<open-config-dialog>>", config_dialog) if flist: root.bind("<<close-all-windows>>", flist.close_all_callback) ###check if Tk version >= 8.4.14; if so, use hard-coded showprefs binding tkversion = root.tk.eval("info patchlevel") # Note: we cannot check if the string tkversion >= '8.4.14', because # the string '8.4.7' is greater than the string '8.4.14'. if tuple(map(int, tkversion.split("."))) >= (8, 4, 14): Bindings.menudefs[0] = ("application", [("About IDLE", "<<about-idle>>"), None]) root.createcommand("::tk::mac::ShowPreferences", config_dialog) else: for mname, entrylist in Bindings.menudefs: menu = menudict.get(mname) if not menu: continue else: for entry in entrylist: if not entry: menu.add_separator() else: label, eventname = entry underline, label = prepstr(label) accelerator = get_accelerator(Bindings.default_keydefs, eventname) def command(text=root, eventname=eventname): text.event_generate(eventname) menu.add_command(label=label, underline=underline, command=command, accelerator=accelerator)
def __init__(self, flist=None, filename=None, key=None, root=None): edconf = idleconf.getsection('EditorWindow') coconf = idleconf.getsection('Colors') self.flist = flist root = root or flist.root self.root = root if flist: self.vars = flist.vars self.menubar = Menu(root) self.top = top = self.Toplevel(root, menu=self.menubar) self.vbar = vbar = Scrollbar(top, name='vbar') self.text_frame = text_frame = Frame(top) self.text = text = Text( text_frame, name='text', padx=5, foreground=coconf.getdef('normal-foreground'), background=coconf.getdef('normal-background'), highlightcolor=coconf.getdef('hilite-foreground'), highlightbackground=coconf.getdef('hilite-background'), insertbackground=coconf.getdef('cursor-background'), width=edconf.getint('width'), height=edconf.getint('height'), wrap="none") self.createmenubar() self.apply_bindings() self.top.protocol("WM_DELETE_WINDOW", self.close) self.top.bind("<<close-window>>", self.close_event) text.bind("<<center-insert>>", self.center_insert_event) text.bind("<<help>>", self.help_dialog) text.bind("<<python-docs>>", self.python_docs) text.bind("<<about-idle>>", self.about_dialog) text.bind("<<open-module>>", self.open_module) text.bind("<<do-nothing>>", lambda event: "break") text.bind("<<select-all>>", self.select_all) text.bind("<<remove-selection>>", self.remove_selection) text.bind("<3>", self.right_menu_event) if flist: flist.inversedict[self] = key if key: flist.dict[key] = self text.bind("<<open-new-window>>", self.flist.new_callback) text.bind("<<close-all-windows>>", self.flist.close_all_callback) text.bind("<<open-class-browser>>", self.open_class_browser) text.bind("<<open-path-browser>>", self.open_path_browser) vbar['command'] = text.yview vbar.pack(side=RIGHT, fill=Y) text['yscrollcommand'] = vbar.set text['font'] = edconf.get('font-name'), edconf.get('font-size') text_frame.pack(side=LEFT, fill=BOTH, expand=1) text.pack(side=TOP, fill=BOTH, expand=1) text.focus_set() self.per = per = self.Percolator(text) if self.ispythonsource(filename): self.color = color = self.ColorDelegator() per.insertfilter(color) ##print "Initial colorizer" else: ##print "No initial colorizer" self.color = None self.undo = undo = self.UndoDelegator() per.insertfilter(undo) self.io = io = self.IOBinding(self) text.undo_block_start = undo.undo_block_start text.undo_block_stop = undo.undo_block_stop undo.set_saved_change_hook(self.saved_change_hook) io.set_filename_change_hook(self.filename_change_hook) if filename: if os.path.exists(filename): io.loadfile(filename) else: io.set_filename(filename) self.saved_change_hook() self.load_extensions() menu = self.menudict.get('windows') if menu: end = menu.index("end") if end is None: end = -1 if end >= 0: menu.add_separator() end = end + 1 self.wmenu_end = end WindowList.register_callback(self.postwindowsmenu) # Some abstractions so IDLE extensions are cross-IDE self.askyesno = tkMessageBox.askyesno self.askinteger = tkSimpleDialog.askinteger self.showerror = tkMessageBox.showerror if self.extensions.has_key('AutoIndent'): self.extensions['AutoIndent'].set_indentation_params( self.ispythonsource(filename)) self.set_status_bar()
def __init__(self, flist=None, filename=None, key=None, root=None, start_page=EditorPage): if EditorWindow.help_url is None: dochome = os.path.join(sys.prefix, 'Doc', 'index.html') if sys.platform.count('linux'): # look for html docs in a couple of standard places pyver = 'python-docs-' + '%s.%s.%s' % sys.version_info[:3] if os.path.isdir('/var/www/html/python/'): # "python2" rpm dochome = '/var/www/html/python/index.html' else: basepath = '/usr/share/doc/' # standard location dochome = os.path.join(basepath, pyver, 'Doc', 'index.html') elif sys.platform[:3] == 'win': chmfile = os.path.join(sys.prefix, 'Doc', 'Python%d%d.chm' % sys.version_info[:2]) if os.path.isfile(chmfile): dochome = chmfile elif macosxSupport.runningAsOSXApp(): # documentation is stored inside the python framework dochome = os.path.join( sys.prefix, 'Resources/English.lproj/Documentation/index.html') dochome = os.path.normpath(dochome) if os.path.isfile(dochome): EditorWindow.help_url = dochome if sys.platform == 'darwin': # Safari requires real file:-URLs EditorWindow.help_url = 'file://' + EditorWindow.help_url else: EditorWindow.help_url = "http://www.python.org/doc/current" self.flist = flist root = root or flist.root self.root = root try: sys.ps1 except AttributeError: sys.ps1 = '>>> ' self.menubar = Menu(root) self.top = WindowList.ListedToplevel(root, menu=self.menubar) if flist: self.tkinter_vars = flist.vars # self.top.instance_dict makes flist.inversedict avalable to # configDialog.py so it can access all EditorWindow instaces self.top.instance_dict = flist.inversedict else: self.tkinter_vars = {} # keys: Tkinter event names # values: Tkinter variable instances self.top.instance_dict = {} self.recent_files_path = os.path.join(idleConf.GetUserCfgDir(), 'recent-files.lst') if flist: flist.inversedict[self] = key if key: flist.dict[key] = self self.menudict = None # create a Notebook where the text pages for this EditorWindow will # reside self.text_notebook = TabbedPageSet(self.top) self.text_notebook.pack(fill=BOTH, expand=True) self.text_notebook.bind('<<NotebookTabChanged>>', self._update_controls) self.new_tab(filename=filename, load_ext=False, ptype=start_page) self.text = self.current_page.text # XXX self.top.focused_widget = self.text self.top.bind('<<tab-closed>>', self._post_tab_close) # The following "width" attribute is used by PyShell, so keep it here self.width = idleConf.GetOption('main', 'EditorPage', 'width') self.top.protocol("WM_DELETE_WINDOW", self.close) self.top.bind("<<close-window>>", self.close_event) self._create_statusbar() self.top.after_idle(self.set_line_and_column) # usetabs true -> literal tab characters are used by indent and # dedent cmds, possibly mixed with spaces if # indentwidth is not a multiple of tabwidth, # which will cause Tabnanny to nag! # false -> tab characters are converted to spaces by indent # and dedent cmds, and ditto TAB keystrokes # Although use-spaces=0 can be configured manually in config-main.def, # configuration of tabs v. spaces is not supported in the configuration # dialog. IDLE promotes the preferred Python indentation: use spaces! usespaces = idleConf.GetOption('main', 'Indent', 'use-spaces', type='bool') self.usetabs = not usespaces # tabwidth is the display width of a literal tab character. # CAUTION: telling Tk to use anything other than its default # tab setting causes it to use an entirely different tabbing algorithm, # treating tab stops as fixed distances from the left margin. # Nobody expects this, so for now tabwidth should never be changed. self.tabwidth = 8 # must remain 8 until Tk is fixed. # indentwidth is the number of screen characters per indent level. # The recommended Python indentation is four spaces. self.indentwidth = self.tabwidth self.set_notabs_indentwidth() # If context_use_ps1 is true, parsing searches back for a ps1 line; # else searches for a popular (if, def, ...) Python stmt. self.context_use_ps1 = False # When searching backwards for a reliable place to begin parsing, # first start num_context_lines[0] lines back, then # num_context_lines[1] lines back if that didn't work, and so on. # The last value should be huge (larger than the # of lines in a # conceivable file). # Making the initial values larger slows things down more often. self.num_context_lines = 50, 500, 5000000 if hasattr(self, 'ispythonsource'): # PyShell self.set_indentation_params(self.ispythonsource(filename)) else: self.set_indentation_params( self.current_page.ispythonsource(filename)) self.extensions = {} self._load_extensions() menu = self.menudict.get('windows') if menu: end = menu.index("end") if end is None: end = -1 if end >= 0: menu.add_separator() end = end + 1 self.wmenu_end = end WindowList.register_callback(self.postwindowsmenu) # Some abstractions so IDLE extensions are cross-IDE self.askyesno = tkMessageBox.askyesno self.askinteger = tkSimpleDialog.askinteger self.showerror = tkMessageBox.showerror
def overrideRootMenu(root, flist): """ Replace the Tk root menu by something that's more appropriate for IDLE. """ # The menu that is attached to the Tk root (".") is also used by AquaTk for # all windows that don't specify a menu of their own. The default menubar # contains a number of menus, none of which are appropriate for IDLE. The # Most annoying of those is an 'About Tck/Tk...' menu in the application # menu. # # This function replaces the default menubar by a mostly empty one, it # should only contain the correct application menu and the window menu. # # Due to a (mis-)feature of TkAqua the user will also see an empty Help # menu. from Tkinter import Menu, Text, Text from EditorWindow import prepstr, get_accelerator import Bindings import WindowList from MultiCall import MultiCallCreator menubar = Menu(root) root.configure(menu=menubar) menudict = {} menudict['windows'] = menu = Menu(menubar, name='windows') menubar.add_cascade(label='Window', menu=menu, underline=0) def postwindowsmenu(menu=menu): end = menu.index('end') if end is None: end = -1 if end > 0: menu.delete(0, end) WindowList.add_windows_to_menu(menu) WindowList.register_callback(postwindowsmenu) menudict['application'] = menu = Menu(menubar, name='apple') menubar.add_cascade(label='IDLE', menu=menu) def about_dialog(event=None): import aboutDialog aboutDialog.AboutDialog(root, 'About IDLE') def config_dialog(event=None): import configDialog configDialog.ConfigDialog(root, 'Settings') root.bind('<<about-idle>>', about_dialog) root.bind('<<open-config-dialog>>', config_dialog) if flist: root.bind('<<close-all-windows>>', flist.close_all_callback) for mname, entrylist in Bindings.menudefs: menu = menudict.get(mname) if not menu: continue for entry in entrylist: if not entry: menu.add_separator() else: label, eventname = entry underline, label = prepstr(label) accelerator = get_accelerator(Bindings.default_keydefs, eventname) def command(text=root, eventname=eventname): text.event_generate(eventname) menu.add_command(label=label, underline=underline, command=command, accelerator=accelerator)
import sys
def overrideRootMenu(root, flist): """ Replace the Tk root menu by something that's more appropriate for IDLE. """ # The menu that is attached to the Tk root (".") is also used by AquaTk for # all windows that don't specify a menu of their own. The default menubar # contains a number of menus, none of which are appropriate for IDLE. The # Most annoying of those is an 'About Tck/Tk...' menu in the application # menu. # # This function replaces the default menubar by a mostly empty one, it # should only contain the correct application menu and the window menu. # # Due to a (mis-)feature of TkAqua the user will also see an empty Help # menu. from Tkinter import Menu, Text, Text from EditorWindow import prepstr, get_accelerator import Bindings import WindowList from MultiCall import MultiCallCreator menubar = Menu(root) root.configure(menu=menubar) menudict = {} menudict['windows'] = menu = Menu(menubar, name='windows') menubar.add_cascade(label='Window', menu=menu, underline=0) def postwindowsmenu(menu=menu): end = menu.index('end') if end is None: end = -1 if end > 0: menu.delete(0, end) WindowList.add_windows_to_menu(menu) WindowList.register_callback(postwindowsmenu) menudict['application'] = menu = Menu(menubar, name='apple') menubar.add_cascade(label='IDLE', menu=menu) def about_dialog(event=None): import aboutDialog aboutDialog.AboutDialog(root, 'About IDLE') def config_dialog(event=None): import configDialog root.instance_dict = flist.inversedict configDialog.ConfigDialog(root, 'Settings') root.bind('<<about-idle>>', about_dialog) root.bind('<<open-config-dialog>>', config_dialog) if flist: root.bind('<<close-all-windows>>', flist.close_all_callback) root.createcommand('exit', flist.close_all_callback) ###check if Tk version >= 8.4.14; if so, use hard-coded showprefs binding tkversion = root.tk.eval('info patchlevel') # Note: we cannot check if the string tkversion >= '8.4.14', because # the string '8.4.7' is greater than the string '8.4.14'. if tuple(map(int, tkversion.split('.'))) >= (8, 4, 14): Bindings.menudefs[0] = ('application', [ ('About IDLE', '<<about-idle>>'), None, ]) root.createcommand('::tk::mac::ShowPreferences', config_dialog) else: for mname, entrylist in Bindings.menudefs: menu = menudict.get(mname) if not menu: continue else: for entry in entrylist: if not entry: menu.add_separator() else: label, eventname = entry underline, label = prepstr(label) accelerator = get_accelerator(Bindings.default_keydefs, eventname) def command(text=root, eventname=eventname): text.event_generate(eventname) menu.add_command(label=label, underline=underline, command=command, accelerator=accelerator)
def __init__(self, flist=None, filename=None, key=None, root=None, start_page=EditorPage): if EditorWindow.help_url is None: dochome = os.path.join(sys.prefix, 'Doc', 'index.html') if sys.platform.count('linux'): # look for html docs in a couple of standard places pyver = 'python-docs-' + '%s.%s.%s' % sys.version_info[:3] if os.path.isdir('/var/www/html/python/'): # "python2" rpm dochome = '/var/www/html/python/index.html' else: basepath = '/usr/share/doc/' # standard location dochome = os.path.join(basepath, pyver, 'Doc', 'index.html') elif sys.platform[:3] == 'win': chmfile = os.path.join(sys.prefix, 'Doc', 'Python%d%d.chm' % sys.version_info[:2]) if os.path.isfile(chmfile): dochome = chmfile elif macosxSupport.runningAsOSXApp(): # documentation is stored inside the python framework dochome = os.path.join(sys.prefix, 'Resources/English.lproj/Documentation/index.html') dochome = os.path.normpath(dochome) if os.path.isfile(dochome): EditorWindow.help_url = dochome if sys.platform == 'darwin': # Safari requires real file:-URLs EditorWindow.help_url = 'file://' + EditorWindow.help_url else: EditorWindow.help_url = "http://www.python.org/doc/current" self.flist = flist root = root or flist.root self.root = root try: sys.ps1 except AttributeError: sys.ps1 = '>>> ' self.menubar = Menu(root) self.top = WindowList.ListedToplevel(root, menu=self.menubar) if flist: self.tkinter_vars = flist.vars # self.top.instance_dict makes flist.inversedict avalable to # configDialog.py so it can access all EditorWindow instaces self.top.instance_dict = flist.inversedict else: self.tkinter_vars = {} # keys: Tkinter event names # values: Tkinter variable instances self.top.instance_dict = {} self.recent_files_path = os.path.join(idleConf.GetUserCfgDir(), 'recent-files.lst') if flist: flist.inversedict[self] = key if key: flist.dict[key] = self self.menudict = None # create a Notebook where the text pages for this EditorWindow will # reside self.text_notebook = TabbedPageSet(self.top) self.text_notebook.pack(fill=BOTH, expand=True) self.text_notebook.bind('<<NotebookTabChanged>>', self._update_controls) self.new_tab(filename=filename, load_ext=False, ptype=start_page) self.text = self.current_page.text # XXX self.top.focused_widget = self.text self.top.bind('<<tab-closed>>', self._post_tab_close) # The following "width" attribute is used by PyShell, so keep it here self.width = idleConf.GetOption('main', 'EditorPage', 'width') self.top.protocol("WM_DELETE_WINDOW", self.close) self.top.bind("<<close-window>>", self.close_event) self._create_statusbar() self.top.after_idle(self.set_line_and_column) # usetabs true -> literal tab characters are used by indent and # dedent cmds, possibly mixed with spaces if # indentwidth is not a multiple of tabwidth, # which will cause Tabnanny to nag! # false -> tab characters are converted to spaces by indent # and dedent cmds, and ditto TAB keystrokes # Although use-spaces=0 can be configured manually in config-main.def, # configuration of tabs v. spaces is not supported in the configuration # dialog. IDLE promotes the preferred Python indentation: use spaces! usespaces = idleConf.GetOption('main', 'Indent', 'use-spaces', type='bool') self.usetabs = not usespaces # tabwidth is the display width of a literal tab character. # CAUTION: telling Tk to use anything other than its default # tab setting causes it to use an entirely different tabbing algorithm, # treating tab stops as fixed distances from the left margin. # Nobody expects this, so for now tabwidth should never be changed. self.tabwidth = 8 # must remain 8 until Tk is fixed. # indentwidth is the number of screen characters per indent level. # The recommended Python indentation is four spaces. self.indentwidth = self.tabwidth self.set_notabs_indentwidth() # If context_use_ps1 is true, parsing searches back for a ps1 line; # else searches for a popular (if, def, ...) Python stmt. self.context_use_ps1 = False # When searching backwards for a reliable place to begin parsing, # first start num_context_lines[0] lines back, then # num_context_lines[1] lines back if that didn't work, and so on. # The last value should be huge (larger than the # of lines in a # conceivable file). # Making the initial values larger slows things down more often. self.num_context_lines = 50, 500, 5000000 if hasattr(self, 'ispythonsource'): # PyShell self.set_indentation_params(self.ispythonsource(filename)) else: self.set_indentation_params( self.current_page.ispythonsource(filename)) self.extensions = {} self._load_extensions() menu = self.menudict.get('windows') if menu: end = menu.index("end") if end is None: end = -1 if end >= 0: menu.add_separator() end = end + 1 self.wmenu_end = end WindowList.register_callback(self.postwindowsmenu) # Some abstractions so IDLE extensions are cross-IDE self.askyesno = tkMessageBox.askyesno self.askinteger = tkSimpleDialog.askinteger self.showerror = tkMessageBox.showerror