/[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 651 by jonathan, Fri Apr 11 14:27:53 2003 UTC revision 666 by jonathan, Mon Apr 14 16:36:33 2003 UTC
# Line 39  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 68  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 90  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 105  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 166  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          if self.bmpUnDock is not None:          #self.__dockButton.SetBitmapLabel(self.__bmpUnDock)
167              self.__dockButton.SetBitmapLabel(self.bmpUnDock)          #self.__dockButton.SetBitmapFocus(self.__bmpUnDock)
168              self.__dockButton.SetBitmapFocus(self.bmpUnDock)          self.__dockButton.SetToolTip(wxToolTip(_("Undock")))
             self.__dockButton.SetToolTip(wxToolTip(_("Undock")))  
         else:  
             self.__dockButton.SetLabel(_("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 196  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          if self.bmpDock is not None:          #self.__dockButton.SetBitmapLabel(self.__bmpDock)
192              self.__dockButton.SetBitmapLabel(self.bmpDock)          #self.__dockButton.SetBitmapFocus(self.__bmpDock)
193              self.__dockButton.SetBitmapFocus(self.bmpDock)          self.__dockButton.SetToolTip(wxToolTip(_("Dock")))
             self.__dockButton.SetToolTip(wxToolTip(_("Dock")))  
         else:  
             self.__dockButton.SetLabel(_("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 217  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 229  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 289  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 326  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()          font = text.GetFont()
315          font.SetPointSize(10)          font.SetPointSize(10)
316          text.SetFont(font)          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.bmpDock   = \          self.__bmpDock   = \
323              resource.GetBitmapResource(DOCK_BMP, wxBITMAP_TYPE_XPM)              resource.GetBitmapResource(DOCK_BMP, wxBITMAP_TYPE_XPM)
324          self.bmpUnDock = \          self.__bmpUnDock = \
325              resource.GetBitmapResource(UNDOCK_BMP, wxBITMAP_TYPE_XPM)              resource.GetBitmapResource(UNDOCK_BMP, wxBITMAP_TYPE_XPM)
326    
327          if self.bmpDock is not None \          if self.__docked:
328              and self.bmpUnDock is not None:              bmp = self.__bmpDock
             self.__dockButton = wxBitmapButton(  
                 self.__dockPanel, ID_BUTTON_DOCK,  
                 self.bmpUnDock,  
                 size = wxSize(self.bmpDock.GetWidth() + 4,  
                               self.bmpDock.GetHeight() + 4),  
                 style = wxBU_EXACTFIT | wxADJUST_MINSIZE)  
329          else:          else:
330              self.bmpDock = \              bmp = self.__bmpUnDock
             self.bmpUnDock = None  
331    
332              self.__dockButton = wxButton(          self.__dockButton = wxBitmapButton(
333                  self.__dockPanel, ID_BUTTON_DOCK,              self.__dockPanel, ID_BUTTON_DOCK,
334                  "WW", style = wxBU_EXACTFIT | wxADJUST_MINSIZE)              bmp,
335                size = wxSize(bmp.GetWidth() + 4, bmp.GetHeight() + 4),
336                style = wxBU_EXACTFIT | wxADJUST_MINSIZE)
337    
338          bmp = resource.GetBitmapResource(CLOSE_BMP, wxBITMAP_TYPE_XPM)          bmp = resource.GetBitmapResource(CLOSE_BMP, wxBITMAP_TYPE_XPM)
339    
# Line 372  class DockableWindow(Publisher): Line 343  class DockableWindow(Publisher):
343                            style = wxBU_EXACTFIT | wxADJUST_MINSIZE)                            style = wxBU_EXACTFIT | wxADJUST_MINSIZE)
344          closeX.SetToolTip(wxToolTip(_("Close")))          closeX.SetToolTip(wxToolTip(_("Close")))
345    
346            #
347          #closeX = wxButton(self.__dockPanel, ID_BUTTON_CLOSE, "X",          # fill in the sizer in an order appropriate to the orientation
348                           #style = wxBU_EXACTFIT | wxADJUST_MINSIZE)          #
   
         #buttonBox.Add(self.__dockButton, 0, wxALIGN_RIGHT, 0)  
         #buttonBox.Add(closeX, 0, wxALIGN_RIGHT, 0)  
   
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, 5, 1, wxGROW)              headerBox.Add(1, 5, 1, wxGROW)
             #headerBox.Add(buttonBox, 0, wxGROW | wxALIGN_RIGHT, 0)  
352              headerBox.Add(self.__dockButton, 0, wxALIGN_RIGHT, 0)              headerBox.Add(self.__dockButton, 0, wxALIGN_RIGHT, 0)
353              headerBox.Add(closeX, 0, wxALIGN_RIGHT | wxLEFT, 4)              headerBox.Add(closeX, 0, wxALIGN_RIGHT | wxLEFT, 4)
354          else:          else:
# Line 391  class DockableWindow(Publisher): Line 357  class DockableWindow(Publisher):
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 459  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 482  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 494  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.651  
changed lines
  Added in v.666

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26