Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python2..../idlelib
File: SearchDialog.py
from Tkinter import *
[0] Fix | Delete
[1] Fix | Delete
from idlelib import SearchEngine
[2] Fix | Delete
from idlelib.SearchDialogBase import SearchDialogBase
[3] Fix | Delete
[4] Fix | Delete
def _setup(text):
[5] Fix | Delete
root = text._root()
[6] Fix | Delete
engine = SearchEngine.get(root)
[7] Fix | Delete
if not hasattr(engine, "_searchdialog"):
[8] Fix | Delete
engine._searchdialog = SearchDialog(root, engine)
[9] Fix | Delete
return engine._searchdialog
[10] Fix | Delete
[11] Fix | Delete
def find(text):
[12] Fix | Delete
pat = text.get("sel.first", "sel.last")
[13] Fix | Delete
return _setup(text).open(text,pat)
[14] Fix | Delete
[15] Fix | Delete
def find_again(text):
[16] Fix | Delete
return _setup(text).find_again(text)
[17] Fix | Delete
[18] Fix | Delete
def find_selection(text):
[19] Fix | Delete
return _setup(text).find_selection(text)
[20] Fix | Delete
[21] Fix | Delete
class SearchDialog(SearchDialogBase):
[22] Fix | Delete
[23] Fix | Delete
def create_widgets(self):
[24] Fix | Delete
SearchDialogBase.create_widgets(self)
[25] Fix | Delete
self.make_button("Find Next", self.default_command, 1)
[26] Fix | Delete
[27] Fix | Delete
def default_command(self, event=None):
[28] Fix | Delete
if not self.engine.getprog():
[29] Fix | Delete
return
[30] Fix | Delete
self.find_again(self.text)
[31] Fix | Delete
[32] Fix | Delete
def find_again(self, text):
[33] Fix | Delete
if not self.engine.getpat():
[34] Fix | Delete
self.open(text)
[35] Fix | Delete
return False
[36] Fix | Delete
if not self.engine.getprog():
[37] Fix | Delete
return False
[38] Fix | Delete
res = self.engine.search_text(text)
[39] Fix | Delete
if res:
[40] Fix | Delete
line, m = res
[41] Fix | Delete
i, j = m.span()
[42] Fix | Delete
first = "%d.%d" % (line, i)
[43] Fix | Delete
last = "%d.%d" % (line, j)
[44] Fix | Delete
try:
[45] Fix | Delete
selfirst = text.index("sel.first")
[46] Fix | Delete
sellast = text.index("sel.last")
[47] Fix | Delete
if selfirst == first and sellast == last:
[48] Fix | Delete
text.bell()
[49] Fix | Delete
return False
[50] Fix | Delete
except TclError:
[51] Fix | Delete
pass
[52] Fix | Delete
text.tag_remove("sel", "1.0", "end")
[53] Fix | Delete
text.tag_add("sel", first, last)
[54] Fix | Delete
text.mark_set("insert", self.engine.isback() and first or last)
[55] Fix | Delete
text.see("insert")
[56] Fix | Delete
return True
[57] Fix | Delete
else:
[58] Fix | Delete
text.bell()
[59] Fix | Delete
return False
[60] Fix | Delete
[61] Fix | Delete
def find_selection(self, text):
[62] Fix | Delete
pat = text.get("sel.first", "sel.last")
[63] Fix | Delete
if pat:
[64] Fix | Delete
self.engine.setcookedpat(pat)
[65] Fix | Delete
return self.find_again(text)
[66] Fix | Delete
[67] Fix | Delete
def _search_dialog(parent):
[68] Fix | Delete
root = Tk()
[69] Fix | Delete
root.title("Test SearchDialog")
[70] Fix | Delete
width, height, x, y = list(map(int, re.split('[x+]', parent.geometry())))
[71] Fix | Delete
root.geometry("+%d+%d"%(x, y + 150))
[72] Fix | Delete
text = Text(root)
[73] Fix | Delete
text.pack()
[74] Fix | Delete
text.insert("insert","This is a sample string.\n"*10)
[75] Fix | Delete
[76] Fix | Delete
def show_find():
[77] Fix | Delete
text.tag_add(SEL, "1.0", END)
[78] Fix | Delete
s = _setup(text)
[79] Fix | Delete
s.open(text)
[80] Fix | Delete
text.tag_remove(SEL, "1.0", END)
[81] Fix | Delete
[82] Fix | Delete
button = Button(root, text="Search", command=show_find)
[83] Fix | Delete
button.pack()
[84] Fix | Delete
[85] Fix | Delete
if __name__ == '__main__':
[86] Fix | Delete
from idlelib.idle_test.htest import run
[87] Fix | Delete
run(_search_dialog)
[88] Fix | Delete
[89] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function