1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | ## ## ## ################################################ ## ###### Please Don't Remove Author Name ######### ## ############# Thanks ########################### ## ################################################ ## ## __author__='''
###################################################### By ######################################################
Suraj Singh surajsinghbisht054@gmail.com http://www.bitforestinfo.com/
###################################################### '''
from Graphics import Tkinter
def FindAsk(parent,*args): root = Tkinter.Toplevel(parent) root.title("Find And Replace") root.transient(parent) root.focus_force() root.resizable(width=0, height=0) root['padx']=20 fields = {} field={} for r, label in enumerate(args): store_label = Tkinter.Label(root, text=label) store_label.grid(row=r, column = 0, ipady=5, ipadx=20) store_entry = Tkinter.Entry(root) store_entry.grid(row=r, column=1) field[label]=store_entry fields['submit']=False def sub(): for l,t in field.iteritems(): fields[l]=t.get() fields['submit']=True root.destroy() return submit=Tkinter.Button(root,text="Ok", command=sub) submit.grid(row=r+1, column=2) root.wait_window() return fields
class FindReplaceFunctions: def __init__(self,text): self.text = text self.key_binding_functions() self.binding_functions_configuration()
def binding_functions_configuration(self): self.text.storeobj['Find'] = self.find_ self.text.storeobj['FindAll'] = self.find_all self.text.storeobj['Replace'] = self.replace self.text.storeobj['ReplaceAll'] = self.replace_all return
def key_binding_functions(self): for key in ['<Control-F>',"<Control-f>"]: self.text.bind(key, self.find_) for key in ['<Control-Shift-F>',"<Control-Shift-f>"]: self.text.bind(key, self.find_all) for key in ['<Control-Shift-H>',"<Control-Shift-h>"]: self.text.bind(key, self.replace_all) for key in ['<Control-H>',"<Control-h>"]: self.text.bind(key, self.replace) return
def find_(self, event=None): t = FindAsk(self.text.master, "Find") if t['submit']: print t['Find'] return
def find_all(self, event=None): t = FindAsk(self.text.master, "FindAll") if t['submit']: print t['FindAll'] return
def replace(self, event=None): t = FindAsk(self.text.master, "Find", "Replace") if t['submit']: print t['Find'] print t['Replace'] return
def replace_all(self, event=None): t = FindAsk(self.text.master, "FindAll", "ReplaceAll") if t['submit']: print t['FindAll'] print t['ReplaceAll'] return
if __name__ == '__main__': root = Tkinter.Tk() pad = Tkinter.Text(root) pad.pack() pad.storeobj={} FindReplaceFunctions(pad) #print FindAsk(root,"a","b",1) root.mainloop()
|