mirror of https://github.com/python/cpython
textView cleanup. Patch 1718043 Tal Einat.
M idlelib/EditorWindow.py M idlelib/aboutDialog.py M idlelib/textView.py M idlelib/NEWS.txt
This commit is contained in:
parent
0b634efcbc
commit
d5f4910afd
|
@ -392,7 +392,7 @@ class EditorWindow(object):
|
|||
|
||||
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':
|
||||
|
|
|
@ -3,6 +3,8 @@ What's New in IDLE 2.6a1?
|
|||
|
||||
*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;
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
"""
|
||||
|
||||
from Tkinter import *
|
||||
import string, os
|
||||
import os
|
||||
import os.path
|
||||
import textView
|
||||
import idlever
|
||||
|
||||
|
@ -70,7 +71,7 @@ class AboutDialog(Toplevel):
|
|||
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 @@ class AboutDialog(Toplevel):
|
|||
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()
|
||||
|
|
|
@ -6,13 +6,12 @@ from Tkinter import *
|
|||
import tkMessageBox
|
||||
|
||||
class TextViewer(Toplevel):
|
||||
"""
|
||||
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.
|
||||
"""A simple text viewer dialog for IDLE
|
||||
|
||||
"""
|
||||
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 @@ class TextViewer(Toplevel):
|
|||
#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 @@ class TextViewer(Toplevel):
|
|||
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()
|
||||
|
|
Loading…
Reference in New Issue