/[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 577 by jonathan, Mon Mar 31 18:31:33 2003 UTC revision 659 by jonathan, Mon Apr 14 14:07:05 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"))          if self.__bmpUnDock is not None:
167                self.__dockButton.SetBitmapLabel(self.__bmpUnDock)
168                self.__dockButton.SetBitmapFocus(self.__bmpUnDock)
169                self.__dockButton.SetToolTip(wxToolTip(_("Undock")))
170            else:
171                self.__dockButton.SetLabel(_("Undock"))
172    
173          self.SetDockSize(self.__dockWindow.GetSize())          self.SetDockSize(self.__dockWindow.GetSize())
174    
# Line 187  class DockableWindow(Publisher): Line 193  class DockableWindow(Publisher):
193          self.__topWindow = self.__floatWindow          self.__topWindow = self.__floatWindow
194          self.__dockPanel.Reparent(self.__topWindow)          self.__dockPanel.Reparent(self.__topWindow)
195    
196          self.__dockButton.SetLabel(_("Dock"))          if self.__bmpDock is not None:
197                self.__dockButton.SetBitmapLabel(self.__bmpDock)
198                self.__dockButton.SetBitmapFocus(self.__bmpDock)
199                self.__dockButton.SetToolTip(wxToolTip(_("Dock")))
200            else:
201                self.__dockButton.SetLabel(_("Dock"))
202    
203          if wasVisible: self.Show()          if wasVisible: self.Show()
204    
# Line 197  class DockableWindow(Publisher): Line 208  class DockableWindow(Publisher):
208          if self.__floatPosition is not None: self.SetPosition(self.__floatPosition)          if self.__floatPosition is not None: self.SetPosition(self.__floatPosition)
209          if self.__floatSize     is not None: self.SetSize(self.__floatSize)          if self.__floatSize     is not None: self.SetSize(self.__floatSize)
210    
211            self.__dockPanel.SetSize(self.__topWindow.GetClientSize())
212    
213          self.issue(DOCKABLE_UNDOCKED, self.__id, self)          self.issue(DOCKABLE_UNDOCKED, self.__id, self)
214    
215      def IsDocked(self):      def IsDocked(self):
# Line 213  class DockableWindow(Publisher): Line 226  class DockableWindow(Publisher):
226    
227      def SetDockSize(self, rect = None):      def SetDockSize(self, rect = None):
228    
         #  
         # adjust the size to get the  
229          w0, h0 = self.__dockPanel.GetBestSize()          w0, h0 = self.__dockPanel.GetBestSize()
230          w, h = self.__panel.GetBestSize()          w, h = self.__panel.GetBestSize()
231    
         #print (w0, h0), (w, h)  
   
232          if (w, h) < (w0, h0):          if (w, h) < (w0, h0):
233              w = w0              w = w0
234              h = h0              h = h0
235                                                                                          
236          if rect is not None:          if rect is not None:
237              rw = rect.width              rw = rect.width
238              rh = rect.height              rh = rect.height
             #print "   ", (rw, rh)  
239              if rw < w: rw = w              if rw < w: rw = w
240              if rh < h: rh = h              if rh < h: rh = h
241          else:          else:
# Line 245  class DockableWindow(Publisher): Line 253  class DockableWindow(Publisher):
253          self.__panel.Destroy()          self.__panel.Destroy()
254          self.__floatWindow.Destroy()          self.__floatWindow.Destroy()
255          self.__dockWindow.Destroy()          self.__dockWindow.Destroy()
256          self.__parent.OnDockClose(self)          self.__parent.OnDockDestroy(self)
257                    
258      ##      ##
259      # Event handlers      # Event handlers
260      #      #
261    
262      def _OnButtonClose(self, event):      def _OnButtonClose(self, event):
263          self.Close()          #self.Close()
264            self.Show(False)
265    
266      def _OnClose(self, force = False):      def _OnClose(self, force = False):
267          self.Destroy()          self.Show(False)
268    
269      def _OnToggleDock(self, event):      def _OnToggleDock(self, event):
270          self.__CheckAllGood()          self.__CheckAllGood()
# Line 272  class DockableWindow(Publisher): Line 281  class DockableWindow(Publisher):
281    
282      def __DoShow(self):      def __DoShow(self):
283          if self.IsShown(): return          if self.IsShown(): return
         #print "__DoShow()", self.IsShown()  
284    
285          self.__topWindow.Show()          self.__topWindow.Show()
286    
# Line 284  class DockableWindow(Publisher): Line 292  class DockableWindow(Publisher):
292                            
293      def __DoHide(self):      def __DoHide(self):
294          if not self.IsShown(): return          if not self.IsShown(): return
         #print "__DoHide()", self.IsShown()  
295          self.__topWindow.Show(False)          self.__topWindow.Show(False)
296    
297          if self.__topWindow is self.__dockWindow:          if self.__topWindow is self.__dockWindow:
# Line 296  class DockableWindow(Publisher): Line 303  class DockableWindow(Publisher):
303          #self.__panel.Reparent(self) # Make sure we hang on to the panel          #self.__panel.Reparent(self) # Make sure we hang on to the panel
304    
305          self.__dockPanel = wxPanel(self.__topWindow, -1, style=wxSUNKEN_BORDER)          self.__dockPanel = wxPanel(self.__topWindow, -1, style=wxSUNKEN_BORDER)
306          #self.__dockPanel.SetBackgroundColour(wxColour(255, 0, 0))  
307            self.__panel.Reparent(self.__dockPanel)
308            self.__panel.SetId(PANEL_ID)
309    
310          if self.__orientation == wxLAYOUT_VERTICAL:          if self.__orientation == wxLAYOUT_VERTICAL:
311              sizer = wxBoxSizer(wxVERTICAL)              sizer = wxBoxSizer(wxVERTICAL)
# Line 309  class DockableWindow(Publisher): Line 318  class DockableWindow(Publisher):
318          headerBox = wxStaticBoxSizer(          headerBox = wxStaticBoxSizer(
319                          wxStaticBox(self.__dockPanel, -1, ""), headerBoxOrient)                          wxStaticBox(self.__dockPanel, -1, ""), headerBoxOrient)
320    
321          buttonBox = wxBoxSizer(wxHORIZONTAL)          #buttonBox = wxBoxSizer(wxHORIZONTAL)
322    
323          #          #
324          # ideally, we should be able to rotate this text depending on          # ideally, we should be able to rotate this text depending on
325          # our orientation          # our orientation
326          #          #
327          text = wxStaticText(self.__dockPanel, -1, self.GetTitle(),          text = wxStaticText(self.__dockPanel, -1, self.GetTitle(),
328                               style = wxSIMPLE_BORDER | wxALIGN_CENTRE)                               style = wxALIGN_CENTRE)
329    
330            font = text.GetFont()
331            font.SetPointSize(10)
332            text.SetFont(font)
333    
334          #          #
335          # Perhaps using wxToggleButton would be better, but it's only          # Perhaps using wxToggleButton would be better, but it's only
336          # supported under wxMSW and wxGTK as of v2.4.0.3          # supported under wxMSW and wxGTK as of v2.4.0.3
337          #          #
338          self.__dockButton = wxButton(self.__dockPanel, ID_BUTTON_DOCK, "WWWWWW",          self.__bmpDock   = \
339                                       style = wxBU_EXACTFIT | wxADJUST_MINSIZE)              resource.GetBitmapResource(DOCK_BMP, wxBITMAP_TYPE_XPM)
340            self.__bmpUnDock = \
341                resource.GetBitmapResource(UNDOCK_BMP, wxBITMAP_TYPE_XPM)
342    
343            if self.__bmpDock is not None \
344                and self.__bmpUnDock is not None:
345                self.__dockButton = wxBitmapButton(
346                    self.__dockPanel, ID_BUTTON_DOCK,
347                    self.__bmpUnDock,
348                    size = wxSize(self.__bmpDock.GetWidth() + 4,
349                                  self.__bmpDock.GetHeight() + 4),
350                    style = wxBU_EXACTFIT | wxADJUST_MINSIZE)
351            else:
352                self.__bmpDock = \
353                self.__bmpUnDock = None
354    
355                self.__dockButton = wxButton(
356                    self.__dockPanel, ID_BUTTON_DOCK,
357                    "WW", style = wxBU_EXACTFIT | wxADJUST_MINSIZE)
358    
359            bmp = resource.GetBitmapResource(CLOSE_BMP, wxBITMAP_TYPE_XPM)
360    
361            closeX = wxBitmapButton(self.__dockPanel, ID_BUTTON_CLOSE, bmp,
362                              size = wxSize(bmp.GetWidth() + 4,
363                                            bmp.GetHeight() + 4),
364                              style = wxBU_EXACTFIT | wxADJUST_MINSIZE)
365            closeX.SetToolTip(wxToolTip(_("Close")))
366    
367    
368          closeX = wxButton(self.__dockPanel, ID_BUTTON_CLOSE, "X",          #closeX = wxButton(self.__dockPanel, ID_BUTTON_CLOSE, "X",
369                           style = wxBU_EXACTFIT | wxADJUST_MINSIZE)                           #style = wxBU_EXACTFIT | wxADJUST_MINSIZE)
370    
371          buttonBox.Add(self.__dockButton, 0, wxALIGN_RIGHT, 0)          #buttonBox.Add(self.__dockButton, 0, wxALIGN_RIGHT, 0)
372          buttonBox.Add(closeX, 0, wxALIGN_RIGHT, 0)          #buttonBox.Add(closeX, 0, wxALIGN_RIGHT, 0)
373    
374          if self.__orientation == wxLAYOUT_VERTICAL:          if self.__orientation == wxLAYOUT_VERTICAL:
375              headerBox.Add(text, 0, wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL, 0)              headerBox.Add(text, 0, wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL, 0)
376              headerBox.Add(1, 20, 1, wxGROW)              headerBox.Add(1, 5, 1, wxGROW)
377              headerBox.Add(buttonBox, 0, wxGROW | wxALIGN_RIGHT, 0)              headerBox.Add(self.__dockButton, 0, wxALIGN_RIGHT, 0)
378                headerBox.Add(closeX, 0, wxALIGN_RIGHT | wxLEFT, 4)
379          else:          else:
380              headerBox.Add(buttonBox, 0, wxGROW, 0)              headerBox.Add(closeX, 0, wxALIGN_RIGHT | wxBOTTOM, 4)
381                headerBox.Add(self.__dockButton, 0, wxALIGN_RIGHT, 0)
382              headerBox.Add(text, 0, wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL, 0)              headerBox.Add(text, 0, wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL, 0)
383    
384          sizer.Add(headerBox, 0, wxGROW, 0)          sizer.Add(headerBox, 0, wxGROW, 0)
   
         self.__panel.Reparent(self.__dockPanel)  
         self.__panel.SetId(PANEL_ID)  
   
385          sizer.Add(self.__panel, 1, wxGROW, 0)          sizer.Add(self.__panel, 1, wxGROW, 0)
386    
         sizer.Fit(self.__dockPanel)  
   
         self.__dockPanel.SetSizer(sizer)  
387          self.__dockPanel.SetAutoLayout(True)          self.__dockPanel.SetAutoLayout(True)
388            self.__dockPanel.SetSizer(sizer)
389          sizer.SetSizeHints(self.__dockPanel)          sizer.SetSizeHints(self.__dockPanel)
390    
391            sizer.SetSizeHints(self.__topWindow)
392    
393          EVT_BUTTON(self.__dockPanel, ID_BUTTON_DOCK, self._OnToggleDock)          EVT_BUTTON(self.__dockPanel, ID_BUTTON_DOCK, self._OnToggleDock)
394          EVT_BUTTON(self.__dockPanel, ID_BUTTON_CLOSE, self._OnButtonClose)          EVT_BUTTON(self.__dockPanel, ID_BUTTON_CLOSE, self._OnButtonClose)
395    
# Line 408  class DockFrame(wxFrame): Line 445  class DockFrame(wxFrame):
445          sash = wxSashLayoutWindow(self, id, style=wxNO_BORDER|wxSW_3D)          sash = wxSashLayoutWindow(self, id, style=wxNO_BORDER|wxSW_3D)
446          sash.SetOrientation(orient)          sash.SetOrientation(orient)
447          sash.SetAlignment(align)          sash.SetAlignment(align)
         #print align, DockFrame.layout2oppSash[align]  
448          sash.SetSashVisible(DockFrame.layout2oppSash[align], True)          sash.SetSashVisible(DockFrame.layout2oppSash[align], True)
449          sash.SetSashBorder(DockFrame.layout2oppSash[align], True)          sash.SetSashBorder(DockFrame.layout2oppSash[align], True)
450    
# Line 422  class DockFrame(wxFrame): Line 458  class DockFrame(wxFrame):
458      def FindRegisteredDock(self, name):      def FindRegisteredDock(self, name):
459          return self.openWindows.get(name)          return self.openWindows.get(name)
460    
461      def OnDockClose(self, win):      def OnDockDestroy(self, win):
462          del self.openWindows[win.GetName()]          del self.openWindows[win.GetName()]
463          self._UpdateDocks()          self._UpdateDocks()
464    
# Line 431  class DockFrame(wxFrame): Line 467  class DockFrame(wxFrame):
467          self._UpdateDocks()          self._UpdateDocks()
468                    
469      def _UpdateDocks(self):      def _UpdateDocks(self):
         #print "_UpdateDocks()"  
470          if self.__update_lock == 0:          if self.__update_lock == 0:
471              wxLayoutAlgorithm().LayoutWindow(self, self.__mainWindow)              wxLayoutAlgorithm().LayoutWindow(self, self.__mainWindow)
472    
# Line 443  class DockFrame(wxFrame): Line 478  class DockFrame(wxFrame):
478          sash = self.FindWindowById(id)          sash = self.FindWindowById(id)
479          #assert(isinstance(win, wxPanel))          #assert(isinstance(win, wxPanel))
480          dockPanel = sash.GetChildren()[0]          dockPanel = sash.GetChildren()[0]
         #print dockPanel  
481          panel = dockPanel.FindWindowById(PANEL_ID)          panel = dockPanel.FindWindowById(PANEL_ID)
482          #print panel          assert isinstance(panel, DockPanel)
         assert(isinstance(panel, DockPanel))  
483          win = panel.GetDockParent()          win = panel.GetDockParent()
484          #print win          assert isinstance(win, DockableWindow)
         assert(isinstance(win, DockableWindow))  
485    
486          assert(win.IsDocked())          assert win.IsDocked()
487    
488          rect = event.GetDragRect()          rect = event.GetDragRect()
489    

Legend:
Removed from v.577  
changed lines
  Added in v.659

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26