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() |
183 |
self.__topWindow = self.__dockWindow |
self.__topWindow = self.__dockWindow |
184 |
self.__dockPanel.Reparent(self.__topWindow) |
self.__dockPanel.Reparent(self.__topWindow) |
185 |
|
|
186 |
if self.__bmpUnDock is not None: |
self.__dockButton.SetBitmapLabel(self.__bmpUnDock) |
187 |
self.__dockButton.SetBitmapLabel(self.__bmpUnDock) |
self.__dockButton.SetBitmapFocus(self.__bmpUnDock) |
188 |
self.__dockButton.SetBitmapFocus(self.__bmpUnDock) |
self.__dockButton.SetBitmapSelected(self.__bmpUnDock) |
189 |
self.__dockButton.SetToolTip(wxToolTip(_("Undock"))) |
self.__dockButton.SetBitmapDisabled(self.__bmpUnDock) |
190 |
else: |
self.__dockButton.SetToolTip(wxToolTip(_("Undock"))) |
|
self.__dockButton.SetLabel(_("Undock")) |
|
191 |
|
|
192 |
self.SetDockSize(self.__dockWindow.GetSize()) |
self.SetDockSize(self.__dockWindow.GetSize()) |
193 |
|
|
194 |
if wasVisible: self.Show(True) |
if wasVisible: self.Show(True) |
195 |
|
|
|
#self.__parent._UpdateDocks() |
|
|
|
|
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() |
211 |
self.__topWindow = self.__floatWindow |
self.__topWindow = self.__floatWindow |
212 |
self.__dockPanel.Reparent(self.__topWindow) |
self.__dockPanel.Reparent(self.__topWindow) |
213 |
|
|
214 |
if self.__bmpDock is not None: |
self.__dockButton.SetBitmapLabel(self.__bmpDock) |
215 |
self.__dockButton.SetBitmapLabel(self.__bmpDock) |
self.__dockButton.SetBitmapFocus(self.__bmpDock) |
216 |
self.__dockButton.SetBitmapFocus(self.__bmpDock) |
self.__dockButton.SetBitmapSelected(self.__bmpDock) |
217 |
self.__dockButton.SetToolTip(wxToolTip(_("Dock"))) |
self.__dockButton.SetBitmapDisabled(self.__bmpDock) |
218 |
else: |
self.__dockButton.SetToolTip(wxToolTip(_("Dock"))) |
|
self.__dockButton.SetLabel(_("Dock")) |
|
219 |
|
|
220 |
if wasVisible: self.Show() |
if wasVisible: self.Show() |
221 |
|
|
222 |
# |
# |
223 |
# restore window information |
# restore window information |
224 |
# |
# |
225 |
if self.__floatPosition is not None: self.SetPosition(self.__floatPosition) |
if self.__floatPosition is not None: |
226 |
if self.__floatSize is not None: self.SetSize(self.__floatSize) |
self.SetPosition(self.__floatPosition) |
227 |
|
if self.__floatSize is not None: |
228 |
|
self.SetSize(self.__floatSize) |
229 |
|
|
230 |
self.__dockPanel.SetSize(self.__topWindow.GetClientSize()) |
self.__dockPanel.SetSize(self.__topWindow.GetClientSize()) |
231 |
|
|
233 |
|
|
234 |
def IsDocked(self): |
def IsDocked(self): |
235 |
self.__CheckAllGood() |
self.__CheckAllGood() |
|
|
|
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() |
303 |
|
|
304 |
self.__topWindow.Show() |
self.__topWindow.Show() |
305 |
|
|
|
#if self.IsDocked(): |
|
|
#self.SetDockSize() |
|
|
|
|
306 |
if self.__topWindow is self.__dockWindow: |
if self.__topWindow is self.__dockWindow: |
307 |
self.__parent._UpdateDocks() |
self.__parent._UpdateDocks() |
308 |
|
|
309 |
def __DoHide(self): |
def __DoHide(self): |
310 |
if not self.IsShown(): return |
if not self.IsShown(): return |
311 |
|
|
312 |
self.__topWindow.Show(False) |
self.__topWindow.Show(False) |
313 |
|
|
314 |
if self.__topWindow is self.__dockWindow: |
if self.__topWindow is self.__dockWindow: |
315 |
self.__parent._UpdateDocks() |
self.__parent._UpdateDocks() |
316 |
|
|
|
|
|
317 |
def __CreateBorder(self): |
def __CreateBorder(self): |
318 |
|
|
|
#self.__panel.Reparent(self) # Make sure we hang on to the panel |
|
|
|
|
319 |
self.__dockPanel = wxPanel(self.__topWindow, -1, style=wxSUNKEN_BORDER) |
self.__dockPanel = wxPanel(self.__topWindow, -1, style=wxSUNKEN_BORDER) |
320 |
|
|
321 |
self.__panel.Reparent(self.__dockPanel) |
self.__panel.Reparent(self.__dockPanel) |
332 |
headerBox = wxStaticBoxSizer( |
headerBox = wxStaticBoxSizer( |
333 |
wxStaticBox(self.__dockPanel, -1, ""), headerBoxOrient) |
wxStaticBox(self.__dockPanel, -1, ""), headerBoxOrient) |
334 |
|
|
|
#buttonBox = wxBoxSizer(wxHORIZONTAL) |
|
|
|
|
335 |
# |
# |
336 |
# ideally, we should be able to rotate this text depending on |
# ideally, we should be able to rotate this text depending on |
337 |
# our orientation |
# our orientation |
338 |
# |
# |
339 |
text = wxStaticText(self.__dockPanel, -1, self.GetTitle(), |
text = wxStaticText(self.__dockPanel, -1, self.GetTitle(), |
340 |
style = wxALIGN_CENTRE) |
style = wxALIGN_CENTRE) |
|
|
|
341 |
font = text.GetFont() |
font = text.GetFont() |
342 |
font.SetPointSize(10) |
font.SetPointSize(10) |
343 |
text.SetFont(font) |
text.SetFont(font) |
344 |
|
|
345 |
# |
# |
346 |
# Perhaps using wxToggleButton would be better, but it's only |
# load the dock/undock/close bitmaps |
347 |
# supported under wxMSW and wxGTK as of v2.4.0.3 |
# and create the buttons |
348 |
# |
# |
349 |
self.__bmpDock = \ |
self.__bmpDock = \ |
350 |
resource.GetBitmapResource(DOCK_BMP, wxBITMAP_TYPE_XPM) |
resource.GetBitmapResource(DOCK_BMP, wxBITMAP_TYPE_XPM) |
351 |
self.__bmpUnDock = \ |
self.__bmpUnDock = \ |
352 |
resource.GetBitmapResource(UNDOCK_BMP, wxBITMAP_TYPE_XPM) |
resource.GetBitmapResource(UNDOCK_BMP, wxBITMAP_TYPE_XPM) |
353 |
|
|
354 |
if self.__bmpDock is not None \ |
if self.__docked: |
355 |
and self.__bmpUnDock is not None: |
bmp = self.__bmpDock |
|
self.__dockButton = wxBitmapButton( |
|
|
self.__dockPanel, ID_BUTTON_DOCK, |
|
|
self.__bmpUnDock, |
|
|
size = wxSize(self.__bmpDock.GetWidth() + 4, |
|
|
self.__bmpDock.GetHeight() + 4), |
|
|
style = wxBU_EXACTFIT | wxADJUST_MINSIZE) |
|
356 |
else: |
else: |
357 |
self.__bmpDock = \ |
bmp = self.__bmpUnDock |
|
self.__bmpUnDock = None |
|
358 |
|
|
359 |
self.__dockButton = wxButton( |
self.__dockButton = wxBitmapButton( |
360 |
self.__dockPanel, ID_BUTTON_DOCK, |
self.__dockPanel, ID_BUTTON_DOCK, |
361 |
"WW", style = wxBU_EXACTFIT | wxADJUST_MINSIZE) |
bmp, |
362 |
|
size = wxSize(bmp.GetWidth() + 4, bmp.GetHeight() + 4), |
363 |
|
style = wxBU_EXACTFIT | wxADJUST_MINSIZE) |
364 |
|
|
365 |
bmp = resource.GetBitmapResource(CLOSE_BMP, wxBITMAP_TYPE_XPM) |
bmp = resource.GetBitmapResource(CLOSE_BMP, wxBITMAP_TYPE_XPM) |
366 |
|
|
370 |
style = wxBU_EXACTFIT | wxADJUST_MINSIZE) |
style = wxBU_EXACTFIT | wxADJUST_MINSIZE) |
371 |
closeX.SetToolTip(wxToolTip(_("Close"))) |
closeX.SetToolTip(wxToolTip(_("Close"))) |
372 |
|
|
373 |
|
# |
374 |
#closeX = wxButton(self.__dockPanel, ID_BUTTON_CLOSE, "X", |
# fill in the sizer in an order appropriate to the orientation |
375 |
#style = wxBU_EXACTFIT | wxADJUST_MINSIZE) |
# |
|
|
|
|
#buttonBox.Add(self.__dockButton, 0, wxALIGN_RIGHT, 0) |
|
|
#buttonBox.Add(closeX, 0, wxALIGN_RIGHT, 0) |
|
|
|
|
376 |
if self.__orientation == wxLAYOUT_VERTICAL: |
if self.__orientation == wxLAYOUT_VERTICAL: |
377 |
headerBox.Add(text, 0, wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL, 0) |
headerBox.Add(text, 0, wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL, 0) |
378 |
headerBox.Add(1, 5, 1, wxGROW) |
headerBox.Add((1, 5), 1, wxGROW) |
379 |
headerBox.Add(self.__dockButton, 0, wxALIGN_RIGHT, 0) |
headerBox.Add(self.__dockButton, 0, wxALIGN_RIGHT, 0) |
380 |
headerBox.Add(closeX, 0, wxALIGN_RIGHT | wxLEFT, 4) |
headerBox.Add(closeX, 0, wxALIGN_RIGHT | wxLEFT, 4) |
381 |
else: |
else: |
386 |
sizer.Add(headerBox, 0, wxGROW, 0) |
sizer.Add(headerBox, 0, wxGROW, 0) |
387 |
sizer.Add(self.__panel, 1, wxGROW, 0) |
sizer.Add(self.__panel, 1, wxGROW, 0) |
388 |
|
|
389 |
|
|
390 |
self.__dockPanel.SetAutoLayout(True) |
self.__dockPanel.SetAutoLayout(True) |
391 |
self.__dockPanel.SetSizer(sizer) |
self.__dockPanel.SetSizer(sizer) |
392 |
sizer.SetSizeHints(self.__dockPanel) |
sizer.SetSizeHints(self.__dockPanel) |
393 |
|
sizer.SetSizeHints(self.__floatWindow) |
|
sizer.SetSizeHints(self.__topWindow) |
|
394 |
|
|
395 |
EVT_BUTTON(self.__dockPanel, ID_BUTTON_DOCK, self._OnToggleDock) |
EVT_BUTTON(self.__dockPanel, ID_BUTTON_DOCK, self._OnToggleDock) |
396 |
EVT_BUTTON(self.__dockPanel, ID_BUTTON_CLOSE, self._OnButtonClose) |
EVT_BUTTON(self.__dockPanel, ID_BUTTON_CLOSE, self._OnButtonClose) |
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) |
410 |
|
|
411 |
|
|
412 |
EVT_SIZE(self, self._OnSashSize) |
EVT_SIZE(self, self._OnSashSize) |
413 |
EVT_CLOSE(self, self._OnClose) |
EVT_CLOSE(self, self.OnClose) |
414 |
|
|
415 |
layout2oppSash = { |
layout2oppSash = { |
416 |
wxLAYOUT_NONE : wxSASH_NONE, |
wxLAYOUT_NONE : wxSASH_NONE, |
420 |
wxLAYOUT_BOTTOM : wxSASH_TOP } |
wxLAYOUT_BOTTOM : wxSASH_TOP } |
421 |
|
|
422 |
|
|
423 |
def _OnClose(self, event): |
def OnClose(self, event): |
424 |
|
|
425 |
self.__update_lock += 1 |
self.__update_lock += 1 |
426 |
|
|
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): |