From cf6f1b69eb5f491dd3cba6c5c90bcb344d4b3a96 Mon Sep 17 00:00:00 2001 From: "Kurt B. Kaiser" Date: Sun, 11 Apr 2004 03:16:07 +0000 Subject: [PATCH] M EditorWindow.py M IOBinding.py M NEWS.txt M configDialog.py - If nulls somehow got into the strings in recent-files.lst EditorWindow.update_recent_files_list() was failing. Python Bug 931336. --- Lib/idlelib/EditorWindow.py | 112 ++++++++++++++++-------------------- Lib/idlelib/IOBinding.py | 2 +- Lib/idlelib/NEWS.txt | 5 +- Lib/idlelib/configDialog.py | 4 +- 4 files changed, 55 insertions(+), 68 deletions(-) diff --git a/Lib/idlelib/EditorWindow.py b/Lib/idlelib/EditorWindow.py index 546fa9d026c..ca52ccb582f 100644 --- a/Lib/idlelib/EditorWindow.py +++ b/Lib/idlelib/EditorWindow.py @@ -2,6 +2,7 @@ import sys import os import re import imp +from itertools import count from Tkinter import * import tkSimpleDialog import tkMessageBox @@ -78,10 +79,10 @@ class EditorWindow: self.top = top = self.Toplevel(root, menu=self.menubar) if flist: self.vars = flist.vars - #self.top.instanceDict makes flist.inversedict avalable to + #self.top.instance_dict makes flist.inversedict avalable to #configDialog.py so it can access all EditorWindow instaces - self.top.instanceDict=flist.inversedict - self.recentFilesPath=os.path.join(idleConf.GetUserCfgDir(), + self.top.instance_dict=flist.inversedict + self.recent_files_path=os.path.join(idleConf.GetUserCfgDir(), 'recent-files.lst') self.vbar = vbar = Scrollbar(top, name='vbar') self.text_frame = text_frame = Frame(top) @@ -178,11 +179,12 @@ class EditorWindow: self.io = io = self.IOBinding(self) io.set_filename_change_hook(self.filename_change_hook) - #create the Recent Files submenu - self.menuRecentFiles=Menu(self.menubar) - self.menudict['file'].insert_cascade(3,label='Recent Files', - underline=0,menu=self.menuRecentFiles) - self.UpdateRecentFilesList() + # Create the recent files submenu + self.recent_files_menu = Menu(self.menubar) + self.menudict['file'].insert_cascade(3, label='Recent Files', + underline=0, + menu=self.recent_files_menu) + self.update_recent_files_list() if filename: if os.path.exists(filename) and not os.path.isdir(filename): @@ -579,66 +581,48 @@ class EditorWindow: self.display_docs(helpfile) return display_extra_help - def UpdateRecentFilesList(self,newFile=None): - "Load or update the recent files list, and menu if required" - rfList=[] - if os.path.exists(self.recentFilesPath): - RFfile=open(self.recentFilesPath,'r') + def update_recent_files_list(self, new_file=None): + "Load and update the recent files list and menus" + rf_list = [] + if os.path.exists(self.recent_files_path): + rf_list_file = open(self.recent_files_path,'r') try: - rfList=RFfile.readlines() + rf_list = rf_list_file.readlines() finally: - RFfile.close() - if newFile: - newFile=os.path.abspath(newFile)+'\n' - if newFile in rfList: - rfList.remove(newFile) - rfList.insert(0,newFile) - rfList=self.__CleanRecentFiles(rfList) - #print self.flist.inversedict - #print self.top.instanceDict - #print self - ullist = "1234567890ABCDEFGHIJ" - if rfList: - for instance in self.top.instanceDict.keys(): - menu = instance.menuRecentFiles - menu.delete(1,END) - i = 0 ; ul = 0; ullen = len(ullist) - for file in rfList: - fileName=file[0:-1] - callback = instance.__RecentFileCallback(fileName) - if i > ullen: # don't underline menuitems - ul=None - menu.add_command(label=ullist[i] + " " + fileName, - command=callback, - underline=ul) - i += 1 - - def __CleanRecentFiles(self,rfList): - origRfList=rfList[:] - count=0 - nonFiles=[] - for path in rfList: - if not os.path.exists(path[0:-1]): - nonFiles.append(count) - count=count+1 - if nonFiles: - nonFiles.reverse() - for index in nonFiles: - del(rfList[index]) - if len(rfList)>19: - rfList=rfList[0:19] - #if rfList != origRfList: - RFfile=open(self.recentFilesPath,'w') + rf_list_file.close() + if new_file: + new_file = os.path.abspath(new_file) + '\n' + if new_file in rf_list: + rf_list.remove(new_file) # move to top + rf_list.insert(0, new_file) + # clean and save the recent files list + bad_paths = [] + for path in rf_list: + if '\0' in path or not os.path.exists(path[0:-1]): + bad_paths.append(path) + rf_list = [path for path in rf_list if path not in bad_paths] + ulchars = "1234567890ABCDEFGHIJK" + rf_list = rf_list[0:len(ulchars)] + rf_file = open(self.recent_files_path, 'w') try: - RFfile.writelines(rfList) + rf_file.writelines(rf_list) finally: - RFfile.close() - return rfList + rf_file.close() + # for each edit window instance, construct the recent files menu + for instance in self.top.instance_dict.keys(): + menu = instance.recent_files_menu + menu.delete(1, END) # clear, and rebuild: + for i, file in zip(count(), rf_list): + file_name = file[0:-1] # zap \n + callback = instance.__recent_file_callback(file_name) + menu.add_command(label=ulchars[i] + " " + file_name, + command=callback, + underline=0) - def __RecentFileCallback(self,fileName): - def OpenRecentFile(fileName=fileName): - self.io.open(editFile=fileName) - return OpenRecentFile + def __recent_file_callback(self, file_name): + def open_recent_file(fn_closure=file_name): + self.io.open(editFile=fn_closure) + return open_recent_file def saved_change_hook(self): short = self.short_title() @@ -729,7 +713,7 @@ class EditorWindow: def _close(self): #print self.io.filename if self.io.filename: - self.UpdateRecentFilesList(newFile=self.io.filename) + self.update_recent_files_list(new_file=self.io.filename) WindowList.unregister_callback(self.postwindowsmenu) if self.close_hook: self.close_hook() diff --git a/Lib/idlelib/IOBinding.py b/Lib/idlelib/IOBinding.py index bddd4d6d525..7baf8ccae6a 100644 --- a/Lib/idlelib/IOBinding.py +++ b/Lib/idlelib/IOBinding.py @@ -540,7 +540,7 @@ class IOBinding: def updaterecentfileslist(self,filename): "Update recent file list on all editor windows" - self.editwin.UpdateRecentFilesList(filename) + self.editwin.update_recent_files_list(filename) def test(): root = Tk() diff --git a/Lib/idlelib/NEWS.txt b/Lib/idlelib/NEWS.txt index 717eabcb610..800e44b4de2 100644 --- a/Lib/idlelib/NEWS.txt +++ b/Lib/idlelib/NEWS.txt @@ -3,8 +3,11 @@ What's New in IDLE 1.1a0? *Release date: XX-XXX-2004* +- If nulls somehow got into the strings in recent-files.lst + EditorWindow.update_recent_files_list() was failing. Python Bug 931336. + - If the normal background is changed via Configure/Highlighting, it will update - immediately, thanks to the previously mentioned patch. + immediately, thanks to the previously mentioned patch by Nigel Rowe. - Add a highlight theme for builtin keywords. Python Patch 805830 Nigel Rowe This also fixed IDLEfork bug [ 693418 ] Normal text background color not refreshed diff --git a/Lib/idlelib/configDialog.py b/Lib/idlelib/configDialog.py index 69cf818b01a..2645943a97e 100644 --- a/Lib/idlelib/configDialog.py +++ b/Lib/idlelib/configDialog.py @@ -1157,7 +1157,7 @@ class ConfigDialog(Toplevel): #update theme and repaint #update keybindings and re-bind #update user help sources menu - winInstances=self.parent.instanceDict.keys() + winInstances=self.parent.instance_dict.keys() for instance in winInstances: instance.ResetColorizer() instance.ResetFont() @@ -1183,5 +1183,5 @@ if __name__ == '__main__': root=Tk() Button(root,text='Dialog', command=lambda:ConfigDialog(root,'Settings')).pack() - root.instanceDict={} + root.instance_dict={} root.mainloop()