blob: 3556ebf69f3be0ca786dea272f647298bc053910 [file] [log] [blame]
David Scherer7aced172000-08-15 01:13:23 +00001from Tkinter import *
2
3class SearchDialogBase:
4
5 title = "Search Dialog"
6 icon = "Search"
7 needwrapbutton = 1
8
9 def __init__(self, root, engine):
10 self.root = root
11 self.engine = engine
12 self.top = None
13
14 def open(self, text):
15 self.text = text
16 if not self.top:
17 self.create_widgets()
18 else:
19 self.top.deiconify()
20 self.top.tkraise()
21 self.ent.focus_set()
22 self.ent.selection_range(0, "end")
23 self.ent.icursor(0)
24 self.top.grab_set()
25
26 def close(self, event=None):
27 if self.top:
28 self.top.grab_release()
29 self.top.withdraw()
30
31 def create_widgets(self):
32 top = Toplevel(self.root)
33 top.bind("<Return>", self.default_command)
34 top.bind("<Escape>", self.close)
35 top.protocol("WM_DELETE_WINDOW", self.close)
36 top.wm_title(self.title)
37 top.wm_iconname(self.icon)
38 self.top = top
39
40 self.row = 0
Chui Tey72a8a3b2002-11-04 23:07:51 +000041 self.top.grid_columnconfigure(0, pad=2, weight=0)
42 self.top.grid_columnconfigure(1, pad=2, minsize=100, weight=100)
David Scherer7aced172000-08-15 01:13:23 +000043
44 self.create_entries()
45 self.create_option_buttons()
46 self.create_other_buttons()
47 return self.create_command_buttons()
48
49 def make_entry(self, label, var):
50 l = Label(self.top, text=label)
Chui Tey72a8a3b2002-11-04 23:07:51 +000051 l.grid(row=self.row, col=0, sticky="nw")
David Scherer7aced172000-08-15 01:13:23 +000052 e = Entry(self.top, textvariable=var, exportselection=0)
Chui Tey72a8a3b2002-11-04 23:07:51 +000053 e.grid(row=self.row, col=1, sticky="nwe")
David Scherer7aced172000-08-15 01:13:23 +000054 self.row = self.row + 1
55 return e
56
Chui Tey72a8a3b2002-11-04 23:07:51 +000057 def make_frame(self,labeltext=None):
58 if labeltext:
59 l = Label(self.top, text=labeltext)
60 l.grid(row=self.row, col=0, sticky="nw")
David Scherer7aced172000-08-15 01:13:23 +000061 f = Frame(self.top)
Chui Tey72a8a3b2002-11-04 23:07:51 +000062 f.grid(row=self.row, col=1, columnspan=1, sticky="nwe")
David Scherer7aced172000-08-15 01:13:23 +000063 self.row = self.row + 1
64 return f
65
Chui Tey72a8a3b2002-11-04 23:07:51 +000066 def make_button(self, label, command, isdef=0):
David Scherer7aced172000-08-15 01:13:23 +000067 b = Button(self.buttonframe,
68 text=label, command=command,
69 default=isdef and "active" or "normal")
Chui Tey72a8a3b2002-11-04 23:07:51 +000070 cols,rows=self.buttonframe.grid_size()
71 b.grid(pady=1,row=rows,column=0,sticky="ew")
72 self.buttonframe.grid(rowspan=rows+1)
David Scherer7aced172000-08-15 01:13:23 +000073 return b
74
75 def create_entries(self):
76 self.ent = self.make_entry("Find:", self.engine.patvar)
77
78 def create_option_buttons(self):
Chui Tey72a8a3b2002-11-04 23:07:51 +000079 f = self.make_frame("Options")
David Scherer7aced172000-08-15 01:13:23 +000080
81 btn = Checkbutton(f, anchor="w",
82 variable=self.engine.revar,
83 text="Regular expression")
84 btn.pack(side="left", fill="both")
85 if self.engine.isre():
86 btn.select()
87
88 btn = Checkbutton(f, anchor="w",
89 variable=self.engine.casevar,
90 text="Match case")
91 btn.pack(side="left", fill="both")
92 if self.engine.iscase():
93 btn.select()
94
95 btn = Checkbutton(f, anchor="w",
96 variable=self.engine.wordvar,
97 text="Whole word")
98 btn.pack(side="left", fill="both")
99 if self.engine.isword():
100 btn.select()
101
102 if self.needwrapbutton:
103 btn = Checkbutton(f, anchor="w",
104 variable=self.engine.wrapvar,
105 text="Wrap around")
106 btn.pack(side="left", fill="both")
107 if self.engine.iswrap():
108 btn.select()
109
110 def create_other_buttons(self):
Chui Tey72a8a3b2002-11-04 23:07:51 +0000111 f = self.make_frame("Direction")
David Scherer7aced172000-08-15 01:13:23 +0000112
Chui Tey72a8a3b2002-11-04 23:07:51 +0000113 #lbl = Label(f, text="Direction: ")
114 #lbl.pack(side="left")
David Scherer7aced172000-08-15 01:13:23 +0000115
116 btn = Radiobutton(f, anchor="w",
117 variable=self.engine.backvar, value=1,
118 text="Up")
119 btn.pack(side="left", fill="both")
120 if self.engine.isback():
121 btn.select()
122
123 btn = Radiobutton(f, anchor="w",
124 variable=self.engine.backvar, value=0,
125 text="Down")
126 btn.pack(side="left", fill="both")
127 if not self.engine.isback():
128 btn.select()
129
130 def create_command_buttons(self):
Chui Tey72a8a3b2002-11-04 23:07:51 +0000131 #
132 # place button frame on the right
133 f = self.buttonframe = Frame(self.top)
134 f.grid(row=0,col=2,padx=2,pady=2,ipadx=2,ipady=2)
135
136 b = self.make_button("close", self.close)
David Scherer7aced172000-08-15 01:13:23 +0000137 b.lower()