Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python2..../idlelib
File: textView.py
"""Simple text browser for IDLE
[0] Fix | Delete
[1] Fix | Delete
"""
[2] Fix | Delete
[3] Fix | Delete
from Tkinter import *
[4] Fix | Delete
import tkMessageBox
[5] Fix | Delete
[6] Fix | Delete
class TextViewer(Toplevel):
[7] Fix | Delete
"""A simple text viewer dialog for IDLE
[8] Fix | Delete
[9] Fix | Delete
"""
[10] Fix | Delete
def __init__(self, parent, title, text, modal=True, _htest=False):
[11] Fix | Delete
"""Show the given text in a scrollable window with a 'close' button
[12] Fix | Delete
[13] Fix | Delete
If modal option set to False, user can interact with other windows,
[14] Fix | Delete
otherwise they will be unable to interact with other windows until
[15] Fix | Delete
the textview window is closed.
[16] Fix | Delete
[17] Fix | Delete
_htest - bool; change box location when running htest.
[18] Fix | Delete
"""
[19] Fix | Delete
Toplevel.__init__(self, parent)
[20] Fix | Delete
self.configure(borderwidth=5)
[21] Fix | Delete
# place dialog below parent if running htest
[22] Fix | Delete
self.geometry("=%dx%d+%d+%d" % (750, 500,
[23] Fix | Delete
parent.winfo_rootx() + 10,
[24] Fix | Delete
parent.winfo_rooty() + (10 if not _htest else 100)))
[25] Fix | Delete
#elguavas - config placeholders til config stuff completed
[26] Fix | Delete
self.bg = '#ffffff'
[27] Fix | Delete
self.fg = '#000000'
[28] Fix | Delete
[29] Fix | Delete
self.CreateWidgets()
[30] Fix | Delete
self.title(title)
[31] Fix | Delete
self.protocol("WM_DELETE_WINDOW", self.Ok)
[32] Fix | Delete
self.parent = parent
[33] Fix | Delete
self.textView.focus_set()
[34] Fix | Delete
#key bindings for this dialog
[35] Fix | Delete
self.bind('<Return>',self.Ok) #dismiss dialog
[36] Fix | Delete
self.bind('<Escape>',self.Ok) #dismiss dialog
[37] Fix | Delete
self.textView.insert(0.0, text)
[38] Fix | Delete
self.textView.config(state=DISABLED)
[39] Fix | Delete
[40] Fix | Delete
self.is_modal = modal
[41] Fix | Delete
if self.is_modal:
[42] Fix | Delete
self.transient(parent)
[43] Fix | Delete
self.grab_set()
[44] Fix | Delete
self.wait_window()
[45] Fix | Delete
[46] Fix | Delete
def CreateWidgets(self):
[47] Fix | Delete
frameText = Frame(self, relief=SUNKEN, height=700)
[48] Fix | Delete
frameButtons = Frame(self)
[49] Fix | Delete
self.buttonOk = Button(frameButtons, text='Close',
[50] Fix | Delete
command=self.Ok, takefocus=FALSE)
[51] Fix | Delete
self.scrollbarView = Scrollbar(frameText, orient=VERTICAL,
[52] Fix | Delete
takefocus=FALSE, highlightthickness=0)
[53] Fix | Delete
self.textView = Text(frameText, wrap=WORD, highlightthickness=0,
[54] Fix | Delete
fg=self.fg, bg=self.bg)
[55] Fix | Delete
self.scrollbarView.config(command=self.textView.yview)
[56] Fix | Delete
self.textView.config(yscrollcommand=self.scrollbarView.set)
[57] Fix | Delete
self.buttonOk.pack()
[58] Fix | Delete
self.scrollbarView.pack(side=RIGHT,fill=Y)
[59] Fix | Delete
self.textView.pack(side=LEFT,expand=TRUE,fill=BOTH)
[60] Fix | Delete
frameButtons.pack(side=BOTTOM,fill=X)
[61] Fix | Delete
frameText.pack(side=TOP,expand=TRUE,fill=BOTH)
[62] Fix | Delete
[63] Fix | Delete
def Ok(self, event=None):
[64] Fix | Delete
if self.is_modal:
[65] Fix | Delete
self.grab_release()
[66] Fix | Delete
self.destroy()
[67] Fix | Delete
[68] Fix | Delete
[69] Fix | Delete
def view_text(parent, title, text, modal=True):
[70] Fix | Delete
return TextViewer(parent, title, text, modal)
[71] Fix | Delete
[72] Fix | Delete
def view_file(parent, title, filename, encoding=None, modal=True):
[73] Fix | Delete
try:
[74] Fix | Delete
if encoding:
[75] Fix | Delete
import codecs
[76] Fix | Delete
textFile = codecs.open(filename, 'r')
[77] Fix | Delete
else:
[78] Fix | Delete
textFile = open(filename, 'r')
[79] Fix | Delete
except IOError:
[80] Fix | Delete
tkMessageBox.showerror(title='File Load Error',
[81] Fix | Delete
message='Unable to load file %r .' % filename,
[82] Fix | Delete
parent=parent)
[83] Fix | Delete
except UnicodeDecodeError as err:
[84] Fix | Delete
showerror(title='Unicode Decode Error',
[85] Fix | Delete
message=str(err),
[86] Fix | Delete
parent=parent)
[87] Fix | Delete
else:
[88] Fix | Delete
return view_text(parent, title, textFile.read(), modal)
[89] Fix | Delete
[90] Fix | Delete
[91] Fix | Delete
if __name__ == '__main__':
[92] Fix | Delete
import unittest
[93] Fix | Delete
unittest.main('idlelib.idle_test.test_textview', verbosity=2, exit=False)
[94] Fix | Delete
from idlelib.idle_test.htest import run
[95] Fix | Delete
run(TextViewer)
[96] Fix | Delete
[97] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function