diff -r bf8710cf896b Lib/idlelib/EditorWindow.py --- a/Lib/idlelib/EditorWindow.py Tue Jun 03 20:54:21 2014 -0400 +++ b/Lib/idlelib/EditorWindow.py Wed Jun 04 20:19:33 2014 +0530 @@ -2,7 +2,7 @@ import importlib.abc import importlib.util import os -from platform import python_version +from platform import python_version_tuple import re import string import sys @@ -932,23 +932,49 @@ return open_recent_file def saved_change_hook(self): - short = self.short_title() - long = self.long_title() - if short and long: - title = short + " - " + long - elif short: - title = short - elif long: - title = long - else: - title = "Untitled" - icon = short or long or title - if not self.get_saved(): - title = "*%s*" % title - icon = "*%s" % icon + title = icon = self.get_title() self.top.wm_title(title) self.top.wm_iconname(icon) + def get_title(self): + "Utility function to return title based on config-main.def" + info = {} + major, minor, patchlevel = python_version_tuple() + info['py_major_version'] = major + info['py_minor_version'] = minor + info['py_patchlevel'] = patchlevel + info['tk_version'] = TkVersion + info['tcl_version'] = TclVersion + + filename = self.io.filename + if filename: + dir_path = os.path.dirname(filename) + os.path.sep + filename = os.path.basename(filename) + info['filename'] = filename + else: + dir_path = '' + info['filename'] = 'Untitled' + info['dir_path'] = os.path.normcase(dir_path) + info['full_path'] = os.path.join(info['dir_path'], info['filename']) + + if self.get_saved(): + info['modified_asterik'] = '' + else: + info['modified_asterik'] = '*' + + section = self.__class__.__name__ + + # Else AutoCompleteTest will fail + if section == 'EditorWindow': + section = 'PyShellEditorWindow' + + if section in idleConf.userCfg['main']: + config = idleConf.userCfg['main'][section]['title'] + else: + config = idleConf.defaultCfg['main'][section]['title'] + title = config.format(**info) + return title + def get_saved(self): return self.undo.get_saved() @@ -958,20 +984,6 @@ def reset_undo(self): self.undo.reset_undo() - def short_title(self): - pyversion = "Python " + python_version() + ": " - filename = self.io.filename - if filename: - filename = os.path.basename(filename) - else: - filename = "Untitled" - # return unicode string to display non-ASCII chars correctly - return pyversion + self._filename_to_unicode(filename) - - def long_title(self): - # return unicode string to display non-ASCII chars correctly - return self._filename_to_unicode(self.io.filename or "") - def center_insert_event(self, event): self.center() diff -r bf8710cf896b Lib/idlelib/config-main.def --- a/Lib/idlelib/config-main.def Tue Jun 03 20:54:21 2014 -0400 +++ b/Lib/idlelib/config-main.def Wed Jun 04 20:19:33 2014 +0530 @@ -58,6 +58,15 @@ font-bold= 0 encoding= none +[PyShellEditorWindow] +title={modified_asterik}{full_path} - Python {py_major_version}.{py_minor_version} + +[PyShell] +title= Python {py_major_version}.{py_minor_version} Shell + +[OutputWindow] +title=*Output* + [FormatParagraph] paragraph=72 diff -r bf8710cf896b Lib/idlelib/configDialog.py --- a/Lib/idlelib/configDialog.py Tue Jun 03 20:54:21 2014 -0400 +++ b/Lib/idlelib/configDialog.py Wed Jun 04 20:19:33 2014 +0530 @@ -21,6 +21,7 @@ from idlelib.keybindingDialog import GetKeysDialog from idlelib.configSectionNameDialog import GetCfgSectionNameDialog from idlelib.configHelpSourceEdit import GetHelpSourceDialog +from idlelib.configTitle import GetTitleDialog from idlelib import macosxSupport class ConfigDialog(Toplevel): @@ -353,6 +354,7 @@ text=' Autosave Preferences ') frameWinSize=Frame(frame,borderwidth=2,relief=GROOVE) frameParaSize=Frame(frame,borderwidth=2,relief=GROOVE) + frameTitleBar=Frame(frame,borderwidth=2,relief=GROOVE) frameHelp=LabelFrame(frame,borderwidth=2,relief=GROOVE, text=' Additional Help Sources ') #frameRun @@ -381,6 +383,10 @@ ' width (in characters)') entryParaWidth=Entry(frameParaSize,textvariable=self.paraWidth, width=3) + #configureTitleBar + labelTitleBarTitle=Label(frameTitleBar,text='Configure Title Bar') + self.buttonTitleBar=Button(frameTitleBar,text='Configure', + command=self.ConfigureTitleBar) #frameHelp frameHelpList=Frame(frameHelp) frameHelpListButtons=Frame(frameHelpList) @@ -402,6 +408,7 @@ frameSave.pack(side=TOP,padx=5,pady=5,fill=X) frameWinSize.pack(side=TOP,padx=5,pady=5,fill=X) frameParaSize.pack(side=TOP,padx=5,pady=5,fill=X) + frameTitleBar.pack(side=TOP,padx=5,pady=5,fill=X) frameHelp.pack(side=TOP,padx=5,pady=5,expand=TRUE,fill=BOTH) #frameRun labelRunChoiceTitle.pack(side=LEFT,anchor=W,padx=5,pady=5) @@ -420,6 +427,9 @@ #paragraphFormatWidth labelParaWidthTitle.pack(side=LEFT,anchor=W,padx=5,pady=5) entryParaWidth.pack(side=RIGHT,anchor=E,padx=10,pady=5) + #frameTitleBar + labelTitleBarTitle.pack(side=LEFT,anchor=W,padx=5,pady=5) + self.buttonTitleBar.pack(side=RIGHT,anchor=W,padx=5,pady=5) #frameHelp frameHelpListButtons.pack(side=RIGHT,padx=5,pady=5,fill=Y) frameHelpList.pack(side=TOP,padx=5,pady=5,expand=TRUE,fill=BOTH) @@ -874,6 +884,29 @@ self.textHighlightSample.tag_config(element, **colours) self.SetColourSample() + def ConfigureTitleBar(self): + """ + A dialog to allow the user to modify the title + bar in EditorWindow, PyShell and OutputWindow. + """ + dItems = self.GetDefaultItems() + titles_config = {} + sections = ('PyShellEditorWindow', 'PyShell', 'OutputWindow') + for s in sections: + if s in self.changedItems['main']: + titles_config[s] = self.changedItems['main'][s]['title'] + elif s in idleConf.userCfg['main']: + titles_config[s] = idleConf.userCfg['main'][s]['title'] + else: + titles_config[s] = dItems['main'][s]['title'] + + result = GetTitleDialog(self, 'Configure Titles', + title_configs=titles_config).result + if result: + for _ in result: + self.changedItems['main'][_] = {} + self.AddChangedItem('main', _, 'title', result[_]) + def HelpSourceSelected(self,event): self.SetHelpListButtonStates() diff -r bf8710cf896b Lib/idlelib/configTitle.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Lib/idlelib/configTitle.py Wed Jun 04 20:19:33 2014 +0530 @@ -0,0 +1,120 @@ +"""A dialog to allow the user to modify the title bar in EditorWindow +PyShell and OutputWindow. +""" +import tkinter as tk +import tkinter.messagebox as tkMessageBox + +class GetTitleDialog(tk.Toplevel): + def __init__(self, parent, title, title_configs={}): + """ + title - Title for the config dialog + title_configs - Dict. Contains existing title config + + User configures title bar for + EditorWindow, OutputWindow and PyShell + """ + tk.Toplevel.__init__(self, parent) + self.configure(borderwidth=5) + self.resizable(height=False, width=False) + self.title(title) + self.transient(parent) + self.protocol('WM_DELETE_WINDOW', self.cancel) + self.parent = parent + self.result = None + self.create_widgets() + try: + self.editor_window.set(title_configs['PyShellEditorWindow']) + self.pyshell.set(title_configs['PyShell']) + self.output_window.set(title_configs['OutputWindow']) + except KeyError: + pass + self.withdraw() + self.deiconify() + self.bind('', self.ok) + self.wait_window() + + def create_widgets(self): + self.editor_window = tk.StringVar(self) + self.pyshell = tk.StringVar(self) + self.output_window = tk.StringVar(self) + + self.frameMain = tk.Frame(self, borderwidth=2) + self.frameMain.pack(side='top', expand=True, fill='both') + self.labelEditorWindow = tk.Label(self.frameMain, anchor='w', + justify='left', text='EditorWindow') + self.labelPyShell = tk.Label(self.frameMain, anchor='w', + justify='left', text='PyShell') + self.labelOutputWindow = tk.Label(self.frameMain, anchor='w', + justify='left', text='OutputWindow') + self.entryEditorWindow = tk.Entry(self.frameMain,width=80, + textvariable=self.editor_window) + self.entryPyShell = tk.Entry(self.frameMain,width=80, + textvariable=self.pyshell) + self.entryOutputWindow = tk.Entry(self.frameMain,width=80, + textvariable=self.output_window) + + self.labelEditorWindow.pack(anchor='w', padx=5, pady=3) + self.entryEditorWindow.pack(anchor='w', padx=5, pady=3) + self.labelPyShell.pack(anchor='w', padx=5, pady=3) + self.entryPyShell.pack(anchor='w', padx=5, pady=3) + self.labelOutputWindow.pack(anchor='w', padx=5, pady=3) + self.entryOutputWindow.pack(anchor='w', padx=5, pady=3) + + frameButtons = tk.Frame(self) + frameButtons.pack(side='bottom', fill='x') + self.buttonOk = tk.Button(frameButtons, text='OK', + width=8, default='active', command=self.ok) + + self.buttonOk.grid(row=0, column=0, padx=5,pady=5) + self.buttonCancel = tk.Button(frameButtons, text='Cancel', + width=8, command=self.cancel) + self.buttonCancel.grid(row=0, column=1, padx=5, pady=5) + + def titles_ok(self): + """Simple validity check""" + config_ok = True + info = {} + info['py_major_version'] = '' + info['py_minor_version'] = '' + info['py_patchlevel'] = '' + info['tk_version'] = '' + info['tcl_version'] = '' + info['filename'] = '' + info['dir_path'] = '' + info['full_path'] = '' + info['modified_asterik'] = '' + + for title in (self.editor_window.get(), self.pyshell.get(), + self.output_window.get()): + try: + title.format(**info) + except: + tkMessageBox.showerror(title='Configure Title Error', + message='Error!', + parent=self) + config_ok = False + + return config_ok + + def ok(self): + if self.titles_ok(): + self.result = {} + self.result['PyShellEditorWindow'] = self.editor_window.get() + self.result['PyShell'] = self.pyshell.get() + self.result['OutputWindow'] = self.output_window.get() + self.destroy() + else: + self.result = None + + def cancel(self): + self.result = None + self.destroy() + +if __name__ == '__main__': + root = tk.Tk() + title_configs = {'PyShell':'Python {py_major_version}.{py_minor_version} Shell'} + title_configs['PyShellEditorWindow'] = '{modified_asterik}{full_path} - Python {py_major_version}.{py_minor_version}' + title_configs['OutputWindow'] = '*Output*' + + g = GetTitleDialog(root, 'Configure Title Bar', title_configs=title_configs) +