summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib
diff options
context:
space:
mode:
authorKurt B. Kaiser <kbk@shore.net>2004-04-11 03:16:07 (GMT)
committerKurt B. Kaiser <kbk@shore.net>2004-04-11 03:16:07 (GMT)
commitcf6f1b69eb5f491dd3cba6c5c90bcb344d4b3a96 (patch)
treeb68bdb1ab0c5203094923cdd3d5a7d367cc8dd49 /Lib/idlelib
parent5bed456056db0b16afd97c0045796cdafeac4bd9 (diff)
downloadcpython-cf6f1b69eb5f491dd3cba6c5c90bcb344d4b3a96.zip
cpython-cf6f1b69eb5f491dd3cba6c5c90bcb344d4b3a96.tar.gz
cpython-cf6f1b69eb5f491dd3cba6c5c90bcb344d4b3a96.tar.bz2
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.
Diffstat (limited to 'Lib/idlelib')
-rw-r--r--Lib/idlelib/EditorWindow.py114
-rw-r--r--Lib/idlelib/IOBinding.py2
-rw-r--r--Lib/idlelib/NEWS.txt5
-rw-r--r--Lib/idlelib/configDialog.py4
4 files changed, 56 insertions, 69 deletions
diff --git a/Lib/idlelib/EditorWindow.py b/Lib/idlelib/EditorWindow.py
index 546fa9d..ca52ccb 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
-
- def __RecentFileCallback(self,fileName):
- def OpenRecentFile(fileName=fileName):
- self.io.open(editFile=fileName)
- return OpenRecentFile
+ 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 __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 bddd4d6..7baf8cc 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 717eabc..800e44b 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 69cf818..2645943 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()