]>
Commit | Line | Data |
---|---|---|
d14a1e28 RD |
1 | #---------------------------------------------------------------------- |
2 | # Name: multisash | |
3 | # Purpose: Multi Sash control | |
4 | # | |
5 | # Author: Gerrit van Dyk | |
6 | # | |
7 | # Created: 2002/11/20 | |
8 | # Version: 0.1 | |
9 | # RCS-ID: $Id$ | |
d4b73b1b | 10 | # License: wxWindows license |
d14a1e28 | 11 | #---------------------------------------------------------------------- |
b881fc78 RD |
12 | # 12/09/2003 - Jeff Grimmett (grimmtooth@softhome.net) |
13 | # | |
14 | # o 2.5 compatability update. | |
15 | # | |
d4b73b1b RD |
16 | # 12/20/2003 - Jeff Grimmett (grimmtooth@softhome.net) |
17 | # | |
18 | # o wxMultiSash -> MultiSash | |
19 | # o wxMultiSplit -> MultiSplit wxMultiViewLeaf | |
20 | # o wxMultiViewLeaf -> MultiViewLeaf | |
21 | # | |
1fded56b | 22 | |
b881fc78 | 23 | import wx |
1fded56b | 24 | |
d14a1e28 RD |
25 | MV_HOR = 0 |
26 | MV_VER = not MV_HOR | |
27 | ||
28 | SH_SIZE = 5 | |
29 | CR_SIZE = SH_SIZE * 3 | |
30 | ||
31 | #---------------------------------------------------------------------- | |
32 | ||
d4b73b1b | 33 | class MultiSash(wx.Window): |
d14a1e28 | 34 | def __init__(self, *_args,**_kwargs): |
b881fc78 | 35 | apply(wx.Window.__init__,(self,) + _args,_kwargs) |
d14a1e28 | 36 | self._defChild = EmptyChild |
d4b73b1b | 37 | self.child = MultiSplit(self,self,(0,0),self.GetSize()) |
b881fc78 | 38 | self.Bind(wx.EVT_SIZE,self.OnMultiSize) |
d14a1e28 RD |
39 | |
40 | def SetDefaultChildClass(self,childCls): | |
41 | self._defChild = childCls | |
42 | self.child.DefaultChildChanged() | |
43 | ||
44 | def OnMultiSize(self,evt): | |
45 | self.child.SetSize(self.GetSize()) | |
46 | ||
47 | def UnSelect(self): | |
48 | self.child.UnSelect() | |
49 | ||
50 | def Clear(self): | |
51 | old = self.child | |
d4b73b1b | 52 | self.child = MultiSplit(self,self,(0,0),self.GetSize()) |
d14a1e28 RD |
53 | old.Destroy() |
54 | self.child.OnSize(None) | |
55 | ||
56 | def GetSaveData(self): | |
57 | saveData = {} | |
58 | saveData['_defChild'] = str(self._defChild) | |
59 | saveData['child'] = self.child.GetSaveData() | |
60 | return saveData | |
61 | ||
62 | def SetSaveData(self,data): | |
63 | dChild = data['_defChild'] | |
64 | mod = dChild.split('.')[0] | |
65 | exec 'import %s' % mod | |
66 | self._defChild = eval(dChild) | |
67 | old = self.child | |
d4b73b1b | 68 | self.child = MultiSplit(self,self,wxPoint(0,0),self.GetSize()) |
d14a1e28 RD |
69 | self.child.SetSaveData(data['child']) |
70 | old.Destroy() | |
71 | self.OnMultiSize(None) | |
72 | self.child.OnSize(None) | |
73 | ||
74 | ||
75 | #---------------------------------------------------------------------- | |
76 | ||
77 | ||
d4b73b1b | 78 | class MultiSplit(wx.Window): |
d14a1e28 | 79 | def __init__(self,multiView,parent,pos,size,view1 = None): |
b881fc78 RD |
80 | wx.Window.__init__(self,id = -1,parent = parent,pos = pos,size = size, |
81 | style = wx.CLIP_CHILDREN) | |
d14a1e28 RD |
82 | self.multiView = multiView |
83 | self.view2 = None | |
84 | if view1: | |
85 | self.view1 = view1 | |
86 | self.view1.Reparent(self) | |
87 | self.view1.MoveXY(0,0) | |
88 | else: | |
d4b73b1b | 89 | self.view1 = MultiViewLeaf(self.multiView,self, |
b881fc78 | 90 | (0,0),self.GetSize()) |
d14a1e28 RD |
91 | self.direction = None |
92 | ||
b881fc78 | 93 | self.Bind(wx.EVT_SIZE,self.OnSize) |
d14a1e28 RD |
94 | |
95 | def GetSaveData(self): | |
96 | saveData = {} | |
97 | if self.view1: | |
98 | saveData['view1'] = self.view1.GetSaveData() | |
d4b73b1b | 99 | if isinstance(self.view1,MultiSplit): |
d14a1e28 RD |
100 | saveData['view1IsSplit'] = 1 |
101 | if self.view2: | |
102 | saveData['view2'] = self.view2.GetSaveData() | |
d4b73b1b | 103 | if isinstance(self.view2,MultiSplit): |
d14a1e28 RD |
104 | saveData['view2IsSplit'] = 1 |
105 | saveData['direction'] = self.direction | |
b881fc78 | 106 | v1,v2 = self.GetPosition() |
d14a1e28 RD |
107 | saveData['x'] = v1 |
108 | saveData['y'] = v2 | |
b881fc78 | 109 | v1,v2 = self.GetSize() |
d14a1e28 RD |
110 | saveData['w'] = v1 |
111 | saveData['h'] = v2 | |
112 | return saveData | |
113 | ||
114 | def SetSaveData(self,data): | |
115 | self.direction = data['direction'] | |
226b6402 | 116 | self.SetDimensions(int(data['x']), int(data['y']), int(data['w']), int(data['h'])) |
d14a1e28 RD |
117 | v1Data = data.get('view1',None) |
118 | if v1Data: | |
119 | isSplit = data.get('view1IsSplit',None) | |
120 | old = self.view1 | |
121 | if isSplit: | |
d4b73b1b | 122 | self.view1 = MultiSplit(self.multiView,self, |
b881fc78 | 123 | (0,0),self.GetSize()) |
d14a1e28 | 124 | else: |
d4b73b1b | 125 | self.view1 = MultiViewLeaf(self.multiView,self, |
b881fc78 | 126 | (0,0),self.GetSize()) |
d14a1e28 RD |
127 | self.view1.SetSaveData(v1Data) |
128 | if old: | |
129 | old.Destroy() | |
130 | v2Data = data.get('view2',None) | |
131 | if v2Data: | |
132 | isSplit = data.get('view2IsSplit',None) | |
133 | old = self.view2 | |
134 | if isSplit: | |
d4b73b1b | 135 | self.view2 = MultiSplit(self.multiView,self, |
b881fc78 | 136 | (0,0),self.GetSize()) |
d14a1e28 | 137 | else: |
d4b73b1b | 138 | self.view2 = MultiViewLeaf(self.multiView,self, |
b881fc78 | 139 | (0,0),self.GetSize()) |
d14a1e28 RD |
140 | self.view2.SetSaveData(v2Data) |
141 | if old: | |
142 | old.Destroy() | |
143 | if self.view1: | |
144 | self.view1.OnSize(None) | |
145 | if self.view2: | |
146 | self.view2.OnSize(None) | |
147 | ||
148 | def UnSelect(self): | |
149 | if self.view1: | |
150 | self.view1.UnSelect() | |
151 | if self.view2: | |
152 | self.view2.UnSelect() | |
153 | ||
154 | def DefaultChildChanged(self): | |
155 | if not self.view2: | |
156 | self.view1.DefaultChildChanged() | |
157 | ||
158 | def AddLeaf(self,direction,caller,pos): | |
159 | if self.view2: | |
160 | if caller == self.view1: | |
d4b73b1b | 161 | self.view1 = MultiSplit(self.multiView,self, |
d14a1e28 RD |
162 | caller.GetPosition(), |
163 | caller.GetSize(), | |
164 | caller) | |
165 | self.view1.AddLeaf(direction,caller,pos) | |
166 | else: | |
d4b73b1b | 167 | self.view2 = MultiSplit(self.multiView,self, |
d14a1e28 RD |
168 | caller.GetPosition(), |
169 | caller.GetSize(), | |
170 | caller) | |
171 | self.view2.AddLeaf(direction,caller,pos) | |
172 | else: | |
173 | self.direction = direction | |
b881fc78 | 174 | w,h = self.GetSize() |
d14a1e28 RD |
175 | if direction == MV_HOR: |
176 | x,y = (pos,0) | |
177 | w1,h1 = (w-pos,h) | |
178 | w2,h2 = (pos,h) | |
179 | else: | |
180 | x,y = (0,pos) | |
181 | w1,h1 = (w,h-pos) | |
182 | w2,h2 = (w,pos) | |
d4b73b1b | 183 | self.view2 = MultiViewLeaf(self.multiView, self, (x,y), (w1,h1)) |
b881fc78 | 184 | self.view1.SetSize((w2,h2)) |
d14a1e28 RD |
185 | self.view2.OnSize(None) |
186 | ||
187 | def DestroyLeaf(self,caller): | |
188 | if not self.view2: # We will only have 2 windows if | |
189 | return # we need to destroy any | |
190 | parent = self.GetParent() # Another splitview | |
191 | if parent == self.multiView: # We'r at the root | |
192 | if caller == self.view1: | |
193 | old = self.view1 | |
194 | self.view1 = self.view2 | |
195 | self.view2 = None | |
196 | old.Destroy() | |
197 | else: | |
198 | self.view2.Destroy() | |
199 | self.view2 = None | |
200 | self.view1.SetSize(self.GetSize()) | |
201 | self.view1.Move(self.GetPosition()) | |
202 | else: | |
b881fc78 RD |
203 | w,h = self.GetSize() |
204 | x,y = self.GetPosition() | |
d14a1e28 RD |
205 | if caller == self.view1: |
206 | if self == parent.view1: | |
207 | parent.view1 = self.view2 | |
208 | else: | |
209 | parent.view2 = self.view2 | |
210 | self.view2.Reparent(parent) | |
211 | self.view2.SetDimensions(x,y,w,h) | |
212 | else: | |
213 | if self == parent.view1: | |
214 | parent.view1 = self.view1 | |
215 | else: | |
216 | parent.view2 = self.view1 | |
217 | self.view1.Reparent(parent) | |
218 | self.view1.SetDimensions(x,y,w,h) | |
219 | self.view1 = None | |
220 | self.view2 = None | |
221 | self.Destroy() | |
222 | ||
223 | def CanSize(self,side,view): | |
224 | if self.SizeTarget(side,view): | |
225 | return True | |
226 | return False | |
227 | ||
228 | def SizeTarget(self,side,view): | |
229 | if self.direction == side and self.view2 and view == self.view1: | |
230 | return self | |
231 | parent = self.GetParent() | |
232 | if parent != self.multiView: | |
233 | return parent.SizeTarget(side,self) | |
234 | return None | |
235 | ||
236 | def SizeLeaf(self,leaf,pos,side): | |
237 | if self.direction != side: | |
238 | return | |
239 | if not (self.view1 and self.view2): | |
240 | return | |
241 | if pos < 10: return | |
b881fc78 | 242 | w,h = self.GetSize() |
d14a1e28 RD |
243 | if side == MV_HOR: |
244 | if pos > w - 10: return | |
245 | else: | |
246 | if pos > h - 10: return | |
247 | if side == MV_HOR: | |
248 | self.view1.SetDimensions(0,0,pos,h) | |
249 | self.view2.SetDimensions(pos,0,w-pos,h) | |
250 | else: | |
251 | self.view1.SetDimensions(0,0,w,pos) | |
252 | self.view2.SetDimensions(0,pos,w,h-pos) | |
253 | ||
254 | def OnSize(self,evt): | |
255 | if not self.view2: | |
256 | self.view1.SetSize(self.GetSize()) | |
257 | self.view1.OnSize(None) | |
258 | return | |
b881fc78 RD |
259 | v1w,v1h = self.view1.GetSize() |
260 | v2w,v2h = self.view2.GetSize() | |
261 | v1x,v1y = self.view1.GetPosition() | |
262 | v2x,v2y = self.view2.GetPosition() | |
263 | w,h = self.GetSize() | |
d14a1e28 RD |
264 | |
265 | if v1x != v2x: | |
266 | ratio = float(w) / float((v1w + v2w)) | |
267 | v1w *= ratio | |
268 | v2w = w - v1w | |
269 | v2x = v1w | |
270 | else: | |
271 | v1w = v2w = w | |
272 | ||
273 | if v1y != v2y: | |
274 | ratio = float(h) / float((v1h + v2h)) | |
275 | v1h *= ratio | |
276 | v2h = h - v1h | |
277 | v2y = v1h | |
278 | else: | |
279 | v1h = v2h = h | |
280 | ||
226b6402 RD |
281 | self.view1.SetDimensions(int(v1x), int(v1y), int(v1w), int(v1h)) |
282 | self.view2.SetDimensions(int(v2x), int(v2y), int(v2w), int(v2h)) | |
d14a1e28 RD |
283 | self.view1.OnSize(None) |
284 | self.view2.OnSize(None) | |
285 | ||
286 | ||
287 | #---------------------------------------------------------------------- | |
288 | ||
289 | ||
d4b73b1b | 290 | class MultiViewLeaf(wx.Window): |
d14a1e28 | 291 | def __init__(self,multiView,parent,pos,size): |
b881fc78 RD |
292 | wx.Window.__init__(self,id = -1,parent = parent,pos = pos,size = size, |
293 | style = wx.CLIP_CHILDREN) | |
d14a1e28 RD |
294 | self.multiView = multiView |
295 | ||
296 | self.sizerHor = MultiSizer(self,MV_HOR) | |
297 | self.sizerVer = MultiSizer(self,MV_VER) | |
298 | self.creatorHor = MultiCreator(self,MV_HOR) | |
299 | self.creatorVer = MultiCreator(self,MV_VER) | |
300 | self.detail = MultiClient(self,multiView._defChild) | |
301 | self.closer = MultiCloser(self) | |
302 | ||
b881fc78 | 303 | self.Bind(wx.EVT_SIZE,self.OnSize) |
d14a1e28 RD |
304 | |
305 | def GetSaveData(self): | |
306 | saveData = {} | |
307 | saveData['detailClass'] = str(self.detail.child.__class__) | |
308 | if hasattr(self.detail.child,'GetSaveData'): | |
309 | attr = getattr(self.detail.child,'GetSaveData') | |
310 | if callable(attr): | |
311 | dData = attr() | |
312 | if dData: | |
313 | saveData['detail'] = dData | |
b881fc78 | 314 | v1,v2 = self.GetPosition() |
d14a1e28 RD |
315 | saveData['x'] = v1 |
316 | saveData['y'] = v2 | |
b881fc78 | 317 | v1,v2 = self.GetSize() |
d14a1e28 RD |
318 | saveData['w'] = v1 |
319 | saveData['h'] = v2 | |
320 | return saveData | |
321 | ||
322 | def SetSaveData(self,data): | |
323 | dChild = data['detailClass'] | |
324 | mod = dChild.split('.')[0] | |
325 | exec 'import %s' % mod | |
326 | detClass = eval(dChild) | |
327 | self.SetDimensions(data['x'],data['y'],data['w'],data['h']) | |
328 | old = self.detail | |
329 | self.detail = MultiClient(self,detClass) | |
330 | dData = data.get('detail',None) | |
331 | if dData: | |
332 | if hasattr(self.detail.child,'SetSaveData'): | |
333 | attr = getattr(self.detail.child,'SetSaveData') | |
334 | if callable(attr): | |
335 | attr(dData) | |
336 | old.Destroy() | |
337 | self.detail.OnSize(None) | |
338 | ||
339 | def UnSelect(self): | |
340 | self.detail.UnSelect() | |
341 | ||
342 | def DefaultChildChanged(self): | |
343 | self.detail.SetNewChildCls(self.multiView._defChild) | |
344 | ||
345 | def AddLeaf(self,direction,pos): | |
346 | if pos < 10: return | |
b881fc78 | 347 | w,h = self.GetSize() |
d14a1e28 RD |
348 | if direction == MV_VER: |
349 | if pos > h - 10: return | |
350 | else: | |
351 | if pos > w - 10: return | |
352 | self.GetParent().AddLeaf(direction,self,pos) | |
353 | ||
354 | def DestroyLeaf(self): | |
355 | self.GetParent().DestroyLeaf(self) | |
356 | ||
357 | def SizeTarget(self,side): | |
358 | return self.GetParent().SizeTarget(side,self) | |
359 | ||
360 | def CanSize(self,side): | |
361 | return self.GetParent().CanSize(side,self) | |
362 | ||
363 | def OnSize(self,evt): | |
364 | self.sizerHor.OnSize(evt) | |
365 | self.sizerVer.OnSize(evt) | |
366 | self.creatorHor.OnSize(evt) | |
367 | self.creatorVer.OnSize(evt) | |
368 | self.detail.OnSize(evt) | |
369 | self.closer.OnSize(evt) | |
370 | ||
371 | #---------------------------------------------------------------------- | |
372 | ||
373 | ||
b881fc78 | 374 | class MultiClient(wx.Window): |
d14a1e28 RD |
375 | def __init__(self,parent,childCls): |
376 | w,h = self.CalcSize(parent) | |
b881fc78 RD |
377 | wx.Window.__init__(self,id = -1,parent = parent, |
378 | pos = (0,0), | |
379 | size = (w,h), | |
380 | style = wx.CLIP_CHILDREN | wx.SUNKEN_BORDER) | |
d14a1e28 RD |
381 | self.child = childCls(self) |
382 | self.child.MoveXY(2,2) | |
383 | self.normalColour = self.GetBackgroundColour() | |
384 | self.selected = False | |
385 | ||
b881fc78 RD |
386 | self.Bind(wx.EVT_SET_FOCUS,self.OnSetFocus) |
387 | self.Bind(wx.EVT_CHILD_FOCUS,self.OnChildFocus) | |
d14a1e28 RD |
388 | |
389 | def UnSelect(self): | |
390 | if self.selected: | |
391 | self.selected = False | |
392 | self.SetBackgroundColour(self.normalColour) | |
393 | self.Refresh() | |
394 | ||
395 | def Select(self): | |
396 | self.GetParent().multiView.UnSelect() | |
397 | self.selected = True | |
b881fc78 | 398 | self.SetBackgroundColour(wx.Colour(255,255,0)) # Yellow |
d14a1e28 RD |
399 | self.Refresh() |
400 | ||
401 | def CalcSize(self,parent): | |
b881fc78 | 402 | w,h = parent.GetSize() |
d14a1e28 RD |
403 | w -= SH_SIZE |
404 | h -= SH_SIZE | |
405 | return (w,h) | |
406 | ||
407 | def OnSize(self,evt): | |
408 | w,h = self.CalcSize(self.GetParent()) | |
409 | self.SetDimensions(0,0,w,h) | |
b881fc78 RD |
410 | w,h = self.GetClientSize() |
411 | self.child.SetSize((w-4,h-4)) | |
d14a1e28 RD |
412 | |
413 | def SetNewChildCls(self,childCls): | |
414 | if self.child: | |
415 | self.child.Destroy() | |
416 | self.child = None | |
417 | self.child = childCls(self) | |
418 | self.child.MoveXY(2,2) | |
419 | ||
420 | def OnSetFocus(self,evt): | |
421 | self.Select() | |
422 | ||
423 | def OnChildFocus(self,evt): | |
424 | self.OnSetFocus(evt) | |
425 | ## from Funcs import FindFocusedChild | |
426 | ## child = FindFocusedChild(self) | |
b881fc78 | 427 | ## child.Bind(wx.EVT_KILL_FOCUS,self.OnChildKillFocus) |
d14a1e28 RD |
428 | |
429 | ||
430 | #---------------------------------------------------------------------- | |
431 | ||
432 | ||
b881fc78 | 433 | class MultiSizer(wx.Window): |
d14a1e28 RD |
434 | def __init__(self,parent,side): |
435 | self.side = side | |
436 | x,y,w,h = self.CalcSizePos(parent) | |
b881fc78 RD |
437 | wx.Window.__init__(self,id = -1,parent = parent, |
438 | pos = (x,y), | |
439 | size = (w,h), | |
440 | style = wx.CLIP_CHILDREN) | |
d14a1e28 RD |
441 | |
442 | self.px = None # Previous X | |
443 | self.py = None # Previous Y | |
444 | self.isDrag = False # In Dragging | |
445 | self.dragTarget = None # View being sized | |
446 | ||
b881fc78 RD |
447 | self.Bind(wx.EVT_LEAVE_WINDOW,self.OnLeave) |
448 | self.Bind(wx.EVT_ENTER_WINDOW,self.OnEnter) | |
449 | self.Bind(wx.EVT_MOTION,self.OnMouseMove) | |
450 | self.Bind(wx.EVT_LEFT_DOWN,self.OnPress) | |
451 | self.Bind(wx.EVT_LEFT_UP,self.OnRelease) | |
d14a1e28 RD |
452 | |
453 | def CalcSizePos(self,parent): | |
b881fc78 | 454 | pw,ph = parent.GetSize() |
d14a1e28 RD |
455 | if self.side == MV_HOR: |
456 | x = CR_SIZE + 2 | |
457 | y = ph - SH_SIZE | |
458 | w = pw - CR_SIZE - SH_SIZE - 2 | |
459 | h = SH_SIZE | |
460 | else: | |
461 | x = pw - SH_SIZE | |
462 | y = CR_SIZE + 2 + SH_SIZE | |
463 | w = SH_SIZE | |
464 | h = ph - CR_SIZE - SH_SIZE - 4 - SH_SIZE # For Closer | |
465 | return (x,y,w,h) | |
466 | ||
467 | def OnSize(self,evt): | |
468 | x,y,w,h = self.CalcSizePos(self.GetParent()) | |
469 | self.SetDimensions(x,y,w,h) | |
470 | ||
471 | def OnLeave(self,evt): | |
b881fc78 | 472 | self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW)) |
d14a1e28 RD |
473 | |
474 | def OnEnter(self,evt): | |
475 | if not self.GetParent().CanSize(not self.side): | |
476 | return | |
477 | if self.side == MV_HOR: | |
b881fc78 | 478 | self.SetCursor(wx.StockCursor(wx.CURSOR_SIZENS)) |
d14a1e28 | 479 | else: |
b881fc78 | 480 | self.SetCursor(wx.StockCursor(wx.CURSOR_SIZEWE)) |
d14a1e28 RD |
481 | |
482 | def OnMouseMove(self,evt): | |
483 | if self.isDrag: | |
484 | DrawSash(self.dragTarget,self.px,self.py,self.side) | |
485 | self.px,self.py = self.ClientToScreenXY(evt.m_x,evt.m_y) | |
486 | self.px,self.py = self.dragTarget.ScreenToClientXY(self.px,self.py) | |
487 | DrawSash(self.dragTarget,self.px,self.py,self.side) | |
488 | else: | |
489 | evt.Skip() | |
490 | ||
491 | def OnPress(self,evt): | |
492 | self.dragTarget = self.GetParent().SizeTarget(not self.side) | |
493 | if self.dragTarget: | |
494 | self.isDrag = True | |
495 | self.px,self.py = self.ClientToScreenXY(evt.m_x,evt.m_y) | |
496 | self.px,self.py = self.dragTarget.ScreenToClientXY(self.px,self.py) | |
497 | DrawSash(self.dragTarget,self.px,self.py,self.side) | |
498 | self.CaptureMouse() | |
499 | else: | |
500 | evt.Skip() | |
501 | ||
502 | def OnRelease(self,evt): | |
503 | if self.isDrag: | |
504 | DrawSash(self.dragTarget,self.px,self.py,self.side) | |
505 | self.ReleaseMouse() | |
506 | self.isDrag = False | |
507 | if self.side == MV_HOR: | |
508 | self.dragTarget.SizeLeaf(self.GetParent(), | |
509 | self.py,not self.side) | |
510 | else: | |
511 | self.dragTarget.SizeLeaf(self.GetParent(), | |
512 | self.px,not self.side) | |
513 | self.dragTarget = None | |
514 | else: | |
515 | evt.Skip() | |
516 | ||
517 | #---------------------------------------------------------------------- | |
518 | ||
519 | ||
b881fc78 | 520 | class MultiCreator(wx.Window): |
d14a1e28 RD |
521 | def __init__(self,parent,side): |
522 | self.side = side | |
523 | x,y,w,h = self.CalcSizePos(parent) | |
b881fc78 RD |
524 | wx.Window.__init__(self,id = -1,parent = parent, |
525 | pos = (x,y), | |
526 | size = (w,h), | |
527 | style = wx.CLIP_CHILDREN) | |
d14a1e28 RD |
528 | |
529 | self.px = None # Previous X | |
530 | self.py = None # Previous Y | |
531 | self.isDrag = False # In Dragging | |
532 | ||
b881fc78 RD |
533 | self.Bind(wx.EVT_LEAVE_WINDOW,self.OnLeave) |
534 | self.Bind(wx.EVT_ENTER_WINDOW,self.OnEnter) | |
535 | self.Bind(wx.EVT_MOTION,self.OnMouseMove) | |
536 | self.Bind(wx.EVT_LEFT_DOWN,self.OnPress) | |
537 | self.Bind(wx.EVT_LEFT_UP,self.OnRelease) | |
538 | self.Bind(wx.EVT_PAINT,self.OnPaint) | |
d14a1e28 RD |
539 | |
540 | def CalcSizePos(self,parent): | |
b881fc78 | 541 | pw,ph = parent.GetSize() |
d14a1e28 RD |
542 | if self.side == MV_HOR: |
543 | x = 2 | |
544 | y = ph - SH_SIZE | |
545 | w = CR_SIZE | |
546 | h = SH_SIZE | |
547 | else: | |
548 | x = pw - SH_SIZE | |
549 | y = 4 + SH_SIZE # Make provision for closer | |
550 | w = SH_SIZE | |
551 | h = CR_SIZE | |
552 | return (x,y,w,h) | |
553 | ||
554 | def OnSize(self,evt): | |
555 | x,y,w,h = self.CalcSizePos(self.GetParent()) | |
556 | self.SetDimensions(x,y,w,h) | |
557 | ||
558 | def OnLeave(self,evt): | |
b881fc78 | 559 | self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW)) |
d14a1e28 RD |
560 | |
561 | def OnEnter(self,evt): | |
562 | if self.side == MV_HOR: | |
b881fc78 | 563 | self.SetCursor(wx.StockCursor(wx.CURSOR_HAND)) |
d14a1e28 | 564 | else: |
b881fc78 | 565 | self.SetCursor(wx.StockCursor(wx.CURSOR_POINT_LEFT)) |
d14a1e28 RD |
566 | |
567 | def OnMouseMove(self,evt): | |
568 | if self.isDrag: | |
569 | parent = self.GetParent() | |
570 | DrawSash(parent,self.px,self.py,self.side) | |
571 | self.px,self.py = self.ClientToScreenXY(evt.m_x,evt.m_y) | |
572 | self.px,self.py = parent.ScreenToClientXY(self.px,self.py) | |
573 | DrawSash(parent,self.px,self.py,self.side) | |
574 | else: | |
575 | evt.Skip() | |
576 | ||
577 | def OnPress(self,evt): | |
578 | self.isDrag = True | |
579 | parent = self.GetParent() | |
580 | self.px,self.py = self.ClientToScreenXY(evt.m_x,evt.m_y) | |
581 | self.px,self.py = parent.ScreenToClientXY(self.px,self.py) | |
582 | DrawSash(parent,self.px,self.py,self.side) | |
583 | self.CaptureMouse() | |
584 | ||
585 | def OnRelease(self,evt): | |
586 | if self.isDrag: | |
587 | parent = self.GetParent() | |
588 | DrawSash(parent,self.px,self.py,self.side) | |
589 | self.ReleaseMouse() | |
590 | self.isDrag = False | |
591 | ||
592 | if self.side == MV_HOR: | |
593 | parent.AddLeaf(MV_VER,self.py) | |
594 | else: | |
595 | parent.AddLeaf(MV_HOR,self.px) | |
596 | else: | |
597 | evt.Skip() | |
598 | ||
599 | def OnPaint(self,evt): | |
b881fc78 RD |
600 | dc = wx.PaintDC(self) |
601 | dc.SetBackground(wx.Brush(self.GetBackgroundColour(),wx.SOLID)) | |
d14a1e28 RD |
602 | dc.Clear() |
603 | ||
b881fc78 RD |
604 | highlight = wx.Pen(wx.SystemSettings_GetColour(wx.SYS_COLOUR_BTNHIGHLIGHT), 1, wx.SOLID) |
605 | shadow = wx.Pen(wx.SystemSettings_GetColour(wx.SYS_COLOUR_BTNSHADOW), 1, wx.SOLID) | |
606 | black = wx.Pen(wx.BLACK,1,wx.SOLID) | |
607 | w,h = self.GetSize() | |
d14a1e28 RD |
608 | w -= 1 |
609 | h -= 1 | |
610 | ||
611 | # Draw outline | |
612 | dc.SetPen(highlight) | |
7722248d RD |
613 | dc.DrawLine((0,0), (0,h)) |
614 | dc.DrawLine((0,0), (w,0)) | |
d14a1e28 | 615 | dc.SetPen(black) |
7722248d RD |
616 | dc.DrawLine((0,h), (w+1,h)) |
617 | dc.DrawLine((w,0), (w,h)) | |
d14a1e28 | 618 | dc.SetPen(shadow) |
7722248d | 619 | dc.DrawLine((w-1,2), (w-1,h)) |
d14a1e28 RD |
620 | |
621 | #---------------------------------------------------------------------- | |
622 | ||
623 | ||
b881fc78 | 624 | class MultiCloser(wx.Window): |
d14a1e28 RD |
625 | def __init__(self,parent): |
626 | x,y,w,h = self.CalcSizePos(parent) | |
b881fc78 RD |
627 | wx.Window.__init__(self,id = -1,parent = parent, |
628 | pos = (x,y), | |
629 | size = (w,h), | |
630 | style = wx.CLIP_CHILDREN) | |
d14a1e28 RD |
631 | |
632 | self.down = False | |
633 | self.entered = False | |
634 | ||
b881fc78 RD |
635 | self.Bind(wx.EVT_LEFT_DOWN,self.OnPress) |
636 | self.Bind(wx.EVT_LEFT_UP,self.OnRelease) | |
637 | self.Bind(wx.EVT_PAINT,self.OnPaint) | |
638 | self.Bind(wx.EVT_LEAVE_WINDOW,self.OnLeave) | |
639 | self.Bind(wx.EVT_ENTER_WINDOW,self.OnEnter) | |
d14a1e28 RD |
640 | |
641 | def OnLeave(self,evt): | |
b881fc78 | 642 | self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW)) |
d14a1e28 RD |
643 | self.entered = False |
644 | ||
645 | def OnEnter(self,evt): | |
b881fc78 | 646 | self.SetCursor(wx.StockCursor(wx.CURSOR_BULLSEYE)) |
d14a1e28 RD |
647 | self.entered = True |
648 | ||
649 | def OnPress(self,evt): | |
650 | self.down = True | |
651 | evt.Skip() | |
652 | ||
653 | def OnRelease(self,evt): | |
654 | if self.down and self.entered: | |
655 | self.GetParent().DestroyLeaf() | |
656 | else: | |
657 | evt.Skip() | |
658 | self.down = False | |
659 | ||
660 | def OnPaint(self,evt): | |
b881fc78 RD |
661 | dc = wx.PaintDC(self) |
662 | dc.SetBackground(wx.Brush(wx.RED,wx.SOLID)) | |
d14a1e28 RD |
663 | dc.Clear() |
664 | ||
665 | def CalcSizePos(self,parent): | |
b881fc78 | 666 | pw,ph = parent.GetSize() |
d14a1e28 RD |
667 | x = pw - SH_SIZE |
668 | w = SH_SIZE | |
669 | h = SH_SIZE + 2 | |
670 | y = 1 | |
671 | return (x,y,w,h) | |
672 | ||
673 | def OnSize(self,evt): | |
674 | x,y,w,h = self.CalcSizePos(self.GetParent()) | |
675 | self.SetDimensions(x,y,w,h) | |
676 | ||
677 | ||
678 | #---------------------------------------------------------------------- | |
679 | ||
680 | ||
b881fc78 | 681 | class EmptyChild(wx.Window): |
d14a1e28 | 682 | def __init__(self,parent): |
b881fc78 | 683 | wx.Window.__init__(self,parent,-1, style = wx.CLIP_CHILDREN) |
d14a1e28 RD |
684 | |
685 | ||
686 | #---------------------------------------------------------------------- | |
687 | ||
688 | ||
689 | def DrawSash(win,x,y,direction): | |
b881fc78 | 690 | dc = wx.ScreenDC() |
d14a1e28 | 691 | dc.StartDrawingOnTopWin(win) |
b881fc78 RD |
692 | bmp = wx.EmptyBitmap(8,8) |
693 | bdc = wx.MemoryDC() | |
d14a1e28 | 694 | bdc.SelectObject(bmp) |
7722248d | 695 | bdc.DrawRectangle((-1,-1), (10,10)) |
d14a1e28 RD |
696 | for i in range(8): |
697 | for j in range(8): | |
698 | if ((i + j) & 1): | |
7722248d | 699 | bdc.DrawPoint((i,j)) |
d14a1e28 | 700 | |
b881fc78 | 701 | brush = wx.Brush(wx.Colour(0,0,0)) |
d14a1e28 RD |
702 | brush.SetStipple(bmp) |
703 | ||
704 | dc.SetBrush(brush) | |
b881fc78 | 705 | dc.SetLogicalFunction(wx.XOR) |
d14a1e28 | 706 | |
b881fc78 | 707 | body_w,body_h = win.GetClientSize() |
d14a1e28 RD |
708 | |
709 | if y < 0: | |
710 | y = 0 | |
711 | if y > body_h: | |
712 | y = body_h | |
713 | if x < 0: | |
714 | x = 0 | |
715 | if x > body_w: | |
716 | x = body_w | |
717 | ||
718 | if direction == MV_HOR: | |
719 | x = 0 | |
720 | else: | |
721 | y = 0 | |
722 | ||
723 | x,y = win.ClientToScreenXY(x,y) | |
724 | ||
725 | w = body_w | |
726 | h = body_h | |
727 | ||
728 | if direction == MV_HOR: | |
7722248d | 729 | dc.DrawRectangle((x,y-2), (w,4)) |
d14a1e28 | 730 | else: |
7722248d | 731 | dc.DrawRectangle((x-2,y), (4,h)) |
d14a1e28 RD |
732 | |
733 | dc.EndDrawingOnTop() |