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