/[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 657 by jonathan, Fri Apr 11 18:29:57 2003 UTC revision 973 by jonathan, Wed May 21 17:39:31 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.SetBitmapSelected(self.__bmpUnDock)
169              self.__dockButton.SetToolTip(wxToolTip(_("Undock")))          self.__dockButton.SetBitmapDisabled(self.__bmpUnDock)
170          else:          self.__dockButton.SetToolTip(wxToolTip(_("Undock")))
             self.__dockButton.SetLabel(_("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 196  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          if self.__bmpDock is not None:          self.__dockButton.SetBitmapLabel(self.__bmpDock)
194              self.__dockButton.SetBitmapLabel(self.__bmpDock)          self.__dockButton.SetBitmapFocus(self.__bmpDock)
195              self.__dockButton.SetBitmapFocus(self.__bmpDock)          self.__dockButton.SetBitmapSelected(self.__bmpDock)
196              self.__dockButton.SetToolTip(wxToolTip(_("Dock")))          self.__dockButton.SetBitmapDisabled(self.__bmpDock)
197          else:          self.__dockButton.SetToolTip(wxToolTip(_("Dock")))
             self.__dockButton.SetLabel(_("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())          self.__dockPanel.SetSize(self.__topWindow.GetClientSize())
210    
# Line 217  class DockableWindow(Publisher): Line 212  class DockableWindow(Publisher):
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 229  class DockableWindow(Publisher): Line 222  class DockableWindow(Publisher):
222    
223      def SetDockSize(self, rect = None):      def SetDockSize(self, rect = None):
224    
         print "---------------"  
         #  
         # adjust the size to get the  
225          w0, h0 = self.__dockPanel.GetBestSize()          w0, h0 = self.__dockPanel.GetBestSize()
         print w0, h0  
226          w, h = self.__panel.GetBestSize()          w, h = self.__panel.GetBestSize()
         print w, h  
         #w0, h0 = self.__dockPanel.GetBestSize()  
         #w0 = h0 = 0  
         #w, h = self.__dockPanel.GetBestSize()  
   
         #print (w0, h0), (w, h)  
227    
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 260  class DockableWindow(Publisher): Line 242  class DockableWindow(Publisher):
242          rw += 8 # XXX: without this the sash isn't visible!?!?!?!          rw += 8 # XXX: without this the sash isn't visible!?!?!?!
243          rh += 8 # XXX: without this the sash isn't visible!?!?!?!          rh += 8 # XXX: without this the sash isn't visible!?!?!?!
244                                                                                                                                                                                
         print rw, rh  
   
245          self.__dockWindow.SetDefaultSize(wxSize(rw, rh))          self.__dockWindow.SetDefaultSize(wxSize(rw, rh))
246    
247    
# Line 297  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)
         #self.__dockPanel.SetBackgroundColour(wxColour(255, 0, 0))  
297    
298          self.__panel.Reparent(self.__dockPanel)          self.__panel.Reparent(self.__dockPanel)
299          self.__panel.SetId(PANEL_ID)          self.__panel.SetId(PANEL_ID)
# Line 337  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 = wxALIGN_CENTRE)                               style = wxALIGN_CENTRE)
   
318          font = text.GetFont()          font = text.GetFont()
319          font.SetPointSize(10)          font.SetPointSize(10)
320          text.SetFont(font)          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.__bmpDock   = \          self.__bmpDock   = \
327              resource.GetBitmapResource(DOCK_BMP, wxBITMAP_TYPE_XPM)              resource.GetBitmapResource(DOCK_BMP, wxBITMAP_TYPE_XPM)
328          self.__bmpUnDock = \          self.__bmpUnDock = \
329              resource.GetBitmapResource(UNDOCK_BMP, wxBITMAP_TYPE_XPM)              resource.GetBitmapResource(UNDOCK_BMP, wxBITMAP_TYPE_XPM)
330    
331          if self.__bmpDock is not None \          if self.__docked:
332              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)  
333          else:          else:
334              self.__bmpDock = \              bmp = self.__bmpUnDock
             self.__bmpUnDock = None  
335    
336              self.__dockButton = wxButton(          self.__dockButton = wxBitmapButton(
337                  self.__dockPanel, ID_BUTTON_DOCK,              self.__dockPanel, ID_BUTTON_DOCK,
338                  "WW", style = wxBU_EXACTFIT | wxADJUST_MINSIZE)              bmp,
339                size = wxSize(bmp.GetWidth() + 4, bmp.GetHeight() + 4),
340                style = wxBU_EXACTFIT | wxADJUST_MINSIZE)
341    
342          bmp = resource.GetBitmapResource(CLOSE_BMP, wxBITMAP_TYPE_XPM)          bmp = resource.GetBitmapResource(CLOSE_BMP, wxBITMAP_TYPE_XPM)
343    
# Line 383  class DockableWindow(Publisher): Line 347  class DockableWindow(Publisher):
347                            style = wxBU_EXACTFIT | wxADJUST_MINSIZE)                            style = wxBU_EXACTFIT | wxADJUST_MINSIZE)
348          closeX.SetToolTip(wxToolTip(_("Close")))          closeX.SetToolTip(wxToolTip(_("Close")))
349    
350            #
351          #closeX = wxButton(self.__dockPanel, ID_BUTTON_CLOSE, "X",          # fill in the sizer in an order appropriate to the orientation
352                           #style = wxBU_EXACTFIT | wxADJUST_MINSIZE)          #
   
         #buttonBox.Add(self.__dockButton, 0, wxALIGN_RIGHT, 0)  
         #buttonBox.Add(closeX, 0, wxALIGN_RIGHT, 0)  
   
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, 5, 1, wxGROW)              headerBox.Add(1, 5, 1, wxGROW)
# Line 401  class DockableWindow(Publisher): Line 361  class DockableWindow(Publisher):
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)
   
   
364          sizer.Add(self.__panel, 1, wxGROW, 0)          sizer.Add(self.__panel, 1, wxGROW, 0)
365    
         #sizer.Fit(self.__dockPanel)  
366    
367          self.__panel.SetAutoLayout(True)          self.__dockPanel.SetAutoLayout(True)
368          sizer.SetSizeHints(self.__panel)          self.__dockPanel.SetSizer(sizer)
369            sizer.SetSizeHints(self.__dockPanel)
370          self.__dockPanel.SetSizerAndFit(sizer)          sizer.SetSizeHints(self.__floatWindow)
         #self.__dockPanel.SetAutoLayout(True)  
         #sizer.SetSizeHints(self.__dockPanel)  
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 431  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 441  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 469  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 492  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 504  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.657  
changed lines
  Added in v.973

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26