/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/UI/dock.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/Thuban/UI/dock.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 605 by jonathan, Fri Apr 4 12:16:13 2003 UTC revision 973 by jonathan, Wed May 21 17:39:31 2003 UTC
# Line 9  Line 9 
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 *
# Line 19  from dialogs import NonModalDialog Line 21  from dialogs import NonModalDialog
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):
# Line 35  class DockPanel(wxPanel): Line 39  class DockPanel(wxPanel):
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    
# Line 64  class DockPanel(wxPanel): Line 73  class DockPanel(wxPanel):
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    
# Line 86  class DockableWindow(Publisher): Line 90  class DockableWindow(Publisher):
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:
# Line 101  class DockableWindow(Publisher): Line 101  class DockableWindow(Publisher):
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()
# Line 162  class DockableWindow(Publisher): Line 163  class DockableWindow(Publisher):
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.SetBitmapSelected(self.__bmpUnDock)
169            self.__dockButton.SetBitmapDisabled(self.__bmpUnDock)
170            self.__dockButton.SetToolTip(wxToolTip(_("Undock")))
171    
172          self.SetDockSize(self.__dockWindow.GetSize())          self.SetDockSize(self.__dockWindow.GetSize())
173    
174          if wasVisible: self.Show(True)          if wasVisible: self.Show(True)
175    
         #self.__parent._UpdateDocks()  
   
176          self.issue(DOCKABLE_DOCKED, self.__id, self)          self.issue(DOCKABLE_DOCKED, self.__id, self)
177    
178      def UnDock(self):      def UnDock(self):
# Line 187  class DockableWindow(Publisher): Line 190  class DockableWindow(Publisher):
190          self.__topWindow = self.__floatWindow          self.__topWindow = self.__floatWindow
191          self.__dockPanel.Reparent(self.__topWindow)          self.__dockPanel.Reparent(self.__topWindow)
192    
193          self.__dockButton.SetLabel(_("Dock"))          self.__dockButton.SetBitmapLabel(self.__bmpDock)
194            self.__dockButton.SetBitmapFocus(self.__bmpDock)
195            self.__dockButton.SetBitmapSelected(self.__bmpDock)
196            self.__dockButton.SetBitmapDisabled(self.__bmpDock)
197            self.__dockButton.SetToolTip(wxToolTip(_("Dock")))
198    
199          if wasVisible: self.Show()          if wasVisible: self.Show()
200    
201          #          #
202          # restore window information          # restore window information
203          #          #
204          if self.__floatPosition is not None: self.SetPosition(self.__floatPosition)          if self.__floatPosition is not None:
205          if self.__floatSize     is not None: self.SetSize(self.__floatSize)              self.SetPosition(self.__floatPosition)
206            if self.__floatSize is not None:
207                self.SetSize(self.__floatSize)
208    
209            self.__dockPanel.SetSize(self.__topWindow.GetClientSize())
210    
211          self.issue(DOCKABLE_UNDOCKED, self.__id, self)          self.issue(DOCKABLE_UNDOCKED, self.__id, self)
212    
213      def IsDocked(self):      def IsDocked(self):
214          self.__CheckAllGood()          self.__CheckAllGood()
   
215          return self.__docked          return self.__docked
216    
   
217      def Show(self, show = True):      def Show(self, show = True):
218          if show:          if show:
219              self.__DoShow()              self.__DoShow()
# Line 213  class DockableWindow(Publisher): Line 222  class DockableWindow(Publisher):
222    
223      def SetDockSize(self, rect = None):      def SetDockSize(self, rect = None):
224    
         #  
         # adjust the size to get the  
225          w0, h0 = self.__dockPanel.GetBestSize()          w0, h0 = self.__dockPanel.GetBestSize()
226          w, h = self.__panel.GetBestSize()          w, h = self.__panel.GetBestSize()
227    
         #print (w0, h0), (w, h)  
   
228          if (w, h) < (w0, h0):          if (w, h) < (w0, h0):
229              w = w0              w = w0
230              h = h0              h = h0
231                                                                                          
232          if rect is not None:          if rect is not None:
233              rw = rect.width              rw = rect.width
234              rh = rect.height              rh = rect.height
             #print "   ", (rw, rh)  
235              if rw < w: rw = w              if rw < w: rw = w
236              if rh < h: rh = h              if rh < h: rh = h
237          else:          else:
# Line 245  class DockableWindow(Publisher): Line 249  class DockableWindow(Publisher):
249          self.__panel.Destroy()          self.__panel.Destroy()
250          self.__floatWindow.Destroy()          self.__floatWindow.Destroy()
251          self.__dockWindow.Destroy()          self.__dockWindow.Destroy()
252          self.__parent.OnDockClose(self)          self.__parent.OnDockDestroy(self)
253                    
254      ##      ##
255      # Event handlers      # Event handlers
# Line 253  class DockableWindow(Publisher): Line 257  class DockableWindow(Publisher):
257    
258      def _OnButtonClose(self, event):      def _OnButtonClose(self, event):
259          #self.Close()          #self.Close()
260          self.Destroy()          self.Show(False)
261    
262      def _OnClose(self, force = False):      def _OnClose(self, force = False):
263          self.Destroy()          self.Show(False)
264    
265      def _OnToggleDock(self, event):      def _OnToggleDock(self, event):
266          self.__CheckAllGood()          self.__CheckAllGood()
# Line 273  class DockableWindow(Publisher): Line 277  class DockableWindow(Publisher):
277    
278      def __DoShow(self):      def __DoShow(self):
279          if self.IsShown(): return          if self.IsShown(): return
         #print "__DoShow()", self.IsShown()  
280    
281          self.__topWindow.Show()          self.__topWindow.Show()
282    
         #if self.IsDocked():  
             #self.SetDockSize()  
   
283          if self.__topWindow is self.__dockWindow:          if self.__topWindow is self.__dockWindow:
284              self.__parent._UpdateDocks()              self.__parent._UpdateDocks()
285                            
286      def __DoHide(self):      def __DoHide(self):
287          if not self.IsShown(): return          if not self.IsShown(): return
288          #print "__DoHide()", self.IsShown()  
289          self.__topWindow.Show(False)          self.__topWindow.Show(False)
290    
291          if self.__topWindow is self.__dockWindow:          if self.__topWindow is self.__dockWindow:
292              self.__parent._UpdateDocks()              self.__parent._UpdateDocks()
293    
   
294      def __CreateBorder(self):      def __CreateBorder(self):
295    
         #self.__panel.Reparent(self) # Make sure we hang on to the panel  
   
296          self.__dockPanel = wxPanel(self.__topWindow, -1, style=wxSUNKEN_BORDER)          self.__dockPanel = wxPanel(self.__topWindow, -1, style=wxSUNKEN_BORDER)
297          #self.__dockPanel.SetBackgroundColour(wxColour(255, 0, 0))  
298            self.__panel.Reparent(self.__dockPanel)
299            self.__panel.SetId(PANEL_ID)
300    
301          if self.__orientation == wxLAYOUT_VERTICAL:          if self.__orientation == wxLAYOUT_VERTICAL:
302              sizer = wxBoxSizer(wxVERTICAL)              sizer = wxBoxSizer(wxVERTICAL)
# Line 310  class DockableWindow(Publisher): Line 309  class DockableWindow(Publisher):
309          headerBox = wxStaticBoxSizer(          headerBox = wxStaticBoxSizer(
310                          wxStaticBox(self.__dockPanel, -1, ""), headerBoxOrient)                          wxStaticBox(self.__dockPanel, -1, ""), headerBoxOrient)
311    
         buttonBox = wxBoxSizer(wxHORIZONTAL)  
   
312          #          #
313          # ideally, we should be able to rotate this text depending on          # ideally, we should be able to rotate this text depending on
314          # our orientation          # our orientation
315          #          #
316          text = wxStaticText(self.__dockPanel, -1, self.GetTitle(),          text = wxStaticText(self.__dockPanel, -1, self.GetTitle(),
317                               style = wxSIMPLE_BORDER | wxALIGN_CENTRE)                               style = wxALIGN_CENTRE)
318            font = text.GetFont()
319            font.SetPointSize(10)
320            text.SetFont(font)
321    
322          #          #
323          # Perhaps using wxToggleButton would be better, but it's only          # load the dock/undock/close bitmaps
324          # supported under wxMSW and wxGTK as of v2.4.0.3          # and create the buttons
325          #          #
326          self.__dockButton = wxButton(self.__dockPanel, ID_BUTTON_DOCK, "WWWWWW",          self.__bmpDock   = \
327                                       style = wxBU_EXACTFIT | wxADJUST_MINSIZE)              resource.GetBitmapResource(DOCK_BMP, wxBITMAP_TYPE_XPM)
328            self.__bmpUnDock = \
329                resource.GetBitmapResource(UNDOCK_BMP, wxBITMAP_TYPE_XPM)
330    
331            if self.__docked:
332                bmp = self.__bmpDock
333            else:
334                bmp = self.__bmpUnDock
335    
336            self.__dockButton = wxBitmapButton(
337                self.__dockPanel, ID_BUTTON_DOCK,
338                bmp,
339                size = wxSize(bmp.GetWidth() + 4, bmp.GetHeight() + 4),
340                style = wxBU_EXACTFIT | wxADJUST_MINSIZE)
341    
342          closeX = wxButton(self.__dockPanel, ID_BUTTON_CLOSE, "X",          bmp = resource.GetBitmapResource(CLOSE_BMP, wxBITMAP_TYPE_XPM)
                          style = wxBU_EXACTFIT | wxADJUST_MINSIZE)  
343    
344          buttonBox.Add(self.__dockButton, 0, wxALIGN_RIGHT, 0)          closeX = wxBitmapButton(self.__dockPanel, ID_BUTTON_CLOSE, bmp,
345          buttonBox.Add(closeX, 0, wxALIGN_RIGHT, 0)                            size = wxSize(bmp.GetWidth() + 4,
346                                            bmp.GetHeight() + 4),
347                              style = wxBU_EXACTFIT | wxADJUST_MINSIZE)
348            closeX.SetToolTip(wxToolTip(_("Close")))
349    
350            #
351            # fill in the sizer in an order appropriate to the orientation
352            #
353          if self.__orientation == wxLAYOUT_VERTICAL:          if self.__orientation == wxLAYOUT_VERTICAL:
354              headerBox.Add(text, 0, wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL, 0)              headerBox.Add(text, 0, wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL, 0)
355              headerBox.Add(1, 20, 1, wxGROW)              headerBox.Add(1, 5, 1, wxGROW)
356              headerBox.Add(buttonBox, 0, wxGROW | wxALIGN_RIGHT, 0)              headerBox.Add(self.__dockButton, 0, wxALIGN_RIGHT, 0)
357                headerBox.Add(closeX, 0, wxALIGN_RIGHT | wxLEFT, 4)
358          else:          else:
359              headerBox.Add(buttonBox, 0, wxGROW, 0)              headerBox.Add(closeX, 0, wxALIGN_RIGHT | wxBOTTOM, 4)
360                headerBox.Add(self.__dockButton, 0, wxALIGN_RIGHT, 0)
361              headerBox.Add(text, 0, wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL, 0)              headerBox.Add(text, 0, wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL, 0)
362    
363          sizer.Add(headerBox, 0, wxGROW, 0)          sizer.Add(headerBox, 0, wxGROW, 0)
   
         self.__panel.Reparent(self.__dockPanel)  
         self.__panel.SetId(PANEL_ID)  
   
364          sizer.Add(self.__panel, 1, wxGROW, 0)          sizer.Add(self.__panel, 1, wxGROW, 0)
365    
         sizer.Fit(self.__dockPanel)  
366    
         self.__dockPanel.SetSizer(sizer)  
367          self.__dockPanel.SetAutoLayout(True)          self.__dockPanel.SetAutoLayout(True)
368            self.__dockPanel.SetSizer(sizer)
369          sizer.SetSizeHints(self.__dockPanel)          sizer.SetSizeHints(self.__dockPanel)
370            sizer.SetSizeHints(self.__floatWindow)
371    
372          EVT_BUTTON(self.__dockPanel, ID_BUTTON_DOCK, self._OnToggleDock)          EVT_BUTTON(self.__dockPanel, ID_BUTTON_DOCK, self._OnToggleDock)
373          EVT_BUTTON(self.__dockPanel, ID_BUTTON_CLOSE, self._OnButtonClose)          EVT_BUTTON(self.__dockPanel, ID_BUTTON_CLOSE, self._OnButtonClose)
# Line 371  class DockFrame(wxFrame): Line 386  class DockFrame(wxFrame):
386    
387    
388          EVT_SIZE(self, self._OnSashSize)          EVT_SIZE(self, self._OnSashSize)
389          EVT_CLOSE(self, self._OnClose)          EVT_CLOSE(self, self.OnClose)
390    
391      layout2oppSash = {      layout2oppSash = {
392              wxLAYOUT_NONE   : wxSASH_NONE,              wxLAYOUT_NONE   : wxSASH_NONE,
# Line 381  class DockFrame(wxFrame): Line 396  class DockFrame(wxFrame):
396              wxLAYOUT_BOTTOM : wxSASH_TOP }              wxLAYOUT_BOTTOM : wxSASH_TOP }
397    
398    
399      def _OnClose(self, event):      def OnClose(self, event):
400    
401          self.__update_lock += 1          self.__update_lock += 1
402    
# Line 409  class DockFrame(wxFrame): Line 424  class DockFrame(wxFrame):
424          sash = wxSashLayoutWindow(self, id, style=wxNO_BORDER|wxSW_3D)          sash = wxSashLayoutWindow(self, id, style=wxNO_BORDER|wxSW_3D)
425          sash.SetOrientation(orient)          sash.SetOrientation(orient)
426          sash.SetAlignment(align)          sash.SetAlignment(align)
         #print align, DockFrame.layout2oppSash[align]  
427          sash.SetSashVisible(DockFrame.layout2oppSash[align], True)          sash.SetSashVisible(DockFrame.layout2oppSash[align], True)
428          sash.SetSashBorder(DockFrame.layout2oppSash[align], True)          sash.SetSashBorder(DockFrame.layout2oppSash[align], True)
429    
# Line 423  class DockFrame(wxFrame): Line 437  class DockFrame(wxFrame):
437      def FindRegisteredDock(self, name):      def FindRegisteredDock(self, name):
438          return self.openWindows.get(name)          return self.openWindows.get(name)
439    
440      def OnDockClose(self, win):      def OnDockDestroy(self, win):
441          del self.openWindows[win.GetName()]          del self.openWindows[win.GetName()]
442          self._UpdateDocks()          self._UpdateDocks()
443    
# Line 432  class DockFrame(wxFrame): Line 446  class DockFrame(wxFrame):
446          self._UpdateDocks()          self._UpdateDocks()
447                    
448      def _UpdateDocks(self):      def _UpdateDocks(self):
         #print "_UpdateDocks()"  
449          if self.__update_lock == 0:          if self.__update_lock == 0:
450              wxLayoutAlgorithm().LayoutWindow(self, self.__mainWindow)              wxLayoutAlgorithm().LayoutWindow(self, self.__mainWindow)
451    
# Line 444  class DockFrame(wxFrame): Line 457  class DockFrame(wxFrame):
457          sash = self.FindWindowById(id)          sash = self.FindWindowById(id)
458          #assert(isinstance(win, wxPanel))          #assert(isinstance(win, wxPanel))
459          dockPanel = sash.GetChildren()[0]          dockPanel = sash.GetChildren()[0]
         #print dockPanel  
460          panel = dockPanel.FindWindowById(PANEL_ID)          panel = dockPanel.FindWindowById(PANEL_ID)
         #print panel  
461          assert isinstance(panel, DockPanel)          assert isinstance(panel, DockPanel)
462          win = panel.GetDockParent()          win = panel.GetDockParent()
         #print win  
463          assert isinstance(win, DockableWindow)          assert isinstance(win, DockableWindow)
464    
465          assert win.IsDocked()          assert win.IsDocked()

Legend:
Removed from v.605  
changed lines
  Added in v.973

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26