PyXR

c:\python24\lib \ idlelib \ SearchDialogBase.py



0001 from Tkinter import *
0002 
0003 class SearchDialogBase:
0004 
0005     title = "Search Dialog"
0006     icon = "Search"
0007     needwrapbutton = 1
0008 
0009     def __init__(self, root, engine):
0010         self.root = root
0011         self.engine = engine
0012         self.top = None
0013 
0014     def open(self, text, searchphrase=None):
0015         self.text = text
0016         if not self.top:
0017             self.create_widgets()
0018         else:
0019             self.top.deiconify()
0020             self.top.tkraise()
0021         if searchphrase:
0022             self.ent.delete(0,"end")
0023             self.ent.insert("end",searchphrase)
0024         self.ent.focus_set()
0025         self.ent.selection_range(0, "end")
0026         self.ent.icursor(0)
0027         self.top.grab_set()
0028 
0029     def close(self, event=None):
0030         if self.top:
0031             self.top.grab_release()
0032             self.top.withdraw()
0033 
0034     def create_widgets(self):
0035         top = Toplevel(self.root)
0036         top.bind("<Return>", self.default_command)
0037         top.bind("<Escape>", self.close)
0038         top.protocol("WM_DELETE_WINDOW", self.close)
0039         top.wm_title(self.title)
0040         top.wm_iconname(self.icon)
0041         self.top = top
0042 
0043         self.row = 0
0044         self.top.grid_columnconfigure(0, pad=2, weight=0)
0045         self.top.grid_columnconfigure(1, pad=2, minsize=100, weight=100)
0046 
0047         self.create_entries()
0048         self.create_option_buttons()
0049         self.create_other_buttons()
0050         return self.create_command_buttons()
0051 
0052     def make_entry(self, label, var):
0053         l = Label(self.top, text=label)
0054         l.grid(row=self.row, column=0, sticky="nw")
0055         e = Entry(self.top, textvariable=var, exportselection=0)
0056         e.grid(row=self.row, column=1, sticky="nwe")
0057         self.row = self.row + 1
0058         return e
0059 
0060     def make_frame(self,labeltext=None):
0061         if labeltext:
0062             l = Label(self.top, text=labeltext)
0063             l.grid(row=self.row, column=0, sticky="nw")
0064         f = Frame(self.top)
0065         f.grid(row=self.row, column=1, columnspan=1, sticky="nwe")
0066         self.row = self.row + 1
0067         return f
0068 
0069     def make_button(self, label, command, isdef=0):
0070         b = Button(self.buttonframe,
0071                    text=label, command=command,
0072                    default=isdef and "active" or "normal")
0073         cols,rows=self.buttonframe.grid_size()
0074         b.grid(pady=1,row=rows,column=0,sticky="ew")
0075         self.buttonframe.grid(rowspan=rows+1)
0076         return b
0077 
0078     def create_entries(self):
0079         self.ent = self.make_entry("Find:", self.engine.patvar)
0080 
0081     def create_option_buttons(self):
0082         f = self.make_frame("Options")
0083 
0084         btn = Checkbutton(f, anchor="w",
0085                 variable=self.engine.revar,
0086                 text="Regular expression")
0087         btn.pack(side="left", fill="both")
0088         if self.engine.isre():
0089             btn.select()
0090 
0091         btn = Checkbutton(f, anchor="w",
0092                 variable=self.engine.casevar,
0093                 text="Match case")
0094         btn.pack(side="left", fill="both")
0095         if self.engine.iscase():
0096             btn.select()
0097 
0098         btn = Checkbutton(f, anchor="w",
0099                 variable=self.engine.wordvar,
0100                 text="Whole word")
0101         btn.pack(side="left", fill="both")
0102         if self.engine.isword():
0103             btn.select()
0104 
0105         if self.needwrapbutton:
0106             btn = Checkbutton(f, anchor="w",
0107                     variable=self.engine.wrapvar,
0108                     text="Wrap around")
0109             btn.pack(side="left", fill="both")
0110             if self.engine.iswrap():
0111                 btn.select()
0112 
0113     def create_other_buttons(self):
0114         f = self.make_frame("Direction")
0115 
0116         #lbl = Label(f, text="Direction: ")
0117         #lbl.pack(side="left")
0118 
0119         btn = Radiobutton(f, anchor="w",
0120                 variable=self.engine.backvar, value=1,
0121                 text="Up")
0122         btn.pack(side="left", fill="both")
0123         if self.engine.isback():
0124             btn.select()
0125 
0126         btn = Radiobutton(f, anchor="w",
0127                 variable=self.engine.backvar, value=0,
0128                 text="Down")
0129         btn.pack(side="left", fill="both")
0130         if not self.engine.isback():
0131             btn.select()
0132 
0133     def create_command_buttons(self):
0134         #
0135         # place button frame on the right
0136         f = self.buttonframe = Frame(self.top)
0137         f.grid(row=0,column=2,padx=2,pady=2,ipadx=2,ipady=2)
0138 
0139         b = self.make_button("close", self.close)
0140         b.lower()
0141 

Generated by PyXR 0.9.4
SourceForge.net Logo