1
2
3 """
4 WizardShell provides a GUI wizard framework.
5
6 WizardShell was derived from AppShell which was itself
7 derived from GuiAppD.py, originally created by
8 Doug Hellmann (doughellmann@mindspring.com).
9
10 """
11
12 from Tkinter import *
13 import Pmw
14 import sys, string
15
16 from types import *
17
19 wizversion = '1.0'
20
21 frameWidth = 550
22 frameHeight = 357
23 padx = 5
24 pady = 5
25 panes = 4
26
27 busyCursor = 'watch'
28
30 self.__illustration = None
31 self.__wizimage = None
32 optiondefs = (
33 ('image', 'wizard.gif', self.changePicture),
34 ('name', 'Generic Wizard Frame', Pmw.INITOPT),
35 ('framewidth', 1, Pmw.INITOPT),
36 ('frameheight', 1, Pmw.INITOPT))
37 self.defineoptions(kw, optiondefs)
38 if parent:
39 self.root = Toplevel(parent)
40 else:
41 self.root = Tk()
42 Pmw.initialise(self.root)
43
44
45 self.root.title(self['name'])
46 self.root.geometry('%dx%d' % (self.frameWidth, self.frameHeight))
47
48
49 Pmw.MegaWidget.__init__(self, parent=self.root)
50
51
52 self.wizardInit()
53
54
55 self.pCurrent = 0
56 self.pFrame = [None] * self.panes
57
58
59 self.__createInterface()
60 self.changePicture()
61
62
63
64 self.preBusyCursors = None
65
66
67
68 self._hull.pack(side=TOP, fill=BOTH, expand=YES)
69 self.focus_set()
70
71
72 self.initialiseoptions(WizardShell)
73
77
86
88 root.option_add('*background', 'grey')
89 root.option_add('*foreground', 'black')
90 root.option_add('*EntryField.Entry.background', 'white')
91 root.option_add('*Entry.background', 'white')
92 root.option_add('*MessageBar.Entry.background', 'gray85')
93 root.option_add('*Listbox*background', 'white')
94 root.option_add('*Listbox*selectBackground', 'dark slate blue')
95 root.option_add('*Listbox*selectForeground', 'white')
96
98 self.__initializeTk_colors_common(root)
99 root.option_add('*Font', 'Verdana 10 bold')
100 root.option_add('*EntryField.Entry.Font', 'Courier 10')
101 root.option_add('*Listbox*Font', 'Courier 10')
102
105
108
110 if not newcursor:
111 newcursor = self.busyCursor
112 newPreBusyCursors = {}
113 for component in self.busyWidgets:
114 newPreBusyCursors[component] = component['cursor']
115 component.configure(cursor=newcursor)
116 component.update_idletasks()
117 self.preBusyCursors = (newPreBusyCursors, self.preBusyCursors)
118
120 if not self.preBusyCursors:
121 return
122 oldPreBusyCursors = self.preBusyCursors[0]
123 self.preBusyCursors = self.preBusyCursors[1]
124 for component in self.busyWidgets:
125 try:
126 component.configure(cursor=oldPreBusyCursors[component])
127 except KeyError:
128 pass
129 component.update_idletasks()
130
132
133 self.__illustration = self.createcomponent('illust',
134 (), None,
135 Label,
136 (self._hull,))
137
138 self.__illustration.grid(row=0,column=0,sticky='ns')
139 self._hull.columnconfigure(0,weight=0)
140
141 self.__dataArea = self.createcomponent('dataarea',
142 (), None,
143 Frame,
144 (self._hull,),
145 relief=FLAT, bd=1)
146
147 self.__dataArea.grid(row=0,column=1,sticky='ewns')
148 self._hull.columnconfigure(1,weight=1)
149 self._hull.rowconfigure(0,weight=1)
150
152 self.__separator = self.createcomponent('separator',
153 (), None,
154 Frame,
155 (self._hull,),
156 relief=SUNKEN,
157 bd=2, height=2)
158 self.__separator.grid(row=1,column=0,columnspan=2,sticky='ew')
159 self._hull.rowconfigure(1,minsize=5)
160
162
163 self.__commandFrame = self.createcomponent('commandframe',
164 (), None,
165 Frame,
166 (self._hull,),
167 relief=FLAT, bd=1)
168 self.__commandFrame.grid(row=2,column=0,columnspan=2,sticky='ew')
169 self._hull.rowconfigure(2,minsize=20)
170
172
173 return self.__dataArea
174
176 if self.__illustration:
177 if self.__wizimage: del self.__wizimage
178
179 if type(self['image']) is StringType:
180 try:
181 self.__wizimage = PhotoImage(file=self['image'])
182 except:
183 self.__wizimage = None
184 else:
185 self.__wizimage = self['image']
186 self.__illustration['image'] = self.__wizimage
187
196
198 for i in range(self.panes):
199 self.pFrame[i] = self.createcomponent('pframe'+str(i),
200 (), None,
201 Frame,
202 (self.interior(),),
203 relief=FLAT, bd=1)
204 if not i == self.pCurrent:
205 self.pFrame[i].forget()
206 else:
207 self.pFrame[i].pack(fill=BOTH, expand=YES)
208
210 return self.pFrame[idx]
211
213 cpane = self.pCurrent
214 self.pCurrent = self.pCurrent + 1
215 self.prevB['state'] = NORMAL
216 if self.pCurrent == self.panes - 1:
217 self.nextB['text'] = 'Finish'
218 self.nextB['command'] = self.done
219 self.pFrame[cpane].forget()
220 self.pFrame[self.pCurrent].pack(fill=BOTH, expand=YES)
221
223 cpane = self.pCurrent
224 self.pCurrent = self.pCurrent - 1
225 if self.pCurrent <= 0:
226 self.pCurrent = 0
227 self.prevB['state'] = DISABLED
228 if cpane == self.panes - 1:
229 self.nextB['text'] = 'Next'
230 self.nextB['command'] = self.next
231 self.pFrame[cpane].forget()
232 self.pFrame[self.pCurrent].pack(fill=BOTH, expand=YES)
233
237
249
253
255
256 self.pack()
257 try:
258 self.mainloop()
259 except KeyboardInterrupt:
260 self.done()
261
264
266
272
273 - def createMain(self):
274 self.w1 = self.createcomponent('w1', (), None,
275 Label,
276 (self.pInterior(0),),
277 text='Wizard Area 1')
278 self.w1.pack()
279 self.w2 = self.createcomponent('w2', (), None,
280 Label,
281 (self.pInterior(1),),
282 text='Wizard Area 2')
283 self.w2.pack()
284
289
292
293 if __name__ == '__main__':
294 test = TestWizardShell(image='Icons/faces.gif')
295 test.run()
296