5 |
# This program is free software under the GPL (>=v2) |
# This program is free software under the GPL (>=v2) |
6 |
# Read the file COPYING coming with Thuban for details. |
# Read the file COPYING coming with Thuban for details. |
7 |
|
|
8 |
"""Classes for creating dockable windows""" |
"""Classes for creating dockable windows. |
9 |
|
|
10 |
|
The DockFrame is the main window that will be the parent for the |
11 |
|
dockable windows. |
12 |
|
|
13 |
|
The DockPanel is a panel that all windows that wish to be dockable |
14 |
|
should derive from. |
15 |
|
""" |
16 |
|
|
17 |
__version__ = "$Revision$" |
__version__ = "$Revision$" |
18 |
|
|
38 |
CLOSE_BMP = "close_12" |
CLOSE_BMP = "close_12" |
39 |
|
|
40 |
class DockPanel(wxPanel): |
class DockPanel(wxPanel): |
41 |
|
"""A DockPanel is a panel that should be derived from to create panels |
42 |
|
that can be docked in a DockFrame. |
43 |
|
""" |
44 |
|
|
45 |
def __init__(self, parent, id): |
def __init__(self, parent, id): |
46 |
|
"""parent should be a DockableWindow created from |
47 |
|
DockFrame.CreateDock(). |
48 |
|
""" |
49 |
|
|
50 |
if not isinstance(parent, DockableWindow): |
if not isinstance(parent, DockableWindow): |
51 |
raise TypeError("") |
raise TypeError("") |
67 |
return self.__dockParent |
return self.__dockParent |
68 |
|
|
69 |
def SetDock(self, dock): |
def SetDock(self, dock): |
70 |
|
"""Specifically set the docked state of the panel |
71 |
|
to dock (True or False). |
72 |
|
""" |
73 |
#if dock == self.IsDocked(): return |
#if dock == self.IsDocked(): return |
74 |
|
|
75 |
if dock: |
if dock: |
78 |
self.UnDock() |
self.UnDock() |
79 |
|
|
80 |
def Dock(self): |
def Dock(self): |
81 |
|
"""Dock the panel in the DockFrame.""" |
82 |
self.GetDockParent().Dock() |
self.GetDockParent().Dock() |
83 |
|
|
84 |
def UnDock(self): |
def UnDock(self): |
85 |
|
"""Undock the panel in the DockFrame.""" |
86 |
self.GetDockParent().UnDock() |
self.GetDockParent().UnDock() |
87 |
|
|
88 |
def IsDocked(self): |
def IsDocked(self): |
89 |
|
"""Return True if the panel is docked.""" |
90 |
return self.GetDockParent().IsDocked() |
return self.GetDockParent().IsDocked() |
91 |
|
|
92 |
class DockableWindow(Publisher): |
class DockableWindow(Publisher): |
162 |
self.UnDock() |
self.UnDock() |
163 |
|
|
164 |
def Dock(self): |
def Dock(self): |
165 |
|
"""Dock the window.""" |
166 |
self.__CheckAllGood() |
self.__CheckAllGood() |
167 |
|
|
168 |
wasVisible = self.IsShown() |
wasVisible = self.IsShown() |
196 |
self.issue(DOCKABLE_DOCKED, self.__id, self) |
self.issue(DOCKABLE_DOCKED, self.__id, self) |
197 |
|
|
198 |
def UnDock(self): |
def UnDock(self): |
199 |
|
"""Undock the window.""" |
200 |
self.__CheckAllGood() |
self.__CheckAllGood() |
201 |
|
|
202 |
wasVisible = self.IsShown() |
wasVisible = self.IsShown() |
236 |
return self.__docked |
return self.__docked |
237 |
|
|
238 |
def Show(self, show = True): |
def Show(self, show = True): |
239 |
|
"""Show or hide the window.""" |
240 |
if show: |
if show: |
241 |
self.__DoShow() |
self.__DoShow() |
242 |
else: |
else: |
243 |
self.__DoHide() |
self.__DoHide() |
244 |
|
|
245 |
def SetDockSize(self, rect = None): |
def SetDockSize(self, rect = None): |
246 |
|
"""Set the size of the dock window to rect.""" |
247 |
|
|
248 |
w0, h0 = self.__dockPanel.GetBestSize() |
w0, h0 = self.__dockPanel.GetBestSize() |
249 |
w, h = self.__panel.GetBestSize() |
w, h = self.__panel.GetBestSize() |
397 |
|
|
398 |
|
|
399 |
class DockFrame(wxFrame): |
class DockFrame(wxFrame): |
400 |
|
"""A DockFrame is a frame that will contain dockable panels.""" |
401 |
|
|
402 |
def __init__(self, parent, id, title, position, size): |
def __init__(self, parent, id, title, position, size): |
403 |
wxFrame.__init__(self, parent, id, title, position, size) |
wxFrame.__init__(self, parent, id, title, position, size) |
439 |
# since we're going away |
# since we're going away |
440 |
|
|
441 |
def CreateDock(self, name, id, title, align): |
def CreateDock(self, name, id, title, align): |
442 |
|
"""Create a new dock. align specifies where the dock will |
443 |
|
be placed. It can be one of wxLAYOUT_NONE, wxLAYOUT_LEFT, |
444 |
|
wxLAYOUT_RIGHT. |
445 |
|
""" |
446 |
|
|
447 |
if align in (wxLAYOUT_NONE, wxLAYOUT_LEFT, wxLAYOUT_RIGHT): |
if align in (wxLAYOUT_NONE, wxLAYOUT_LEFT, wxLAYOUT_RIGHT): |
448 |
orient = wxLAYOUT_VERTICAL |
orient = wxLAYOUT_VERTICAL |
463 |
return win |
return win |
464 |
|
|
465 |
def FindRegisteredDock(self, name): |
def FindRegisteredDock(self, name): |
466 |
|
"""Return a reference to a dock that has name.""" |
467 |
return self.openWindows.get(name) |
return self.openWindows.get(name) |
468 |
|
|
469 |
def OnDockDestroy(self, win): |
def OnDockDestroy(self, win): |