[Python-checkins] r58309 - python/trunk/Lib/idlelib/EditorWindow.py python/trunk/Lib/idlelib/NEWS.txt python/trunk/Lib/idlelib/aboutDialog.py python/trunk/Lib/idlelib/textView.py

kurt.kaiser python-checkins at python.org
Thu Oct 4 04:53:07 CEST 2007


Author: kurt.kaiser
Date: Thu Oct 4 04:53:07 2007
New Revision: 58309
Modified:
 python/trunk/Lib/idlelib/EditorWindow.py
 python/trunk/Lib/idlelib/NEWS.txt
 python/trunk/Lib/idlelib/aboutDialog.py
 python/trunk/Lib/idlelib/textView.py
Log:
textView cleanup. Patch 1718043 Tal Einat.
M idlelib/EditorWindow.py
M idlelib/aboutDialog.py
M idlelib/textView.py
M idlelib/NEWS.txt
Modified: python/trunk/Lib/idlelib/EditorWindow.py
==============================================================================
--- python/trunk/Lib/idlelib/EditorWindow.py	(original)
+++ python/trunk/Lib/idlelib/EditorWindow.py	Thu Oct 4 04:53:07 2007
@@ -392,7 +392,7 @@
 
 def help_dialog(self, event=None):
 fn=os.path.join(os.path.abspath(os.path.dirname(__file__)),'help.txt')
- textView.TextViewer(self.top,'Help',fn)
+ textView.view_file(self.top,'Help',fn)
 
 def python_docs(self, event=None):
 if sys.platform[:3] == 'win':
Modified: python/trunk/Lib/idlelib/NEWS.txt
==============================================================================
--- python/trunk/Lib/idlelib/NEWS.txt	(original)
+++ python/trunk/Lib/idlelib/NEWS.txt	Thu Oct 4 04:53:07 2007
@@ -3,6 +3,8 @@
 
 *Release date: XX-XXX-200X*
 
+- textView cleanup. Patch 1718043 Tal Einat.
+
 - Clean up EditorWindow close.
 
 - Corrected some bugs in AutoComplete. Also, Page Up/Down in ACW implemented;
Modified: python/trunk/Lib/idlelib/aboutDialog.py
==============================================================================
--- python/trunk/Lib/idlelib/aboutDialog.py	(original)
+++ python/trunk/Lib/idlelib/aboutDialog.py	Thu Oct 4 04:53:07 2007
@@ -3,7 +3,8 @@
 """
 
 from Tkinter import *
-import string, os
+import os
+import os.path
 import textView
 import idlever
 
@@ -70,7 +71,7 @@
 tkVer[len(tkVer)-1] = str('%.3g' % (float('.'+tkVer[len(tkVer)-1])))[2:]
 if tkVer[len(tkVer)-1] == '':
 tkVer[len(tkVer)-1] = '0'
- tkVer = string.join(tkVer,'.')
+ tkVer = '.'.join(tkVer)
 labelTkVer = Label(frameBg, text='Tk version: '+
 tkVer, fg=self.fg, bg=self.bg)
 labelTkVer.grid(row=9, column=1, sticky=W, padx=2, pady=0)
@@ -110,45 +111,31 @@
 idle_credits_b.pack(side=LEFT, padx=10, pady=10)
 
 def ShowLicense(self):
- self.display_printer_text(license, 'About - License')
+ self.display_printer_text('About - License', license)
 
 def ShowCopyright(self):
- self.display_printer_text(copyright, 'About - Copyright')
+ self.display_printer_text('About - Copyright', copyright)
 
 def ShowPythonCredits(self):
- self.display_printer_text(credits, 'About - Python Credits')
+ self.display_printer_text('About - Python Credits', credits)
 
 def ShowIDLECredits(self):
- self.ViewFile('About - Credits','CREDITS.txt', 'iso-8859-1')
+ self.display_file_text('About - Credits', 'CREDITS.txt', 'iso-8859-1')
 
 def ShowIDLEAbout(self):
- self.ViewFile('About - Readme', 'README.txt')
+ self.display_file_text('About - Readme', 'README.txt')
 
 def ShowIDLENEWS(self):
- self.ViewFile('About - NEWS', 'NEWS.txt')
+ self.display_file_text('About - NEWS', 'NEWS.txt')
 
- def display_printer_text(self, printer, title):
+ def display_printer_text(self, title, printer):
 printer._Printer__setup()
- data = '\n'.join(printer._Printer__lines)
- textView.TextViewer(self, title, None, data)
+ text = '\n'.join(printer._Printer__lines)
+ textView.view_text(self, title, text)
 
- def ViewFile(self, viewTitle, viewFile, encoding=None):
- fn = os.path.join(os.path.abspath(os.path.dirname(__file__)), viewFile)
- if encoding:
- import codecs
- try:
- textFile = codecs.open(fn, 'r')
- except IOError:
- import tkMessageBox
- tkMessageBox.showerror(title='File Load Error',
- message='Unable to load file %r .' % (fn,),
- parent=self)
- return
- else:
- data = textFile.read()
- else:
- data = None
- textView.TextViewer(self, viewTitle, fn, data=data)
+ def display_file_text(self, title, filename, encoding=None):
+ fn = os.path.join(os.path.abspath(os.path.dirname(__file__)), filename)
+ textView.view_file(self, title, fn, encoding)
 
 def Ok(self, event=None):
 self.destroy()
Modified: python/trunk/Lib/idlelib/textView.py
==============================================================================
--- python/trunk/Lib/idlelib/textView.py	(original)
+++ python/trunk/Lib/idlelib/textView.py	Thu Oct 4 04:53:07 2007
@@ -6,13 +6,12 @@
 import tkMessageBox
 
 class TextViewer(Toplevel):
+ """A simple text viewer dialog for IDLE
+
 """
- simple text viewer dialog for idle
- """
- def __init__(self, parent, title, fileName, data=None):
- """If data exists, load it into viewer, otherwise try to load file.
+ def __init__(self, parent, title, text):
+ """Show the given text in a scrollable window with a 'close' button
 
- fileName - string, should be an absoulute filename
 """
 Toplevel.__init__(self, parent)
 self.configure(borderwidth=5)
@@ -33,23 +32,10 @@
 #key bindings for this dialog
 self.bind('<Return>',self.Ok) #dismiss dialog
 self.bind('<Escape>',self.Ok) #dismiss dialog
- if data:
- self.textView.insert(0.0, data)
- else:
- self.LoadTextFile(fileName)
+ self.textView.insert(0.0, text)
 self.textView.config(state=DISABLED)
 self.wait_window()
 
- def LoadTextFile(self, fileName):
- textFile = None
- try:
- textFile = open(fileName, 'r')
- except IOError:
- tkMessageBox.showerror(title='File Load Error',
- message='Unable to load file %r .' % (fileName,))
- else:
- self.textView.insert(0.0,textFile.read())
-
 def CreateWidgets(self):
 frameText = Frame(self, relief=SUNKEN, height=700)
 frameButtons = Frame(self)
@@ -70,9 +56,38 @@
 def Ok(self, event=None):
 self.destroy()
 
+
+def view_text(parent, title, text):
+ TextViewer(parent, title, text)
+
+def view_file(parent, title, filename, encoding=None):
+ try:
+ if encoding:
+ import codecs
+ textFile = codecs.open(filename, 'r')
+ else:
+ textFile = open(filename, 'r')
+ except IOError:
+ import tkMessageBox
+ tkMessageBox.showerror(title='File Load Error',
+ message='Unable to load file %r .' % filename,
+ parent=parent)
+ else:
+ return view_text(parent, title, textFile.read())
+
+
 if __name__ == '__main__':
 #test the dialog
 root=Tk()
- Button(root,text='View',
- command=lambda:TextViewer(root,'Text','./textView.py')).pack()
+ root.title('textView test')
+ filename = './textView.py'
+ text = file(filename, 'r').read()
+ btn1 = Button(root, text='view_text',
+ command=lambda:view_text(root, 'view_text', text))
+ btn1.pack(side=LEFT)
+ btn2 = Button(root, text='view_file',
+ command=lambda:view_file(root, 'view_file', filename))
+ btn2.pack(side=LEFT)
+ close = Button(root, text='Close', command=root.destroy)
+ close.pack(side=RIGHT)
 root.mainloop()


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /