blob: faf526918f368dfe9039821b8d1438d124b7dd3e [file] [log] [blame]
David Scherer7aced172000-08-15 01:13:23 +00001import string
2from Tkinter import *
3
4class SearchDialogBase:
5
6 title = "Search Dialog"
7 icon = "Search"
8 needwrapbutton = 1
9
10 def __init__(self, root, engine):
11 self.root = root
12 self.engine = engine
13 self.top = None
14
15 def open(self, text):
16 self.text = text
17 if not self.top:
18 self.create_widgets()
19 else:
20 self.top.deiconify()
21 self.top.tkraise()
22 self.ent.focus_set()
23 self.ent.selection_range(0, "end")
24 self.ent.icursor(0)
25 self.top.grab_set()
26
27 def close(self, event=None):
28 if self.top:
29 self.top.grab_release()
30 self.top.withdraw()
31
32 def create_widgets(self):
33 top = Toplevel(self.root)
34 top.bind("<Return>", self.default_command)
35 top.bind("<Escape>", self.close)
36 top.protocol("WM_DELETE_WINDOW", self.close)
37 top.wm_title(self.title)
38 top.wm_iconname(self.icon)
39 self.top = top
40
41 self.row = 0
42 self.top.grid_columnconfigure(0, weight=0)
43 self.top.grid_columnconfigure(1, weight=100)
44
45 self.create_entries()
46 self.create_option_buttons()
47 self.create_other_buttons()
48 return self.create_command_buttons()
49
50 def make_entry(self, label, var):
51 l = Label(self.top, text=label)
52 l.grid(row=self.row, col=0, sticky="w")
53 e = Entry(self.top, textvariable=var, exportselection=0)
54 e.grid(row=self.row, col=1, sticky="we")
55 self.row = self.row + 1
56 return e
57
58 def make_frame(self):
59 f = Frame(self.top)
60 f.grid(row=self.row, col=0, columnspan=2, sticky="we")
61 self.row = self.row + 1
62 return f
63
64 def make_button(self, label, command, isdef=0, side="left"):
65 b = Button(self.buttonframe,
66 text=label, command=command,
67 default=isdef and "active" or "normal")
68 b.pack(side=side)
69 return b
70
71 def create_entries(self):
72 self.ent = self.make_entry("Find:", self.engine.patvar)
73
74 def create_option_buttons(self):
75 f = self.make_frame()
76
77 btn = Checkbutton(f, anchor="w",
78 variable=self.engine.revar,
79 text="Regular expression")
80 btn.pack(side="left", fill="both")
81 if self.engine.isre():
82 btn.select()
83
84 btn = Checkbutton(f, anchor="w",
85 variable=self.engine.casevar,
86 text="Match case")
87 btn.pack(side="left", fill="both")
88 if self.engine.iscase():
89 btn.select()
90
91 btn = Checkbutton(f, anchor="w",
92 variable=self.engine.wordvar,
93 text="Whole word")
94 btn.pack(side="left", fill="both")
95 if self.engine.isword():
96 btn.select()
97
98 if self.needwrapbutton:
99 btn = Checkbutton(f, anchor="w",
100 variable=self.engine.wrapvar,
101 text="Wrap around")
102 btn.pack(side="left", fill="both")
103 if self.engine.iswrap():
104 btn.select()
105
106 def create_other_buttons(self):
107 f = self.make_frame()
108
109 lbl = Label(f, text="Direction: ")
110 lbl.pack(side="left")
111
112 btn = Radiobutton(f, anchor="w",
113 variable=self.engine.backvar, value=1,
114 text="Up")
115 btn.pack(side="left", fill="both")
116 if self.engine.isback():
117 btn.select()
118
119 btn = Radiobutton(f, anchor="w",
120 variable=self.engine.backvar, value=0,
121 text="Down")
122 btn.pack(side="left", fill="both")
123 if not self.engine.isback():
124 btn.select()
125
126 def create_command_buttons(self):
127 f = self.buttonframe = self.make_frame()
128 b = self.make_button("close", self.close, side="right")
129 b.lower()