20 |
|
|
21 |
from Thuban import _ |
from Thuban import _ |
22 |
|
|
23 |
from wxPython.wx import * |
import wx |
24 |
|
|
25 |
from Thuban.Lib.connector import Publisher |
from Thuban.Lib.connector import Publisher |
26 |
|
|
37 |
UNDOCK_BMP = "undock_12" |
UNDOCK_BMP = "undock_12" |
38 |
CLOSE_BMP = "close_12" |
CLOSE_BMP = "close_12" |
39 |
|
|
40 |
class DockPanel(wxPanel): |
class DockPanel(wx.Panel): |
41 |
"""A DockPanel is a panel that should be derived from to create panels |
"""A DockPanel is a panel that should be derived from to create panels |
42 |
that can be docked in a DockFrame. |
that can be docked in a DockFrame. |
43 |
""" |
""" |
50 |
if not isinstance(parent, DockableWindow): |
if not isinstance(parent, DockableWindow): |
51 |
raise TypeError("") |
raise TypeError("") |
52 |
|
|
53 |
wxPanel.__init__(self, parent.GetCurrentParent(), id) |
wx.Panel.__init__(self, parent.GetCurrentParent(), id) |
54 |
|
|
55 |
self.parent = parent |
self.parent = parent |
56 |
|
|
59 |
|
|
60 |
def Create(self): |
def Create(self): |
61 |
self.parent.SetPanel(self) |
self.parent.SetPanel(self) |
62 |
|
|
63 |
def SetDockParent(self, parent): |
def SetDockParent(self, parent): |
64 |
self.__dockParent = parent |
self.__dockParent = parent |
65 |
|
|
94 |
def __getattr__(self, attr): |
def __getattr__(self, attr): |
95 |
return getattr(self.__topWindow, attr) |
return getattr(self.__topWindow, attr) |
96 |
|
|
97 |
def __init__(self, parent, id, name, title, dockWindow, orient): |
def __init__(self, parent, id, name, title, dockWindow, orient): |
98 |
"""Create the dockable window. |
"""Create the dockable window. |
99 |
|
|
100 |
Initially, the window is hidden, but in an undocked state. |
Initially, the window is hidden, but in an undocked state. |
109 |
self.__orientation = orient |
self.__orientation = orient |
110 |
|
|
111 |
self.__dockWindow = dockWindow |
self.__dockWindow = dockWindow |
112 |
self.__floatWindow = wxFrame(parent, id, title) |
self.__floatWindow = wx.Frame(parent, id, title) |
113 |
|
|
114 |
self.__docked = False |
self.__docked = False |
115 |
if self.__docked: |
if self.__docked: |
126 |
self.__dockWindow.Hide() |
self.__dockWindow.Hide() |
127 |
self.__floatWindow.Hide() |
self.__floatWindow.Hide() |
128 |
|
|
129 |
EVT_CLOSE(self, self._OnClose) |
self.Bind(wx.EVT_CLOSE, self._OnClose) |
130 |
|
|
131 |
## |
## |
132 |
# Public methods |
# Public methods |
148 |
|
|
149 |
def GetPanel(self): |
def GetPanel(self): |
150 |
return self.__panel |
return self.__panel |
151 |
|
|
152 |
def GetCurrentParent(self): |
def GetCurrentParent(self): |
153 |
return self.__topWindow |
return self.__topWindow |
154 |
|
|
155 |
def SetDock(self, dock): |
def SetDock(self, dock): |
156 |
|
|
157 |
self.__CheckAllGood() |
self.__CheckAllGood() |
158 |
|
|
159 |
if dock: |
if dock: |
160 |
self.Dock() |
self.Dock() |
161 |
else: |
else: |
187 |
self.__dockButton.SetBitmapFocus(self.__bmpUnDock) |
self.__dockButton.SetBitmapFocus(self.__bmpUnDock) |
188 |
self.__dockButton.SetBitmapSelected(self.__bmpUnDock) |
self.__dockButton.SetBitmapSelected(self.__bmpUnDock) |
189 |
self.__dockButton.SetBitmapDisabled(self.__bmpUnDock) |
self.__dockButton.SetBitmapDisabled(self.__bmpUnDock) |
190 |
self.__dockButton.SetToolTip(wxToolTip(_("Undock"))) |
self.__dockButton.SetToolTip(wx.ToolTip(_("Undock"))) |
191 |
|
|
192 |
self.SetDockSize(self.__dockWindow.GetSize()) |
self.SetDockSize(self.__dockWindow.GetSize()) |
193 |
|
|
204 |
if wasVisible: self.Show(False) |
if wasVisible: self.Show(False) |
205 |
|
|
206 |
self.__docked = False |
self.__docked = False |
207 |
|
|
208 |
# |
# |
209 |
# reparent |
# reparent |
210 |
# |
# |
215 |
self.__dockButton.SetBitmapFocus(self.__bmpDock) |
self.__dockButton.SetBitmapFocus(self.__bmpDock) |
216 |
self.__dockButton.SetBitmapSelected(self.__bmpDock) |
self.__dockButton.SetBitmapSelected(self.__bmpDock) |
217 |
self.__dockButton.SetBitmapDisabled(self.__bmpDock) |
self.__dockButton.SetBitmapDisabled(self.__bmpDock) |
218 |
self.__dockButton.SetToolTip(wxToolTip(_("Dock"))) |
self.__dockButton.SetToolTip(wx.ToolTip(_("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: |
if self.__floatPosition is not None: |
226 |
self.SetPosition(self.__floatPosition) |
self.SetPosition(self.__floatPosition) |
227 |
if self.__floatSize is not None: |
if self.__floatSize is not None: |
228 |
self.SetSize(self.__floatSize) |
self.SetSize(self.__floatSize) |
229 |
|
|
230 |
self.__dockPanel.SetSize(self.__topWindow.GetClientSize()) |
self.__dockPanel.SetSize(self.__topWindow.GetClientSize()) |
260 |
else: |
else: |
261 |
rw = w |
rw = w |
262 |
rh = h |
rh = h |
263 |
|
|
264 |
# these are to account for the border?!!? |
# these are to account for the border?!!? |
265 |
rw += 8 # XXX: without this the sash isn't visible!?!?!?! |
rw += 8 # XXX: without this the sash isn't visible!?!?!?! |
266 |
rh += 8 # XXX: without this the sash isn't visible!?!?!?! |
rh += 8 # XXX: without this the sash isn't visible!?!?!?! |
267 |
|
|
268 |
self.__dockWindow.SetDefaultSize(wxSize(rw, rh)) |
self.__dockWindow.SetDefaultSize(wx.Size(rw, rh)) |
269 |
|
|
270 |
|
|
271 |
def Destroy(self): |
def Destroy(self): |
273 |
self.__floatWindow.Destroy() |
self.__floatWindow.Destroy() |
274 |
self.__dockWindow.Destroy() |
self.__dockWindow.Destroy() |
275 |
self.__parent.OnDockDestroy(self) |
self.__parent.OnDockDestroy(self) |
276 |
|
|
277 |
## |
## |
278 |
# Event handlers |
# Event handlers |
279 |
# |
# |
305 |
|
|
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 |
|
|
316 |
|
|
317 |
def __CreateBorder(self): |
def __CreateBorder(self): |
318 |
|
|
319 |
self.__dockPanel = wxPanel(self.__topWindow, -1, style=wxSUNKEN_BORDER) |
self.__dockPanel = wx.Panel(self.__topWindow, -1, style=wx.SUNKEN_BORDER) |
320 |
|
|
321 |
self.__panel.Reparent(self.__dockPanel) |
self.__panel.Reparent(self.__dockPanel) |
322 |
self.__panel.SetId(PANEL_ID) |
self.__panel.SetId(PANEL_ID) |
323 |
|
|
324 |
if self.__orientation == wxLAYOUT_VERTICAL: |
if self.__orientation == wx.LAYOUT_VERTICAL: |
325 |
sizer = wxBoxSizer(wxVERTICAL) |
sizer = wx.BoxSizer(wx.VERTICAL) |
326 |
headerBoxOrient = wxHORIZONTAL |
headerBoxOrient = wx.HORIZONTAL |
327 |
else: |
else: |
328 |
sizer = wxBoxSizer(wxHORIZONTAL) |
sizer = wx.BoxSizer(wx.HORIZONTAL) |
329 |
headerBoxOrient = wxVERTICAL |
headerBoxOrient = wx.VERTICAL |
|
|
|
330 |
|
|
331 |
headerBox = wxStaticBoxSizer( |
|
332 |
wxStaticBox(self.__dockPanel, -1, ""), headerBoxOrient) |
headerBox = wx.StaticBoxSizer( |
333 |
|
wx.StaticBox(self.__dockPanel, -1, ""), headerBoxOrient) |
334 |
|
|
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 = wx.StaticText(self.__dockPanel, -1, self.GetTitle(), |
340 |
style = wxALIGN_CENTRE) |
style = wx.ALIGN_CENTRE) |
341 |
font = text.GetFont() |
font = text.GetFont() |
342 |
font.SetPointSize(10) |
font.SetPointSize(10) |
343 |
text.SetFont(font) |
text.SetFont(font) |
347 |
# and create the buttons |
# and create the buttons |
348 |
# |
# |
349 |
self.__bmpDock = \ |
self.__bmpDock = \ |
350 |
resource.GetBitmapResource(DOCK_BMP, wxBITMAP_TYPE_XPM) |
resource.GetBitmapResource(DOCK_BMP, wx.BITMAP_TYPE_XPM) |
351 |
self.__bmpUnDock = \ |
self.__bmpUnDock = \ |
352 |
resource.GetBitmapResource(UNDOCK_BMP, wxBITMAP_TYPE_XPM) |
resource.GetBitmapResource(UNDOCK_BMP, wx.BITMAP_TYPE_XPM) |
353 |
|
|
354 |
if self.__docked: |
if self.__docked: |
355 |
bmp = self.__bmpDock |
bmp = self.__bmpDock |
356 |
else: |
else: |
357 |
bmp = self.__bmpUnDock |
bmp = self.__bmpUnDock |
358 |
|
|
359 |
self.__dockButton = wxBitmapButton( |
self.__dockButton = wx.BitmapButton( |
360 |
self.__dockPanel, ID_BUTTON_DOCK, |
self.__dockPanel, ID_BUTTON_DOCK, |
361 |
bmp, |
bmp, |
362 |
size = wxSize(bmp.GetWidth() + 4, bmp.GetHeight() + 4), |
size = wx.Size(bmp.GetWidth() + 4, bmp.GetHeight() + 4), |
363 |
style = wxBU_EXACTFIT | wxADJUST_MINSIZE) |
style = wx.BU_EXACTFIT | wx.ADJUST_MINSIZE) |
364 |
|
|
365 |
bmp = resource.GetBitmapResource(CLOSE_BMP, wxBITMAP_TYPE_XPM) |
bmp = resource.GetBitmapResource(CLOSE_BMP, wx.BITMAP_TYPE_XPM) |
366 |
|
|
367 |
closeX = wxBitmapButton(self.__dockPanel, ID_BUTTON_CLOSE, bmp, |
closeX = wx.BitmapButton(self.__dockPanel, ID_BUTTON_CLOSE, bmp, |
368 |
size = wxSize(bmp.GetWidth() + 4, |
size = wx.Size(bmp.GetWidth() + 4, |
369 |
bmp.GetHeight() + 4), |
bmp.GetHeight() + 4), |
370 |
style = wxBU_EXACTFIT | wxADJUST_MINSIZE) |
style = wx.BU_EXACTFIT | wx.ADJUST_MINSIZE) |
371 |
closeX.SetToolTip(wxToolTip(_("Close"))) |
closeX.SetToolTip(wx.ToolTip(_("Close"))) |
372 |
|
|
373 |
# |
# |
374 |
# fill in the sizer in an order appropriate to the orientation |
# fill in the sizer in an order appropriate to the orientation |
375 |
# |
# |
376 |
if self.__orientation == wxLAYOUT_VERTICAL: |
if self.__orientation == wx.LAYOUT_VERTICAL: |
377 |
headerBox.Add(text, 0, wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL, 0) |
headerBox.Add(text, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTRE_VERTICAL, 0) |
378 |
headerBox.Add((1, 5), 1, wxGROW) |
headerBox.Add((1, 5), 1, wx.GROW) |
379 |
headerBox.Add(self.__dockButton, 0, wxALIGN_RIGHT, 0) |
headerBox.Add(self.__dockButton, 0, wx.ALIGN_RIGHT, 0) |
380 |
headerBox.Add(closeX, 0, wxALIGN_RIGHT | wxLEFT, 4) |
headerBox.Add(closeX, 0, wx.ALIGN_RIGHT | wx.LEFT, 4) |
381 |
else: |
else: |
382 |
headerBox.Add(closeX, 0, wxALIGN_RIGHT | wxBOTTOM, 4) |
headerBox.Add(closeX, 0, wx.ALIGN_RIGHT | wx.BOTTOM, 4) |
383 |
headerBox.Add(self.__dockButton, 0, wxALIGN_RIGHT, 0) |
headerBox.Add(self.__dockButton, 0, wx.ALIGN_RIGHT, 0) |
384 |
headerBox.Add(text, 0, wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL, 0) |
headerBox.Add(text, 0, wx.ALIGN_LEFT | wx.ALIGN_CENTRE_VERTICAL, 0) |
385 |
|
|
386 |
sizer.Add(headerBox, 0, wxGROW, 0) |
sizer.Add(headerBox, 0, wx.GROW, 0) |
387 |
sizer.Add(self.__panel, 1, wxGROW, 0) |
sizer.Add(self.__panel, 1, wx.GROW, 0) |
388 |
|
|
389 |
|
|
390 |
self.__dockPanel.SetAutoLayout(True) |
self.__dockPanel.SetAutoLayout(True) |
392 |
sizer.SetSizeHints(self.__dockPanel) |
sizer.SetSizeHints(self.__dockPanel) |
393 |
sizer.SetSizeHints(self.__floatWindow) |
sizer.SetSizeHints(self.__floatWindow) |
394 |
|
|
395 |
EVT_BUTTON(self.__dockPanel, ID_BUTTON_DOCK, self._OnToggleDock) |
self.Bind(wx.EVT_BUTTON, self._OnToggleDock, self.__dockPanel, id=ID_BUTTON_DOCK) |
396 |
EVT_BUTTON(self.__dockPanel, ID_BUTTON_CLOSE, self._OnButtonClose) |
self.Bind(wx.EVT_BUTTON, self._OnButtonClose, self.__dockPanel, id=ID_BUTTON_CLOSE) |
397 |
|
|
398 |
|
|
399 |
class DockFrame(wxFrame): |
class DockFrame(wx.Frame): |
400 |
"""A DockFrame is a frame that will contain dockable panels.""" |
"""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) |
wx.Frame.__init__(self, parent, id, title, position, size) |
404 |
|
|
405 |
self.openWindows = {} |
self.openWindows = {} |
406 |
|
|
409 |
self.SetMainWindow(None) |
self.SetMainWindow(None) |
410 |
|
|
411 |
|
|
412 |
EVT_SIZE(self, self._OnSashSize) |
self.Bind(wx.EVT_SIZE, self._OnSashSize) |
413 |
EVT_CLOSE(self, self.OnClose) |
self.Bind(wx.EVT_CLOSE, self.OnClose) |
414 |
|
|
415 |
layout2oppSash = { |
layout2oppSash = { |
416 |
wxLAYOUT_NONE : wxSASH_NONE, |
wx.LAYOUT_NONE : wx.SASH_NONE, |
417 |
wxLAYOUT_TOP : wxSASH_BOTTOM, |
wx.LAYOUT_TOP : wx.SASH_BOTTOM, |
418 |
wxLAYOUT_LEFT : wxSASH_RIGHT, |
wx.LAYOUT_LEFT : wx.SASH_RIGHT, |
419 |
wxLAYOUT_RIGHT : wxSASH_LEFT, |
wx.LAYOUT_RIGHT : wx.SASH_LEFT, |
420 |
wxLAYOUT_BOTTOM : wxSASH_TOP } |
wx.LAYOUT_BOTTOM : wx.SASH_TOP } |
421 |
|
|
422 |
|
|
423 |
def OnClose(self, event): |
def OnClose(self, event): |
444 |
wxLAYOUT_RIGHT. |
wxLAYOUT_RIGHT. |
445 |
""" |
""" |
446 |
|
|
447 |
if align in (wxLAYOUT_NONE, wxLAYOUT_LEFT, wxLAYOUT_RIGHT): |
if align in (wx.LAYOUT_NONE, wx.LAYOUT_LEFT, wx.LAYOUT_RIGHT): |
448 |
orient = wxLAYOUT_VERTICAL |
orient = wx.LAYOUT_VERTICAL |
449 |
else: |
else: |
450 |
orient = wxLAYOUT_HORIZONTAL |
orient = wx.LAYOUT_HORIZONTAL |
451 |
|
|
452 |
sash = wxSashLayoutWindow(self, id, style=wxNO_BORDER|wxSW_3D) |
sash = wx.SashLayoutWindow(self, id, style=wx.NO_BORDER|wx.SW_3D) |
453 |
sash.SetOrientation(orient) |
sash.SetOrientation(orient) |
454 |
sash.SetAlignment(align) |
sash.SetAlignment(align) |
455 |
sash.SetSashVisible(DockFrame.layout2oppSash[align], True) |
sash.SetSashVisible(DockFrame.layout2oppSash[align], True) |
458 |
win = DockableWindow(self, id, name, title, sash, orient) |
win = DockableWindow(self, id, name, title, sash, orient) |
459 |
|
|
460 |
self.__RegisterDock(name, win) |
self.__RegisterDock(name, win) |
461 |
EVT_SASH_DRAGGED(self, id, self._OnSashDragged) |
self.Bind(wx.EVT_SASH_DRAGGED, self._OnSashDragged, id=id) |
462 |
|
|
463 |
return win |
return win |
464 |
|
|
473 |
def SetMainWindow(self, main): |
def SetMainWindow(self, main): |
474 |
self.__mainWindow = main |
self.__mainWindow = main |
475 |
self._UpdateDocks() |
self._UpdateDocks() |
476 |
|
|
477 |
def _UpdateDocks(self): |
def _UpdateDocks(self): |
478 |
if self.__update_lock == 0: |
if self.__update_lock == 0: |
479 |
wxLayoutAlgorithm().LayoutWindow(self, self.__mainWindow) |
wx.LayoutAlgorithm().LayoutWindow(self, self.__mainWindow) |
480 |
|
|
481 |
def _OnSashDragged(self, event): |
def _OnSashDragged(self, event): |
482 |
if event.GetDragStatus() == wxSASH_STATUS_OUT_OF_RANGE: |
if event.GetDragStatus() == wx.SASH_STATUS_OUT_OF_RANGE: |
483 |
return |
return |
484 |
|
|
485 |
id = event.GetId() |
id = event.GetId() |