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 from Tkinter import *
26 import Pmw
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
49
51 optiondefs = (
52 ('relief', 'ridge', None),
53 ('width', 640, None),
54 ('height', 480, None),
55 ('background', 'gray50', None),
56 ('borderwidth', 2, None),
57 ('foreground', 'navy', None),
58 ('readyText',"Windows",Pmw.INITOPT),
59 )
60 self.defineoptions(kw, optiondefs)
61
62
63 Pmw.MegaWidget.__init__(self, parent)
64
65 self.propagate(0)
66 self.parent = parent
67 self.children = []
68 self.stack = []
69
70
71
72
73
74 self.configure(hull_width = self['width'])
75 self.configure(hull_height = self['height'])
76 self.configure(hull_relief = self['relief'])
77 self.configure(hull_background = self['background'])
78
79
80
81
82 self.BottomBar = self.createcomponent('BottomBar',
83 (), 'Mygroup',
84 Frame, (self.interior(),), relief = "groove",
85
86 borderwidth = 3)
87 self.Btitle = self.createcomponent('Btitle',
88 (), 'Mygroup',
89 Label, (self.BottomBar,),
90 text = self['readyText'],
91 width=10,
92
93 borderwidth=3, relief="ridge", anchor="w")
94 self.BottomBar.pack(side='bottom', expand = 0, fill='x')
95 self.Btitle.pack(side='left', expand = 0, padx = 3, pady = 3)
96
97 self.initialiseoptions(MultipleWin)
98
100 """Updates the color of all L{InnerWindow} children
101 """
102 for w in self.children:
103 w.setTitleColor()
104
106 """Find a plausible current window (i.e one which is different than avoid and which is not iconified). If no window is available return avoid.
107 """
108 try:
109 return self.stack[-1]
110 except IndexError:
111 l = self.children[:]
112 while True:
113 if len(l) == 0: return avoid
114 if l[0] == avoid or l[0].iconified:
115 del l[0]
116 else:
117 return l[0]
118
120 widgets = [self.BottomBar,self.Btitle]
121 total = self.winfo_height()
122 for win in widgets:
123 total -= win.winfo_height()
124 return total
125
126
127
128
129
130
132
133 mycursors = ["top_left_corner", "top_side", "top_right_corner",
134 "left_side", "crosshair", "right_side",
135 "bottom_left_corner", "bottom_side", "bottom_right_corner"]
136
137
138
139
140
142 if not hasattr( InnerWindow, 'bitmap_cross' ) :
143 InnerWindow.bitmap_cross = BitmapImage(data = """
144 #define im_width 10
145 #define im_height 10
146 static unsigned char im_bits[] = {
147 0,0,0,0,0xc,3,0x9c,3,0xf8,
148 1,0xf0,0,0xf0,0,0xf8,1,0x9c,3,0x0c,3
149 };""" )
150 if not hasattr( InnerWindow, 'bitmap_icon' ) :
151 InnerWindow.bitmap_icon = BitmapImage(data = """
152 #define im_width 10
153 #define im_height 10
154 static unsigned char im_bits[] = {
155 0,0,0,0,0,0,0,0,
156 0,0,0,0,0,0,0xfc,3,0xfc,3,0,0
157 };""" )
158 if not hasattr( InnerWindow, 'bitmap_max' ) :
159 InnerWindow.bitmap_max = BitmapImage(data = """
160 #define im_width 10
161 #define im_height 10
162 static unsigned char im_bits[] = {
163 0,0,0,0,0xfc,3,0xfc,
164 3,0xfc,3,0xfc,3,0xfc,3,0xfc,3,0xfc,3,0xfc,3
165 };""" )
166 if not hasattr( InnerWindow, 'bitmap_min' ) :
167 InnerWindow.bitmap_min = BitmapImage(data = """
168 #define im_width 10
169 #define im_height 10
170 static unsigned char im_bits[] = {
171 0,0,0,0,0,0,0,0,0xf0,
172 0,0xf0,0,0xf0,0,0xf0,0,0,0,0,0
173 };""" )
174
175
176 bd = 15
177
179 palette = Pmw.Color.getdefaultpalette(parent.parent)
180 optiondefs = (
181 ('relief', 'ridge', None),
182 ('title','Inner Window',self.setTitle),
183 ('width', 320, None),
184 ('height', 240, None),
185 ('x', 20, None),
186 ('y', 20, None),
187 ('background', palette['background'], None),
188 ('borderwidth', 2, None),
189 ('foreground', palette['foreground'], None),
190 ('destroycommand',None,Pmw.INITOPT),
191 )
192 self.defineoptions(kw, optiondefs)
193
194
195 Pmw.MegaWidget.__init__(self, parent.interior())
196 self.propagate(0)
197 self.width = self['width']
198 self.height = self['height']
199 self.configure(hull_width = self['width'])
200 self.configure(hull_height = self['height'])
201 self.configure(hull_relief = self['relief'])
202 self.configure(hull_borderwidth = 3)
203 self.parent = parent
204 self.frame = self.createcomponent('frame',(), 'Mygroup',Frame,
205 (self.interior(),), cursor ="left_ptr",
206 background = self['background'],
207 borderwidth = 0,
208 )
209 self.frame.pack(fill='both',expand=1)
210 self.createcomponent('title',(), 'Mygroup',Frame,
211 (self.component('frame'),),
212 borderwidth=2, relief='raised',
213 ).pack(side = 'top', fill = 'x', expand = 0)
214
215 self.createcomponent('label',(), 'Mygroup',Label,
216 (self.component('title'),),
217 cursor = "fleur",
218 ).pack(side='left', expand = 1, fill = 'x')
219 self.createBitmaps()
220 if self['destroycommand']:
221 self.createcomponent('destroy',(), 'Mygroup',Button,
222 (self.component('title'),),
223 image = InnerWindow.bitmap_cross,
224 command = self.destroy,
225 ).pack(side = 'right')
226 self.createcomponent('maximize',(), 'Mygroup',Button,
227 (self.component('title'),),
228 image = InnerWindow.bitmap_max,
229 command = self.minormax,
230 ).pack(side = 'right')
231 self.createcomponent('iconify',(), 'Mygroup',
232 Button, (self.component('title'),),
233 image = InnerWindow.bitmap_icon,
234 command = self.iconify_window,
235 ).pack(side = 'right')
236
237 self.maximized = False
238 self.visible = IntVar()
239 self.visible.set(1)
240 self.iconified = 0
241 self.myindex = 0
242 self.resizing = None
243
244
245 self.make_inner_window_bindings(None)
246
247 parent.children.append(self)
248
249 self.initialiseoptions(InnerWindow)
250
252 self.component('label').configure(text=self['title'])
253 try:
254 widget = self.component('icon')
255 widget.configure(text=self['title'],
256 width=min(len(self['title']),15))
257 except KeyError:
258 pass
259
265
274
282
284 """Updates the title color of this window
285 """
286 palette = Pmw.Color.getdefaultpalette(self.parent.parent)
287 if len(self.parent.stack) > 0 and self is self.parent.stack[-1]:
288 self.component('label').configure(fg=palette['selectForeground'],
289 bg=palette['selectBackground'])
290 else:
291 self.component('label').configure(fg=palette['foreground'],
292 bg=palette['background'])
293
299
303
319
321 if not self.maximized :
322 self.mwraise()
323 self.maximized = True
324 self['x'] = self.winfo_x()
325 self['y'] = self.winfo_y()
326 self.width = self.winfo_width()
327 self.height = self.winfo_height()
328
329 self.pack(fill = 'both', expand = 1)
330
331 but = self.component('maximize')
332 but.configure(image = InnerWindow.bitmap_min)
333
343
345 if not self.iconified:
346 parent = self.parent
347 self.visible.set(0)
348 self.iconified = True
349 self.unselect_window()
350 self.minimize_window()
351
352 if self.winfo_y() > 2 and self.winfo_width() > 20 and \
353 self.winfo_height() > 20:
354 self['x'] = self.winfo_x()
355 self['y'] = self.winfo_y()
356 self.width = self.winfo_width()
357 self.height = self.winfo_height()
358
359 bar = parent.BottomBar
360 title = self.component('label').cget('text')
361 b = self.createcomponent('icon',(),None,Button,(bar,),
362 text = title,
363 font = "-adobe-helvetica-*-r-*-*-*-100-*-*-*-*-*-*",
364 width = min(len(title), 15),
365 anchor = "w",
366 command = self.show_window)
367 b.pack(side = 'left', expand = 0, fill = 'none')
368 self.place_forget()
369
371 if self.iconified:
372 self.iconified = None
373 self.visible.set(1)
374 self.place( x = self['x'],
375 y = self['y'],
376 width = self.width,
377 height = self.height )
378
379 self.destroycomponent('icon')
380 else:
381
382 self.mwraise()
383
384
390
394
396 x = event.x_root
397 y = event.y_root
398 self.mwraise()
399 self['x'] = x
400 self['y'] = y
401
403 x = event.x_root
404 y = event.y_root
405 if not self.maximized:
406 self.update_idletasks()
407 myy = self.encloseY(y)
408 myx = self.encloseX(x,25)
409 self.place(x = myx, y = myy)
410 self['x'] = x
411 self['y'] = y
412
414 return min(max(self.winfo_x() + (x - self['x']),0),
415 self.parent.winfo_width()-pad)
416
418 return min(max(self.winfo_y() + (y - self['y']),0),
419 self.parent.height()-pad)
420
424
426 x = event.x
427 y = event.y
428 w = self.winfo_width()
429 h = self.winfo_height()
430 bd = self.bd
431 ci = 0
432 if y < bd :
433 ci = 0
434 elif y < (h - bd) :
435 ci = 3
436 else:
437 ci = 6
438 if x < bd :
439 ci = ci
440 elif x < (w - bd) :
441 ci = ci + 1
442 else :
443 ci = ci + 2
444 self.myindex = ci
445 self.interior().config(cursor = self.mycursors[ci])
446
448 x = event.x_root
449 y = event.y_root
450 if (not self.resizing) and (not self.maximized) :
451 self.resizing = True
452 index = self.myindex
453 width = self.winfo_width()
454 height = self.winfo_height()
455 parent = self.parent
456 parentHeight = parent.height()
457 parentWidth = parent.winfo_width()
458 off_x = parent.winfo_rootx()
459 off_y = parent.winfo_rooty()
460 x1 = self.winfo_rootx() - off_x
461 y1 = self.winfo_rooty() - off_y
462 x2 = x1 + width
463 y2 = y1 + height
464 if index == 0:
465 x1 = min(max(x - off_x,0),x2-25,parentWidth-25)
466 y1 = min(max(y - off_y,0),y2-25,parentHeight)
467 elif index == 1:
468 y1 = min(max(y - off_y,0),y2-25,parentHeight)
469 elif index == 2:
470 x2 = min(max(x - off_x,x1+25),parentWidth)
471 elif index == 3:
472 x1 = min(max(x - off_x,0),x2-25,parentWidth-25)
473 elif index == 5:
474 x2 = min(max(x - off_x,x1+25),parentWidth)
475 elif index == 6:
476 x1 = min(max(x - off_x,0),x2-25,parentWidth-25)
477 y2 = min(max(y - off_y,y1+25),parentHeight)
478 elif index == 7:
479 y2 = min(max(y - off_y,y1+25),parentHeight)
480 elif index == 8:
481 x2 = min(max(x - off_x,x1+25),parentWidth)
482 y2 = min(max(y - off_y,y1+25),parentHeight)
483 self.place(in_ = parent, x = x1, y = y1,
484 width = (x2 - x1), height = (y2 - y1))
485 self.resizing = False
486
487
488
489
490
491
492
509
510
511
512
513 Pmw.forwardmethods(MultipleWin, Frame, MultipleWin.interior)
514 Pmw.forwardmethods(InnerWindow, Frame, InnerWindow.interior)
515