9 |
|
|
10 |
__version__ = "$Revision$" |
__version__ = "$Revision$" |
11 |
|
|
12 |
|
import resource |
13 |
|
|
14 |
from Thuban import _ |
from Thuban import _ |
15 |
|
|
16 |
from wxPython.wx import * |
from wxPython.wx import * |
21 |
|
|
22 |
from messages import DOCKABLE_DOCKED, DOCKABLE_UNDOCKED, DOCKABLE_CLOSED |
from messages import DOCKABLE_DOCKED, DOCKABLE_UNDOCKED, DOCKABLE_CLOSED |
23 |
|
|
|
import gc |
|
|
|
|
24 |
ID_BUTTON_DOCK = 4001 |
ID_BUTTON_DOCK = 4001 |
25 |
ID_BUTTON_CLOSE = 4002 |
ID_BUTTON_CLOSE = 4002 |
26 |
|
|
27 |
PANEL_ID = 3141 |
PANEL_ID = 3141 |
28 |
|
|
29 |
|
DOCK_BMP = "dock_12" |
30 |
|
UNDOCK_BMP = "undock_12" |
31 |
|
CLOSE_BMP = "close_12" |
32 |
|
|
33 |
class DockPanel(wxPanel): |
class DockPanel(wxPanel): |
34 |
|
|
35 |
def __init__(self, parent, id): |
def __init__(self, parent, id): |
39 |
|
|
40 |
wxPanel.__init__(self, parent.GetCurrentParent(), id) |
wxPanel.__init__(self, parent.GetCurrentParent(), id) |
41 |
|
|
42 |
|
self.parent = parent |
43 |
|
|
44 |
#self.SetDockParent(None) |
#self.SetDockParent(None) |
45 |
parent.SetPanel(self) |
#parent.SetPanel(self) |
46 |
|
|
47 |
|
def Create(self): |
48 |
|
self.parent.SetPanel(self) |
49 |
|
|
50 |
def SetDockParent(self, parent): |
def SetDockParent(self, parent): |
51 |
self.__dockParent = parent |
self.__dockParent = parent |
52 |
|
|
73 |
class DockableWindow(Publisher): |
class DockableWindow(Publisher): |
74 |
|
|
75 |
def __getattr__(self, attr): |
def __getattr__(self, attr): |
|
|
|
|
#print attr |
|
76 |
return getattr(self.__topWindow, attr) |
return getattr(self.__topWindow, attr) |
|
#try: |
|
|
#except AttributeError: |
|
|
#raise |
|
|
#return self.__dict__[attr] |
|
|
#return getattr(self, attr) |
|
|
#pass |
|
77 |
|
|
78 |
def __init__(self, parent, id, name, |
def __init__(self, parent, id, name, title, dockWindow, orient): |
79 |
title, dockWindow, orient): #, panel, docked = False, show = True): |
"""Create the dockable window. |
80 |
|
|
81 |
|
Initially, the window is hidden, but in an undocked state. |
82 |
|
""" |
83 |
|
|
84 |
if not isinstance(parent, DockFrame): raise TypeError("") |
if not isinstance(parent, DockFrame): raise TypeError("") |
85 |
|
|
90 |
self.__orientation = orient |
self.__orientation = orient |
91 |
|
|
92 |
self.__dockWindow = dockWindow |
self.__dockWindow = dockWindow |
|
#self.__floatWindow = NonModalDialog(parent, name, title) |
|
93 |
self.__floatWindow = wxFrame(parent, id, title) |
self.__floatWindow = wxFrame(parent, id, title) |
94 |
|
|
95 |
self.__docked = False |
self.__docked = False |
|
|
|
|
self.__dockPanel = None |
|
|
|
|
96 |
if self.__docked: |
if self.__docked: |
97 |
self.__topWindow = self.__dockWindow |
self.__topWindow = self.__dockWindow |
98 |
else: |
else: |
101 |
self.__floatSize = None |
self.__floatSize = None |
102 |
self.__floatPosition = None |
self.__floatPosition = None |
103 |
|
|
104 |
|
self.__dockPanel = None |
105 |
self.__panel = None |
self.__panel = None |
106 |
|
|
107 |
self.__dockWindow.Hide() |
self.__dockWindow.Hide() |
163 |
self.__topWindow = self.__dockWindow |
self.__topWindow = self.__dockWindow |
164 |
self.__dockPanel.Reparent(self.__topWindow) |
self.__dockPanel.Reparent(self.__topWindow) |
165 |
|
|
166 |
self.__dockButton.SetLabel(_("Undock")) |
#self.__dockButton.SetBitmapLabel(self.__bmpUnDock) |
167 |
|
#self.__dockButton.SetBitmapFocus(self.__bmpUnDock) |
168 |
|
self.__dockButton.SetToolTip(wxToolTip(_("Undock"))) |
169 |
|
|
170 |
self.SetDockSize(self.__dockWindow.GetSize()) |
self.SetDockSize(self.__dockWindow.GetSize()) |
171 |
|
|
172 |
if wasVisible: self.Show(True) |
if wasVisible: self.Show(True) |
173 |
|
|
|
#self.__parent._UpdateDocks() |
|
|
|
|
174 |
self.issue(DOCKABLE_DOCKED, self.__id, self) |
self.issue(DOCKABLE_DOCKED, self.__id, self) |
175 |
|
|
176 |
def UnDock(self): |
def UnDock(self): |
188 |
self.__topWindow = self.__floatWindow |
self.__topWindow = self.__floatWindow |
189 |
self.__dockPanel.Reparent(self.__topWindow) |
self.__dockPanel.Reparent(self.__topWindow) |
190 |
|
|
191 |
self.__dockButton.SetLabel(_("Dock")) |
#self.__dockButton.SetBitmapLabel(self.__bmpDock) |
192 |
|
#self.__dockButton.SetBitmapFocus(self.__bmpDock) |
193 |
|
self.__dockButton.SetToolTip(wxToolTip(_("Dock"))) |
194 |
|
|
195 |
if wasVisible: self.Show() |
if wasVisible: self.Show() |
196 |
|
|
197 |
# |
# |
198 |
# restore window information |
# restore window information |
199 |
# |
# |
200 |
#if self.__floatPosition is not None: self.SetPosition(self.__floatPosition) |
if self.__floatPosition is not None: |
201 |
#if self.__floatSize is not None: self.SetSize(self.__floatSize) |
self.SetPosition(self.__floatPosition) |
202 |
|
if self.__floatSize is not None: |
203 |
|
self.SetSize(self.__floatSize) |
204 |
|
|
205 |
|
self.__dockPanel.SetSize(self.__topWindow.GetClientSize()) |
206 |
|
|
207 |
self.issue(DOCKABLE_UNDOCKED, self.__id, self) |
self.issue(DOCKABLE_UNDOCKED, self.__id, self) |
208 |
|
|
209 |
def IsDocked(self): |
def IsDocked(self): |
210 |
self.__CheckAllGood() |
self.__CheckAllGood() |
|
|
|
211 |
return self.__docked |
return self.__docked |
212 |
|
|
|
|
|
213 |
def Show(self, show = True): |
def Show(self, show = True): |
214 |
if show: |
if show: |
215 |
self.__DoShow() |
self.__DoShow() |
218 |
|
|
219 |
def SetDockSize(self, rect = None): |
def SetDockSize(self, rect = None): |
220 |
|
|
|
# |
|
|
# adjust the size to get the |
|
221 |
w0, h0 = self.__dockPanel.GetBestSize() |
w0, h0 = self.__dockPanel.GetBestSize() |
222 |
w, h = self.__panel.GetBestSize() |
w, h = self.__panel.GetBestSize() |
223 |
|
|
|
#print (w0, h0), (w, h) |
|
|
|
|
224 |
if (w, h) < (w0, h0): |
if (w, h) < (w0, h0): |
225 |
w = w0 |
w = w0 |
226 |
h = h0 |
h = h0 |
227 |
|
|
228 |
if rect is not None: |
if rect is not None: |
229 |
rw = rect.width |
rw = rect.width |
230 |
rh = rect.height |
rh = rect.height |
|
#print " ", (rw, rh) |
|
231 |
if rw < w: rw = w |
if rw < w: rw = w |
232 |
if rh < h: rh = h |
if rh < h: rh = h |
233 |
else: |
else: |
241 |
self.__dockWindow.SetDefaultSize(wxSize(rw, rh)) |
self.__dockWindow.SetDefaultSize(wxSize(rw, rh)) |
242 |
|
|
243 |
|
|
244 |
def Close(self): |
def Destroy(self): |
245 |
self.__panel.Close(True) |
self.__panel.Destroy() |
246 |
self.__floatWindow.Destroy() |
self.__floatWindow.Destroy() |
247 |
self.__dockWindow.Destroy() |
self.__dockWindow.Destroy() |
248 |
self.__parent.OnDockClose(self) |
self.__parent.OnDockDestroy(self) |
249 |
|
|
250 |
## |
## |
251 |
# Event handlers |
# Event handlers |
252 |
# |
# |
253 |
|
|
254 |
def _OnButtonClose(self, event): |
def _OnButtonClose(self, event): |
255 |
self.Close() |
#self.Close() |
256 |
|
self.Show(False) |
257 |
|
|
258 |
def _OnClose(self, force = False): |
def _OnClose(self, force = False): |
259 |
self.Close() |
self.Show(False) |
260 |
|
|
261 |
def _OnToggleDock(self, event): |
def _OnToggleDock(self, event): |
262 |
self.__CheckAllGood() |
self.__CheckAllGood() |
273 |
|
|
274 |
def __DoShow(self): |
def __DoShow(self): |
275 |
if self.IsShown(): return |
if self.IsShown(): return |
|
#print "__DoShow()", self.IsShown() |
|
276 |
|
|
277 |
self.__topWindow.Show() |
self.__topWindow.Show() |
278 |
|
|
|
#if self.IsDocked(): |
|
|
#self.SetDockSize() |
|
|
|
|
279 |
if self.__topWindow is self.__dockWindow: |
if self.__topWindow is self.__dockWindow: |
280 |
self.__parent._UpdateDocks() |
self.__parent._UpdateDocks() |
281 |
|
|
282 |
def __DoHide(self): |
def __DoHide(self): |
283 |
if not self.IsShown(): return |
if not self.IsShown(): return |
284 |
#print "__DoHide()", self.IsShown() |
|
285 |
self.__topWindow.Show(False) |
self.__topWindow.Show(False) |
286 |
|
|
287 |
if self.__topWindow is self.__dockWindow: |
if self.__topWindow is self.__dockWindow: |
288 |
self.__parent._UpdateDocks() |
self.__parent._UpdateDocks() |
289 |
|
|
|
|
|
290 |
def __CreateBorder(self): |
def __CreateBorder(self): |
291 |
|
|
|
#self.__panel.Reparent(self) # Make sure we hang on to the panel |
|
|
|
|
292 |
self.__dockPanel = wxPanel(self.__topWindow, -1, style=wxSUNKEN_BORDER) |
self.__dockPanel = wxPanel(self.__topWindow, -1, style=wxSUNKEN_BORDER) |
293 |
#self.__dockPanel.SetBackgroundColour(wxColour(255, 0, 0)) |
|
294 |
|
self.__panel.Reparent(self.__dockPanel) |
295 |
|
self.__panel.SetId(PANEL_ID) |
296 |
|
|
297 |
if self.__orientation == wxLAYOUT_VERTICAL: |
if self.__orientation == wxLAYOUT_VERTICAL: |
298 |
sizer = wxBoxSizer(wxVERTICAL) |
sizer = wxBoxSizer(wxVERTICAL) |
305 |
headerBox = wxStaticBoxSizer( |
headerBox = wxStaticBoxSizer( |
306 |
wxStaticBox(self.__dockPanel, -1, ""), headerBoxOrient) |
wxStaticBox(self.__dockPanel, -1, ""), headerBoxOrient) |
307 |
|
|
|
buttonBox = wxBoxSizer(wxHORIZONTAL) |
|
|
|
|
308 |
# |
# |
309 |
# ideally, we should be able to rotate this text depending on |
# ideally, we should be able to rotate this text depending on |
310 |
# our orientation |
# our orientation |
311 |
# |
# |
312 |
text = wxStaticText(self.__dockPanel, -1, self.GetTitle(), |
text = wxStaticText(self.__dockPanel, -1, self.GetTitle(), |
313 |
style = wxSIMPLE_BORDER | wxALIGN_CENTRE) |
style = wxALIGN_CENTRE) |
314 |
|
font = text.GetFont() |
315 |
|
font.SetPointSize(10) |
316 |
|
text.SetFont(font) |
317 |
|
|
318 |
# |
# |
319 |
# Perhaps using wxToggleButton would be better, but it's only |
# load the dock/undock/close bitmaps |
320 |
# supported under wxMSW and wxGTK as of v2.4.0.3 |
# and create the buttons |
321 |
# |
# |
322 |
self.__dockButton = wxButton(self.__dockPanel, ID_BUTTON_DOCK, "WWWWWW", |
self.__bmpDock = \ |
323 |
style = wxBU_EXACTFIT | wxADJUST_MINSIZE) |
resource.GetBitmapResource(DOCK_BMP, wxBITMAP_TYPE_XPM) |
324 |
|
self.__bmpUnDock = \ |
325 |
|
resource.GetBitmapResource(UNDOCK_BMP, wxBITMAP_TYPE_XPM) |
326 |
|
|
327 |
closeX = wxButton(self.__dockPanel, ID_BUTTON_CLOSE, "X", |
if self.__docked: |
328 |
style = wxBU_EXACTFIT | wxADJUST_MINSIZE) |
bmp = self.__bmpDock |
329 |
|
else: |
330 |
|
bmp = self.__bmpUnDock |
331 |
|
|
332 |
buttonBox.Add(self.__dockButton, 0, wxALIGN_RIGHT, 0) |
self.__dockButton = wxBitmapButton( |
333 |
buttonBox.Add(closeX, 0, wxALIGN_RIGHT, 0) |
self.__dockPanel, ID_BUTTON_DOCK, |
334 |
|
bmp, |
335 |
|
size = wxSize(bmp.GetWidth() + 4, bmp.GetHeight() + 4), |
336 |
|
style = wxBU_EXACTFIT | wxADJUST_MINSIZE) |
337 |
|
|
338 |
|
bmp = resource.GetBitmapResource(CLOSE_BMP, wxBITMAP_TYPE_XPM) |
339 |
|
|
340 |
|
closeX = wxBitmapButton(self.__dockPanel, ID_BUTTON_CLOSE, bmp, |
341 |
|
size = wxSize(bmp.GetWidth() + 4, |
342 |
|
bmp.GetHeight() + 4), |
343 |
|
style = wxBU_EXACTFIT | wxADJUST_MINSIZE) |
344 |
|
closeX.SetToolTip(wxToolTip(_("Close"))) |
345 |
|
|
346 |
|
# |
347 |
|
# fill in the sizer in an order appropriate to the orientation |
348 |
|
# |
349 |
if self.__orientation == wxLAYOUT_VERTICAL: |
if self.__orientation == wxLAYOUT_VERTICAL: |
350 |
headerBox.Add(text, 0, wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL, 0) |
headerBox.Add(text, 0, wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL, 0) |
351 |
headerBox.Add(1, 20, 1, wxGROW) |
headerBox.Add(1, 5, 1, wxGROW) |
352 |
headerBox.Add(buttonBox, 0, wxGROW | wxALIGN_RIGHT, 0) |
headerBox.Add(self.__dockButton, 0, wxALIGN_RIGHT, 0) |
353 |
|
headerBox.Add(closeX, 0, wxALIGN_RIGHT | wxLEFT, 4) |
354 |
else: |
else: |
355 |
headerBox.Add(buttonBox, 0, wxGROW, 0) |
headerBox.Add(closeX, 0, wxALIGN_RIGHT | wxBOTTOM, 4) |
356 |
|
headerBox.Add(self.__dockButton, 0, wxALIGN_RIGHT, 0) |
357 |
headerBox.Add(text, 0, wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL, 0) |
headerBox.Add(text, 0, wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL, 0) |
358 |
|
|
359 |
sizer.Add(headerBox, 0, wxGROW, 0) |
sizer.Add(headerBox, 0, wxGROW, 0) |
|
|
|
|
self.__panel.Reparent(self.__dockPanel) |
|
|
self.__panel.SetId(PANEL_ID) |
|
|
|
|
360 |
sizer.Add(self.__panel, 1, wxGROW, 0) |
sizer.Add(self.__panel, 1, wxGROW, 0) |
361 |
|
|
|
sizer.Fit(self.__dockPanel) |
|
362 |
|
|
|
self.__dockPanel.SetSizer(sizer) |
|
363 |
self.__dockPanel.SetAutoLayout(True) |
self.__dockPanel.SetAutoLayout(True) |
364 |
|
self.__dockPanel.SetSizer(sizer) |
365 |
sizer.SetSizeHints(self.__dockPanel) |
sizer.SetSizeHints(self.__dockPanel) |
366 |
|
sizer.SetSizeHints(self.__floatWindow) |
367 |
|
|
368 |
EVT_BUTTON(self.__dockPanel, ID_BUTTON_DOCK, self._OnToggleDock) |
EVT_BUTTON(self.__dockPanel, ID_BUTTON_DOCK, self._OnToggleDock) |
369 |
EVT_BUTTON(self.__dockPanel, ID_BUTTON_CLOSE, self._OnButtonClose) |
EVT_BUTTON(self.__dockPanel, ID_BUTTON_CLOSE, self._OnButtonClose) |
376 |
|
|
377 |
self.openWindows = {} |
self.openWindows = {} |
378 |
|
|
379 |
EVT_SIZE(self, self._OnSashSize) |
self.__update_lock = 0 |
380 |
|
|
381 |
self.SetMainWindow(None) |
self.SetMainWindow(None) |
382 |
|
|
383 |
|
|
384 |
|
EVT_SIZE(self, self._OnSashSize) |
385 |
|
EVT_CLOSE(self, self._OnClose) |
386 |
|
|
387 |
layout2oppSash = { |
layout2oppSash = { |
388 |
wxLAYOUT_NONE : wxSASH_NONE, |
wxLAYOUT_NONE : wxSASH_NONE, |
389 |
wxLAYOUT_TOP : wxSASH_BOTTOM, |
wxLAYOUT_TOP : wxSASH_BOTTOM, |
391 |
wxLAYOUT_RIGHT : wxSASH_LEFT, |
wxLAYOUT_RIGHT : wxSASH_LEFT, |
392 |
wxLAYOUT_BOTTOM : wxSASH_TOP } |
wxLAYOUT_BOTTOM : wxSASH_TOP } |
393 |
|
|
394 |
|
|
395 |
|
def _OnClose(self, event): |
396 |
|
|
397 |
|
self.__update_lock += 1 |
398 |
|
|
399 |
|
# |
400 |
|
# child windows are not notified when the parent is destroyed |
401 |
|
# as of v2.4.0.3 so we need to interate over our children |
402 |
|
# and tell them to go away. |
403 |
|
# |
404 |
|
for key in self.openWindows.keys(): |
405 |
|
win = self.openWindows[key] |
406 |
|
win.Destroy() |
407 |
|
|
408 |
|
self.__update_lock -= 1 |
409 |
|
|
410 |
|
# should really call _UpdateDocks() here but we don't need to |
411 |
|
# since we're going away |
412 |
|
|
413 |
def CreateDock(self, name, id, title, align): |
def CreateDock(self, name, id, title, align): |
414 |
|
|
415 |
if align in (wxLAYOUT_NONE, wxLAYOUT_LEFT, wxLAYOUT_RIGHT): |
if align in (wxLAYOUT_NONE, wxLAYOUT_LEFT, wxLAYOUT_RIGHT): |
420 |
sash = wxSashLayoutWindow(self, id, style=wxNO_BORDER|wxSW_3D) |
sash = wxSashLayoutWindow(self, id, style=wxNO_BORDER|wxSW_3D) |
421 |
sash.SetOrientation(orient) |
sash.SetOrientation(orient) |
422 |
sash.SetAlignment(align) |
sash.SetAlignment(align) |
|
#print align, DockFrame.layout2oppSash[align] |
|
423 |
sash.SetSashVisible(DockFrame.layout2oppSash[align], True) |
sash.SetSashVisible(DockFrame.layout2oppSash[align], True) |
424 |
sash.SetSashBorder(DockFrame.layout2oppSash[align], True) |
sash.SetSashBorder(DockFrame.layout2oppSash[align], True) |
425 |
|
|
433 |
def FindRegisteredDock(self, name): |
def FindRegisteredDock(self, name): |
434 |
return self.openWindows.get(name) |
return self.openWindows.get(name) |
435 |
|
|
436 |
def OnDockClose(self, win): |
def OnDockDestroy(self, win): |
437 |
del self.openWindows[win.GetName()] |
del self.openWindows[win.GetName()] |
438 |
self._UpdateDocks() |
self._UpdateDocks() |
439 |
|
|
442 |
self._UpdateDocks() |
self._UpdateDocks() |
443 |
|
|
444 |
def _UpdateDocks(self): |
def _UpdateDocks(self): |
445 |
#print "_UpdateDocks()" |
if self.__update_lock == 0: |
446 |
wxLayoutAlgorithm().LayoutWindow(self, self.__mainWindow) |
wxLayoutAlgorithm().LayoutWindow(self, self.__mainWindow) |
447 |
|
|
448 |
def _OnSashDragged(self, event): |
def _OnSashDragged(self, event): |
449 |
if event.GetDragStatus() == wxSASH_STATUS_OUT_OF_RANGE: |
if event.GetDragStatus() == wxSASH_STATUS_OUT_OF_RANGE: |
453 |
sash = self.FindWindowById(id) |
sash = self.FindWindowById(id) |
454 |
#assert(isinstance(win, wxPanel)) |
#assert(isinstance(win, wxPanel)) |
455 |
dockPanel = sash.GetChildren()[0] |
dockPanel = sash.GetChildren()[0] |
|
#print dockPanel |
|
456 |
panel = dockPanel.FindWindowById(PANEL_ID) |
panel = dockPanel.FindWindowById(PANEL_ID) |
457 |
#print panel |
assert isinstance(panel, DockPanel) |
|
assert(isinstance(panel, DockPanel)) |
|
458 |
win = panel.GetDockParent() |
win = panel.GetDockParent() |
459 |
#print win |
assert isinstance(win, DockableWindow) |
|
assert(isinstance(win, DockableWindow)) |
|
460 |
|
|
461 |
assert(win.IsDocked()) |
assert win.IsDocked() |
462 |
|
|
463 |
rect = event.GetDragRect() |
rect = event.GetDragRect() |
464 |
|
|