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): |
166 |
self.__topWindow = self.__dockWindow |
self.__topWindow = self.__dockWindow |
167 |
self.__dockPanel.Reparent(self.__topWindow) |
self.__dockPanel.Reparent(self.__topWindow) |
168 |
|
|
169 |
self.__dockButton.SetLabel(_("Undock")) |
if self.__bmpUnDock is not None: |
170 |
|
self.__dockButton.SetBitmapLabel(self.__bmpUnDock) |
171 |
|
self.__dockButton.SetBitmapFocus(self.__bmpUnDock) |
172 |
|
self.__dockButton.SetToolTip(wxToolTip(_("Undock"))) |
173 |
|
else: |
174 |
|
self.__dockButton.SetLabel(_("Undock")) |
175 |
|
|
176 |
self.SetDockSize(self.__dockWindow.GetSize()) |
self.SetDockSize(self.__dockWindow.GetSize()) |
177 |
|
|
196 |
self.__topWindow = self.__floatWindow |
self.__topWindow = self.__floatWindow |
197 |
self.__dockPanel.Reparent(self.__topWindow) |
self.__dockPanel.Reparent(self.__topWindow) |
198 |
|
|
199 |
self.__dockButton.SetLabel(_("Dock")) |
if self.__bmpDock is not None: |
200 |
|
self.__dockButton.SetBitmapLabel(self.__bmpDock) |
201 |
|
self.__dockButton.SetBitmapFocus(self.__bmpDock) |
202 |
|
self.__dockButton.SetToolTip(wxToolTip(_("Dock"))) |
203 |
|
else: |
204 |
|
self.__dockButton.SetLabel(_("Dock")) |
205 |
|
|
206 |
if wasVisible: self.Show() |
if wasVisible: self.Show() |
207 |
|
|
211 |
if self.__floatPosition is not None: self.SetPosition(self.__floatPosition) |
if self.__floatPosition is not None: self.SetPosition(self.__floatPosition) |
212 |
if self.__floatSize is not None: self.SetSize(self.__floatSize) |
if self.__floatSize is not None: self.SetSize(self.__floatSize) |
213 |
|
|
214 |
|
self.__dockPanel.SetSize(self.__topWindow.GetClientSize()) |
215 |
|
|
216 |
self.issue(DOCKABLE_UNDOCKED, self.__id, self) |
self.issue(DOCKABLE_UNDOCKED, self.__id, self) |
217 |
|
|
218 |
def IsDocked(self): |
def IsDocked(self): |
229 |
|
|
230 |
def SetDockSize(self, rect = None): |
def SetDockSize(self, rect = None): |
231 |
|
|
232 |
|
print "---------------" |
233 |
# |
# |
234 |
# adjust the size to get the |
# adjust the size to get the |
235 |
w0, h0 = self.__dockPanel.GetBestSize() |
w0, h0 = self.__dockPanel.GetBestSize() |
236 |
|
print w0, h0 |
237 |
w, h = self.__panel.GetBestSize() |
w, h = self.__panel.GetBestSize() |
238 |
|
print w, h |
239 |
|
#w0, h0 = self.__dockPanel.GetBestSize() |
240 |
|
#w0 = h0 = 0 |
241 |
|
#w, h = self.__dockPanel.GetBestSize() |
242 |
|
|
243 |
#print (w0, h0), (w, h) |
#print (w0, h0), (w, h) |
244 |
|
|
260 |
rw += 8 # XXX: without this the sash isn't visible!?!?!?! |
rw += 8 # XXX: without this the sash isn't visible!?!?!?! |
261 |
rh += 8 # XXX: without this the sash isn't visible!?!?!?! |
rh += 8 # XXX: without this the sash isn't visible!?!?!?! |
262 |
|
|
263 |
|
print rw, rh |
264 |
|
|
265 |
self.__dockWindow.SetDefaultSize(wxSize(rw, rh)) |
self.__dockWindow.SetDefaultSize(wxSize(rw, rh)) |
266 |
|
|
267 |
|
|
269 |
self.__panel.Destroy() |
self.__panel.Destroy() |
270 |
self.__floatWindow.Destroy() |
self.__floatWindow.Destroy() |
271 |
self.__dockWindow.Destroy() |
self.__dockWindow.Destroy() |
272 |
self.__parent.OnDockClose(self) |
self.__parent.OnDockDestroy(self) |
273 |
|
|
274 |
## |
## |
275 |
# Event handlers |
# Event handlers |
277 |
|
|
278 |
def _OnButtonClose(self, event): |
def _OnButtonClose(self, event): |
279 |
#self.Close() |
#self.Close() |
280 |
self.Destroy() |
self.Show(False) |
281 |
|
|
282 |
def _OnClose(self, force = False): |
def _OnClose(self, force = False): |
283 |
self.Destroy() |
self.Show(False) |
284 |
|
|
285 |
def _OnToggleDock(self, event): |
def _OnToggleDock(self, event): |
286 |
self.__CheckAllGood() |
self.__CheckAllGood() |
323 |
self.__dockPanel = wxPanel(self.__topWindow, -1, style=wxSUNKEN_BORDER) |
self.__dockPanel = wxPanel(self.__topWindow, -1, style=wxSUNKEN_BORDER) |
324 |
#self.__dockPanel.SetBackgroundColour(wxColour(255, 0, 0)) |
#self.__dockPanel.SetBackgroundColour(wxColour(255, 0, 0)) |
325 |
|
|
326 |
|
self.__panel.Reparent(self.__dockPanel) |
327 |
|
self.__panel.SetId(PANEL_ID) |
328 |
|
|
329 |
if self.__orientation == wxLAYOUT_VERTICAL: |
if self.__orientation == wxLAYOUT_VERTICAL: |
330 |
sizer = wxBoxSizer(wxVERTICAL) |
sizer = wxBoxSizer(wxVERTICAL) |
331 |
headerBoxOrient = wxHORIZONTAL |
headerBoxOrient = wxHORIZONTAL |
337 |
headerBox = wxStaticBoxSizer( |
headerBox = wxStaticBoxSizer( |
338 |
wxStaticBox(self.__dockPanel, -1, ""), headerBoxOrient) |
wxStaticBox(self.__dockPanel, -1, ""), headerBoxOrient) |
339 |
|
|
340 |
buttonBox = wxBoxSizer(wxHORIZONTAL) |
#buttonBox = wxBoxSizer(wxHORIZONTAL) |
341 |
|
|
342 |
# |
# |
343 |
# ideally, we should be able to rotate this text depending on |
# ideally, we should be able to rotate this text depending on |
344 |
# our orientation |
# our orientation |
345 |
# |
# |
346 |
text = wxStaticText(self.__dockPanel, -1, self.GetTitle(), |
text = wxStaticText(self.__dockPanel, -1, self.GetTitle(), |
347 |
style = wxSIMPLE_BORDER | wxALIGN_CENTRE) |
style = wxALIGN_CENTRE) |
348 |
|
|
349 |
|
font = text.GetFont() |
350 |
|
font.SetPointSize(10) |
351 |
|
text.SetFont(font) |
352 |
|
|
353 |
# |
# |
354 |
# Perhaps using wxToggleButton would be better, but it's only |
# Perhaps using wxToggleButton would be better, but it's only |
355 |
# supported under wxMSW and wxGTK as of v2.4.0.3 |
# supported under wxMSW and wxGTK as of v2.4.0.3 |
356 |
# |
# |
357 |
self.__dockButton = wxButton(self.__dockPanel, ID_BUTTON_DOCK, "WWWWWW", |
self.__bmpDock = \ |
358 |
style = wxBU_EXACTFIT | wxADJUST_MINSIZE) |
resource.GetBitmapResource(DOCK_BMP, wxBITMAP_TYPE_XPM) |
359 |
|
self.__bmpUnDock = \ |
360 |
|
resource.GetBitmapResource(UNDOCK_BMP, wxBITMAP_TYPE_XPM) |
361 |
|
|
362 |
|
if self.__bmpDock is not None \ |
363 |
|
and self.__bmpUnDock is not None: |
364 |
|
self.__dockButton = wxBitmapButton( |
365 |
|
self.__dockPanel, ID_BUTTON_DOCK, |
366 |
|
self.__bmpUnDock, |
367 |
|
size = wxSize(self.__bmpDock.GetWidth() + 4, |
368 |
|
self.__bmpDock.GetHeight() + 4), |
369 |
|
style = wxBU_EXACTFIT | wxADJUST_MINSIZE) |
370 |
|
else: |
371 |
|
self.__bmpDock = \ |
372 |
|
self.__bmpUnDock = None |
373 |
|
|
374 |
|
self.__dockButton = wxButton( |
375 |
|
self.__dockPanel, ID_BUTTON_DOCK, |
376 |
|
"WW", style = wxBU_EXACTFIT | wxADJUST_MINSIZE) |
377 |
|
|
378 |
|
bmp = resource.GetBitmapResource(CLOSE_BMP, wxBITMAP_TYPE_XPM) |
379 |
|
|
380 |
closeX = wxButton(self.__dockPanel, ID_BUTTON_CLOSE, "X", |
closeX = wxBitmapButton(self.__dockPanel, ID_BUTTON_CLOSE, bmp, |
381 |
style = wxBU_EXACTFIT | wxADJUST_MINSIZE) |
size = wxSize(bmp.GetWidth() + 4, |
382 |
|
bmp.GetHeight() + 4), |
383 |
|
style = wxBU_EXACTFIT | wxADJUST_MINSIZE) |
384 |
|
closeX.SetToolTip(wxToolTip(_("Close"))) |
385 |
|
|
386 |
buttonBox.Add(self.__dockButton, 0, wxALIGN_RIGHT, 0) |
|
387 |
buttonBox.Add(closeX, 0, wxALIGN_RIGHT, 0) |
#closeX = wxButton(self.__dockPanel, ID_BUTTON_CLOSE, "X", |
388 |
|
#style = wxBU_EXACTFIT | wxADJUST_MINSIZE) |
389 |
|
|
390 |
|
#buttonBox.Add(self.__dockButton, 0, wxALIGN_RIGHT, 0) |
391 |
|
#buttonBox.Add(closeX, 0, wxALIGN_RIGHT, 0) |
392 |
|
|
393 |
if self.__orientation == wxLAYOUT_VERTICAL: |
if self.__orientation == wxLAYOUT_VERTICAL: |
394 |
headerBox.Add(text, 0, wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL, 0) |
headerBox.Add(text, 0, wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL, 0) |
395 |
headerBox.Add(1, 20, 1, wxGROW) |
headerBox.Add(1, 5, 1, wxGROW) |
396 |
headerBox.Add(buttonBox, 0, wxGROW | wxALIGN_RIGHT, 0) |
headerBox.Add(self.__dockButton, 0, wxALIGN_RIGHT, 0) |
397 |
|
headerBox.Add(closeX, 0, wxALIGN_RIGHT | wxLEFT, 4) |
398 |
else: |
else: |
399 |
headerBox.Add(buttonBox, 0, wxGROW, 0) |
headerBox.Add(closeX, 0, wxALIGN_RIGHT | wxBOTTOM, 4) |
400 |
|
headerBox.Add(self.__dockButton, 0, wxALIGN_RIGHT, 0) |
401 |
headerBox.Add(text, 0, wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL, 0) |
headerBox.Add(text, 0, wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL, 0) |
402 |
|
|
403 |
sizer.Add(headerBox, 0, wxGROW, 0) |
sizer.Add(headerBox, 0, wxGROW, 0) |
404 |
|
|
|
self.__panel.Reparent(self.__dockPanel) |
|
|
self.__panel.SetId(PANEL_ID) |
|
405 |
|
|
406 |
sizer.Add(self.__panel, 1, wxGROW, 0) |
sizer.Add(self.__panel, 1, wxGROW, 0) |
407 |
|
|
408 |
sizer.Fit(self.__dockPanel) |
#sizer.Fit(self.__dockPanel) |
409 |
|
|
410 |
self.__dockPanel.SetSizer(sizer) |
self.__panel.SetAutoLayout(True) |
411 |
self.__dockPanel.SetAutoLayout(True) |
sizer.SetSizeHints(self.__panel) |
412 |
|
|
413 |
sizer.SetSizeHints(self.__dockPanel) |
self.__dockPanel.SetSizerAndFit(sizer) |
414 |
|
#self.__dockPanel.SetAutoLayout(True) |
415 |
|
#sizer.SetSizeHints(self.__dockPanel) |
416 |
|
|
417 |
EVT_BUTTON(self.__dockPanel, ID_BUTTON_DOCK, self._OnToggleDock) |
EVT_BUTTON(self.__dockPanel, ID_BUTTON_DOCK, self._OnToggleDock) |
418 |
EVT_BUTTON(self.__dockPanel, ID_BUTTON_CLOSE, self._OnButtonClose) |
EVT_BUTTON(self.__dockPanel, ID_BUTTON_CLOSE, self._OnButtonClose) |
483 |
def FindRegisteredDock(self, name): |
def FindRegisteredDock(self, name): |
484 |
return self.openWindows.get(name) |
return self.openWindows.get(name) |
485 |
|
|
486 |
def OnDockClose(self, win): |
def OnDockDestroy(self, win): |
487 |
del self.openWindows[win.GetName()] |
del self.openWindows[win.GetName()] |
488 |
self._UpdateDocks() |
self._UpdateDocks() |
489 |
|
|