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):
|
def help_dialog(self, event=None):
|
||||||
fn=os.path.join(os.path.abspath(os.path.dirname(__file__)),'help.txt')
|
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):
|
def python_docs(self, event=None):
|
||||||
if sys.platform[:3] == 'win':
|
if sys.platform[:3] == 'win':
|
||||||
|
|
|
@ -3,6 +3,8 @@ What's New in IDLE 2.6a1?
|
||||||
|
|
||||||
*Release date: XX-XXX-200X*
|
*Release date: XX-XXX-200X*
|
||||||
|
|
||||||
|
- textView cleanup. Patch 1718043 Tal Einat.
|
||||||
|
|
||||||
- Clean up EditorWindow close.
|
- Clean up EditorWindow close.
|
||||||
|
|
||||||
- Corrected some bugs in AutoComplete. Also, Page Up/Down in ACW implemented;
|
- Corrected some bugs in AutoComplete. Also, Page Up/Down in ACW implemented;
|
||||||
|
|
|
@ -3,7 +3,8 @@
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from Tkinter import *
|
from Tkinter import *
|
||||||
import string, os
|
import os
|
||||||
|
import os.path
|
||||||
import textView
|
import textView
|
||||||
import idlever
|
import idlever
|
||||||
|
|
||||||
|
@ -70,7 +71,7 @@ class AboutDialog(Toplevel):
|
||||||
tkVer[len(tkVer)-1] = str('%.3g' % (float('.'+tkVer[len(tkVer)-1])))[2:]
|
tkVer[len(tkVer)-1] = str('%.3g' % (float('.'+tkVer[len(tkVer)-1])))[2:]
|
||||||
if tkVer[len(tkVer)-1] == '':
|
if tkVer[len(tkVer)-1] == '':
|
||||||
tkVer[len(tkVer)-1] = '0'
|
tkVer[len(tkVer)-1] = '0'
|
||||||
tkVer = string.join(tkVer,'.')
|
tkVer = '.'.join(tkVer)
|
||||||
labelTkVer = Label(frameBg, text='Tk version: '+
|
labelTkVer = Label(frameBg, text='Tk version: '+
|
||||||
tkVer, fg=self.fg, bg=self.bg)
|
tkVer, fg=self.fg, bg=self.bg)
|
||||||
labelTkVer.grid(row=9, column=1, sticky=W, padx=2, pady=0)
|
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)
|
idle_credits_b.pack(side=LEFT, padx=10, pady=10)
|
||||||
|
|
||||||
def ShowLicense(self):
|
def ShowLicense(self):
|
||||||
self.display_printer_text(license, 'About - License')
|
self.display_printer_text('About - License', license)
|
||||||
|
|
||||||
def ShowCopyright(self):
|
def ShowCopyright(self):
|
||||||
self.display_printer_text(copyright, 'About - Copyright')
|
self.display_printer_text('About - Copyright', copyright)
|
||||||
|
|
||||||
def ShowPythonCredits(self):
|
def ShowPythonCredits(self):
|
||||||
self.display_printer_text(credits, 'About - Python Credits')
|
self.display_printer_text('About - Python Credits', credits)
|
||||||
|
|
||||||
def ShowIDLECredits(self):
|
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):
|
def ShowIDLEAbout(self):
|
||||||
self.ViewFile('About - Readme', 'README.txt')
|
self.display_file_text('About - Readme', 'README.txt')
|
||||||
|
|
||||||
def ShowIDLENEWS(self):
|
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()
|
printer._Printer__setup()
|
||||||
data = '\n'.join(printer._Printer__lines)
|
text = '\n'.join(printer._Printer__lines)
|
||||||
textView.TextViewer(self, title, None, data)
|
textView.view_text(self, title, text)
|
||||||
|
|
||||||
def ViewFile(self, viewTitle, viewFile, encoding=None):
|
def display_file_text(self, title, filename, encoding=None):
|
||||||
fn = os.path.join(os.path.abspath(os.path.dirname(__file__)), viewFile)
|
fn = os.path.join(os.path.abspath(os.path.dirname(__file__)), filename)
|
||||||
if encoding:
|
textView.view_file(self, title, fn, 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 Ok(self, event=None):
|
def Ok(self, event=None):
|
||||||
self.destroy()
|
self.destroy()
|
||||||
|
|
|
@ -6,13 +6,12 @@ from Tkinter import *
|
||||||
import tkMessageBox
|
import tkMessageBox
|
||||||
|
|
||||||
class TextViewer(Toplevel):
|
class TextViewer(Toplevel):
|
||||||
"""
|
"""A simple text viewer dialog for IDLE
|
||||||
simple text viewer dialog for idle
|
|
||||||
"""
|
"""
|
||||||
def __init__(self, parent, title, fileName, data=None):
|
def __init__(self, parent, title, text):
|
||||||
"""If data exists, load it into viewer, otherwise try to load file.
|
"""Show the given text in a scrollable window with a 'close' button
|
||||||
|
|
||||||
fileName - string, should be an absoulute filename
|
|
||||||
"""
|
"""
|
||||||
Toplevel.__init__(self, parent)
|
Toplevel.__init__(self, parent)
|
||||||
self.configure(borderwidth=5)
|
self.configure(borderwidth=5)
|
||||||
|
@ -33,23 +32,10 @@ class TextViewer(Toplevel):
|
||||||
#key bindings for this dialog
|
#key bindings for this dialog
|
||||||
self.bind('<Return>',self.Ok) #dismiss dialog
|
self.bind('<Return>',self.Ok) #dismiss dialog
|
||||||
self.bind('<Escape>',self.Ok) #dismiss dialog
|
self.bind('<Escape>',self.Ok) #dismiss dialog
|
||||||
if data:
|
self.textView.insert(0.0, text)
|
||||||
self.textView.insert(0.0, data)
|
|
||||||
else:
|
|
||||||
self.LoadTextFile(fileName)
|
|
||||||
self.textView.config(state=DISABLED)
|
self.textView.config(state=DISABLED)
|
||||||
self.wait_window()
|
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):
|
def CreateWidgets(self):
|
||||||
frameText = Frame(self, relief=SUNKEN, height=700)
|
frameText = Frame(self, relief=SUNKEN, height=700)
|
||||||
frameButtons = Frame(self)
|
frameButtons = Frame(self)
|
||||||
|
@ -70,9 +56,38 @@ class TextViewer(Toplevel):
|
||||||
def Ok(self, event=None):
|
def Ok(self, event=None):
|
||||||
self.destroy()
|
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__':
|
if __name__ == '__main__':
|
||||||
#test the dialog
|
#test the dialog
|
||||||
root=Tk()
|
root=Tk()
|
||||||
Button(root,text='View',
|
root.title('textView test')
|
||||||
command=lambda:TextViewer(root,'Text','./textView.py')).pack()
|
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()
|
root.mainloop()
|
||||||
|
|
Loading…
Reference in New Issue