/[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 620 by jonathan, Mon Apr 7 10:14:25 2003 UTC revision 666 by jonathan, Mon Apr 14 16:36:33 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.SetToolTip(wxToolTip(_("Undock")))
169    
170          self.SetDockSize(self.__dockWindow.GetSize())          self.SetDockSize(self.__dockWindow.GetSize())
171    
172          if wasVisible: self.Show(True)          if wasVisible: self.Show(True)
173    
         #self.__parent._UpdateDocks()  
   
174          self.issue(DOCKABLE_DOCKED, self.__id, self)          self.issue(DOCKABLE_DOCKED, self.__id, self)
175    
176      def UnDock(self):      def UnDock(self):
# Line 187  class DockableWindow(Publisher): Line 188  class DockableWindow(Publisher):
188          self.__topWindow = self.__floatWindow          self.__topWindow = self.__floatWindow
189          self.__dockPanel.Reparent(self.__topWindow)          self.__dockPanel.Reparent(self.__topWindow)
190    
191          self.__dockButton.SetLabel(_("Dock"))          #self.__dockButton.SetBitmapLabel(self.__bmpDock)
192            #self.__dockButton.SetBitmapFocus(self.__bmpDock)
193            self.__dockButton.SetToolTip(wxToolTip(_("Dock")))
194    
195          if wasVisible: self.Show()          if wasVisible: self.Show()
196    
197          #          #
198          # restore window information          # restore window information
199          #          #
200          if self.__floatPosition is not None: self.SetPosition(self.__floatPosition)          if self.__floatPosition is not None:
201          if self.__floatSize     is not None: self.SetSize(self.__floatSize)              self.SetPosition(self.__floatPosition)
202            if self.__floatSize is not None:
203                self.SetSize(self.__floatSize)
204    
205          self.__dockPanel.SetSize(self.__topWindow.GetClientSize())          self.__dockPanel.SetSize(self.__topWindow.GetClientSize())
206    
# Line 203  class DockableWindow(Publisher): Line 208  class DockableWindow(Publisher):
208    
209      def IsDocked(self):      def IsDocked(self):
210          self.__CheckAllGood()          self.__CheckAllGood()
   
211          return self.__docked          return self.__docked
212    
   
213      def Show(self, show = True):      def Show(self, show = True):
214          if show:          if show:
215              self.__DoShow()              self.__DoShow()
# Line 215  class DockableWindow(Publisher): Line 218  class DockableWindow(Publisher):
218    
219      def SetDockSize(self, rect = None):      def SetDockSize(self, rect = None):
220    
         #  
         # adjust the size to get the  
221          w0, h0 = self.__dockPanel.GetBestSize()          w0, h0 = self.__dockPanel.GetBestSize()
222          w, h = self.__panel.GetBestSize()          w, h = self.__panel.GetBestSize()
223    
         #print (w0, h0), (w, h)  
   
224          if (w, h) < (w0, h0):          if (w, h) < (w0, h0):
225              w = w0              w = w0
226              h = h0              h = h0
227                                                                                          
228          if rect is not None:          if rect is not None:
229              rw = rect.width              rw = rect.width
230              rh = rect.height              rh = rect.height
             #print "   ", (rw, rh)  
231              if rw < w: rw = w              if rw < w: rw = w
232              if rh < h: rh = h              if rh < h: rh = h
233          else:          else:
# Line 247  class DockableWindow(Publisher): Line 245  class DockableWindow(Publisher):
245          self.__panel.Destroy()          self.__panel.Destroy()
246          self.__floatWindow.Destroy()          self.__floatWindow.Destroy()
247          self.__dockWindow.Destroy()          self.__dockWindow.Destroy()
248          self.__parent.OnDockClose(self)          self.__parent.OnDockDestroy(self)
249                    
250      ##      ##
251      # Event handlers      # Event handlers
# Line 255  class DockableWindow(Publisher): Line 253  class DockableWindow(Publisher):
253    
254      def _OnButtonClose(self, event):      def _OnButtonClose(self, event):
255          #self.Close()          #self.Close()
256          self.Destroy()          self.Show(False)
257    
258      def _OnClose(self, force = False):      def _OnClose(self, force = False):
259          self.Destroy()          self.Show(False)
260    
261      def _OnToggleDock(self, event):      def _OnToggleDock(self, event):
262          self.__CheckAllGood()          self.__CheckAllGood()
# Line 275  class DockableWindow(Publisher): Line 273  class DockableWindow(Publisher):
273    
274      def __DoShow(self):      def __DoShow(self):
275          if self.IsShown(): return          if self.IsShown(): return
         #print "__DoShow()", self.IsShown()  
276    
277          self.__topWindow.Show()          self.__topWindow.Show()
278    
         #if self.IsDocked():  
             #self.SetDockSize()  
   
279          if self.__topWindow is self.__dockWindow:          if self.__topWindow is self.__dockWindow:
280              self.__parent._UpdateDocks()              self.__parent._UpdateDocks()
281                            
282      def __DoHide(self):      def __DoHide(self):
283          if not self.IsShown(): return          if not self.IsShown(): return
284          #print "__DoHide()", self.IsShown()  
285          self.__topWindow.Show(False)          self.__topWindow.Show(False)
286    
287          if self.__topWindow is self.__dockWindow:          if self.__topWindow is self.__dockWindow:
288              self.__parent._UpdateDocks()              self.__parent._UpdateDocks()
289    
   
290      def __CreateBorder(self):      def __CreateBorder(self):
291    
         #self.__panel.Reparent(self) # Make sure we hang on to the panel  
   
292          self.__dockPanel = wxPanel(self.__topWindow, -1, style=wxSUNKEN_BORDER)          self.__dockPanel = wxPanel(self.__topWindow, -1, style=wxSUNKEN_BORDER)
293          #self.__dockPanel.SetBackgroundColour(wxColour(255, 0, 0))  
294            self.__panel.Reparent(self.__dockPanel)
295            self.__panel.SetId(PANEL_ID)
296    
297          if self.__orientation == wxLAYOUT_VERTICAL:          if self.__orientation == wxLAYOUT_VERTICAL:
298              sizer = wxBoxSizer(wxVERTICAL)              sizer = wxBoxSizer(wxVERTICAL)
# Line 312  class DockableWindow(Publisher): Line 305  class DockableWindow(Publisher):
305          headerBox = wxStaticBoxSizer(          headerBox = wxStaticBoxSizer(
306                          wxStaticBox(self.__dockPanel, -1, ""), headerBoxOrient)                          wxStaticBox(self.__dockPanel, -1, ""), headerBoxOrient)
307    
         buttonBox = wxBoxSizer(wxHORIZONTAL)  
   
308          #          #
309          # ideally, we should be able to rotate this text depending on          # ideally, we should be able to rotate this text depending on
310          # our orientation          # our orientation
311          #          #
312          text = wxStaticText(self.__dockPanel, -1, self.GetTitle(),          text = wxStaticText(self.__dockPanel, -1, self.GetTitle(),
313                               style = wxALIGN_CENTRE)                               style = wxALIGN_CENTRE)
314            font = text.GetFont()
315            font.SetPointSize(10)
316            text.SetFont(font)
317    
318          #          #
319          # Perhaps using wxToggleButton would be better, but it's only          # load the dock/undock/close bitmaps
320          # supported under wxMSW and wxGTK as of v2.4.0.3          # and create the buttons
321          #          #
322          self.__dockButton = wxButton(self.__dockPanel, ID_BUTTON_DOCK, "WWWWWW",          self.__bmpDock   = \
323                                       style = wxBU_EXACTFIT | wxADJUST_MINSIZE)              resource.GetBitmapResource(DOCK_BMP, wxBITMAP_TYPE_XPM)
324            self.__bmpUnDock = \
325                resource.GetBitmapResource(UNDOCK_BMP, wxBITMAP_TYPE_XPM)
326    
327            if self.__docked:
328                bmp = self.__bmpDock
329            else:
330                bmp = self.__bmpUnDock
331    
332          closeX = wxButton(self.__dockPanel, ID_BUTTON_CLOSE, "X",          self.__dockButton = wxBitmapButton(
333                           style = wxBU_EXACTFIT | wxADJUST_MINSIZE)              self.__dockPanel, ID_BUTTON_DOCK,
334                bmp,
335                size = wxSize(bmp.GetWidth() + 4, bmp.GetHeight() + 4),
336                style = wxBU_EXACTFIT | wxADJUST_MINSIZE)
337    
338          buttonBox.Add(self.__dockButton, 0, wxALIGN_RIGHT, 0)          bmp = resource.GetBitmapResource(CLOSE_BMP, wxBITMAP_TYPE_XPM)
         buttonBox.Add(closeX, 0, wxALIGN_RIGHT, 0)  
339    
340            closeX = wxBitmapButton(self.__dockPanel, ID_BUTTON_CLOSE, bmp,
341                              size = wxSize(bmp.GetWidth() + 4,
342                                            bmp.GetHeight() + 4),
343                              style = wxBU_EXACTFIT | wxADJUST_MINSIZE)
344            closeX.SetToolTip(wxToolTip(_("Close")))
345    
346            #
347            # fill in the sizer in an order appropriate to the orientation
348            #
349          if self.__orientation == wxLAYOUT_VERTICAL:          if self.__orientation == wxLAYOUT_VERTICAL:
350              headerBox.Add(text, 0, wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL, 0)              headerBox.Add(text, 0, wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL, 0)
351              headerBox.Add(1, 20, 1, wxGROW)              headerBox.Add(1, 5, 1, wxGROW)
352              headerBox.Add(buttonBox, 0, wxGROW | wxALIGN_RIGHT, 0)              headerBox.Add(self.__dockButton, 0, wxALIGN_RIGHT, 0)
353                headerBox.Add(closeX, 0, wxALIGN_RIGHT | wxLEFT, 4)
354          else:          else:
355              headerBox.Add(buttonBox, 0, wxGROW, 0)              headerBox.Add(closeX, 0, wxALIGN_RIGHT | wxBOTTOM, 4)
356                headerBox.Add(self.__dockButton, 0, wxALIGN_RIGHT, 0)
357              headerBox.Add(text, 0, wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL, 0)              headerBox.Add(text, 0, wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL, 0)
358    
359          sizer.Add(headerBox, 0, wxGROW, 0)          sizer.Add(headerBox, 0, wxGROW, 0)
   
         self.__panel.Reparent(self.__dockPanel)  
         self.__panel.SetId(PANEL_ID)  
   
360          sizer.Add(self.__panel, 1, wxGROW, 0)          sizer.Add(self.__panel, 1, wxGROW, 0)
361    
         sizer.Fit(self.__dockPanel)  
362    
         self.__dockPanel.SetSizer(sizer)  
363          self.__dockPanel.SetAutoLayout(True)          self.__dockPanel.SetAutoLayout(True)
364            self.__dockPanel.SetSizer(sizer)
365          sizer.SetSizeHints(self.__dockPanel)          sizer.SetSizeHints(self.__dockPanel)
366            sizer.SetSizeHints(self.__floatWindow)
367    
368          EVT_BUTTON(self.__dockPanel, ID_BUTTON_DOCK, self._OnToggleDock)          EVT_BUTTON(self.__dockPanel, ID_BUTTON_DOCK, self._OnToggleDock)
369          EVT_BUTTON(self.__dockPanel, ID_BUTTON_CLOSE, self._OnButtonClose)          EVT_BUTTON(self.__dockPanel, ID_BUTTON_CLOSE, self._OnButtonClose)
# Line 411  class DockFrame(wxFrame): Line 420  class DockFrame(wxFrame):
420          sash = wxSashLayoutWindow(self, id, style=wxNO_BORDER|wxSW_3D)          sash = wxSashLayoutWindow(self, id, style=wxNO_BORDER|wxSW_3D)
421          sash.SetOrientation(orient)          sash.SetOrientation(orient)
422          sash.SetAlignment(align)          sash.SetAlignment(align)
         #print align, DockFrame.layout2oppSash[align]  
423          sash.SetSashVisible(DockFrame.layout2oppSash[align], True)          sash.SetSashVisible(DockFrame.layout2oppSash[align], True)
424          sash.SetSashBorder(DockFrame.layout2oppSash[align], True)          sash.SetSashBorder(DockFrame.layout2oppSash[align], True)
425    
# Line 425  class DockFrame(wxFrame): Line 433  class DockFrame(wxFrame):
433      def FindRegisteredDock(self, name):      def FindRegisteredDock(self, name):
434          return self.openWindows.get(name)          return self.openWindows.get(name)
435    
436      def OnDockClose(self, win):      def OnDockDestroy(self, win):
437          del self.openWindows[win.GetName()]          del self.openWindows[win.GetName()]
438          self._UpdateDocks()          self._UpdateDocks()
439    
# Line 434  class DockFrame(wxFrame): Line 442  class DockFrame(wxFrame):
442          self._UpdateDocks()          self._UpdateDocks()
443                    
444      def _UpdateDocks(self):      def _UpdateDocks(self):
         #print "_UpdateDocks()"  
445          if self.__update_lock == 0:          if self.__update_lock == 0:
446              wxLayoutAlgorithm().LayoutWindow(self, self.__mainWindow)              wxLayoutAlgorithm().LayoutWindow(self, self.__mainWindow)
447    
# Line 446  class DockFrame(wxFrame): Line 453  class DockFrame(wxFrame):
453          sash = self.FindWindowById(id)          sash = self.FindWindowById(id)
454          #assert(isinstance(win, wxPanel))          #assert(isinstance(win, wxPanel))
455          dockPanel = sash.GetChildren()[0]          dockPanel = sash.GetChildren()[0]
         #print dockPanel  
456          panel = dockPanel.FindWindowById(PANEL_ID)          panel = dockPanel.FindWindowById(PANEL_ID)
         #print panel  
457          assert isinstance(panel, DockPanel)          assert isinstance(panel, DockPanel)
458          win = panel.GetDockParent()          win = panel.GetDockParent()
         #print win  
459          assert isinstance(win, DockableWindow)          assert isinstance(win, DockableWindow)
460    
461          assert win.IsDocked()          assert win.IsDocked()

Legend:
Removed from v.620  
changed lines
  Added in v.666

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26