/[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 571 by jonathan, Fri Mar 28 17:06:38 2003 UTC revision 651 by jonathan, Fri Apr 11 14:27:53 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 162  class DockableWindow(Publisher): Line 166  class DockableWindow(Publisher):
166          self.__topWindow = self.__dockWindow          self.__topWindow = self.__dockWindow
167          self.__dockPanel.Reparent(self.__topWindow)          self.__dockPanel.Reparent(self.__topWindow)
168    
169          self.__dockButton.SetLabel(_("Undock"))          if self.bmpUnDock is not None:
170                self.__dockButton.SetBitmapLabel(self.bmpUnDock)
171                self.__dockButton.SetBitmapFocus(self.bmpUnDock)
172                self.__dockButton.SetToolTip(wxToolTip(_("Undock")))
173            else:
174                self.__dockButton.SetLabel(_("Undock"))
175    
176          self.SetDockSize(self.__dockWindow.GetSize())          self.SetDockSize(self.__dockWindow.GetSize())
177    
# Line 187  class DockableWindow(Publisher): Line 196  class DockableWindow(Publisher):
196          self.__topWindow = self.__floatWindow          self.__topWindow = self.__floatWindow
197          self.__dockPanel.Reparent(self.__topWindow)          self.__dockPanel.Reparent(self.__topWindow)
198    
199          self.__dockButton.SetLabel(_("Dock"))          if self.bmpDock is not None:
200                self.__dockButton.SetBitmapLabel(self.bmpDock)
201                self.__dockButton.SetBitmapFocus(self.bmpDock)
202                self.__dockButton.SetToolTip(wxToolTip(_("Dock")))
203            else:
204                self.__dockButton.SetLabel(_("Dock"))
205    
206          if wasVisible: self.Show()          if wasVisible: self.Show()
207    
208          #          #
209          # restore window information          # restore window information
210          #          #
211          #if self.__floatPosition is not None: self.SetPosition(self.__floatPosition)          if self.__floatPosition is not None: self.SetPosition(self.__floatPosition)
212          #if self.__floatSize     is not None: self.SetSize(self.__floatSize)          if self.__floatSize     is not None: self.SetSize(self.__floatSize)
213    
214            self.__dockPanel.SetSize(self.__topWindow.GetClientSize())
215    
216          self.issue(DOCKABLE_UNDOCKED, self.__id, self)          self.issue(DOCKABLE_UNDOCKED, self.__id, self)
217    
# Line 241  class DockableWindow(Publisher): Line 257  class DockableWindow(Publisher):
257          self.__dockWindow.SetDefaultSize(wxSize(rw, rh))          self.__dockWindow.SetDefaultSize(wxSize(rw, rh))
258    
259    
260      def Close(self):      def Destroy(self):
261          self.__panel.Close(True)          self.__panel.Destroy()
262          self.__floatWindow.Destroy()          self.__floatWindow.Destroy()
263          self.__dockWindow.Destroy()          self.__dockWindow.Destroy()
264          self.__parent.OnDockClose(self)          self.__parent.OnDockDestroy(self)
265            
266      ##      ##
267      # Event handlers      # Event handlers
268      #      #
269    
270      def _OnButtonClose(self, event):      def _OnButtonClose(self, event):
271          self.Close()          #self.Close()
272            self.Show(False)
273    
274      def _OnClose(self, force = False):      def _OnClose(self, force = False):
275          self.Close()          self.Show(False)
276    
277      def _OnToggleDock(self, event):      def _OnToggleDock(self, event):
278          self.__CheckAllGood()          self.__CheckAllGood()
# Line 309  class DockableWindow(Publisher): Line 326  class DockableWindow(Publisher):
326          headerBox = wxStaticBoxSizer(          headerBox = wxStaticBoxSizer(
327                          wxStaticBox(self.__dockPanel, -1, ""), headerBoxOrient)                          wxStaticBox(self.__dockPanel, -1, ""), headerBoxOrient)
328    
329          buttonBox = wxBoxSizer(wxHORIZONTAL)          #buttonBox = wxBoxSizer(wxHORIZONTAL)
330    
331          #          #
332          # ideally, we should be able to rotate this text depending on          # ideally, we should be able to rotate this text depending on
333          # our orientation          # our orientation
334          #          #
335          text = wxStaticText(self.__dockPanel, -1, self.GetTitle(),          text = wxStaticText(self.__dockPanel, -1, self.GetTitle(),
336                               style = wxSIMPLE_BORDER | wxALIGN_CENTRE)                               style = wxALIGN_CENTRE)
337    
338            font = text.GetFont()
339            font.SetPointSize(10)
340            text.SetFont(font)
341    
342          #          #
343          # Perhaps using wxToggleButton would be better, but it's only          # Perhaps using wxToggleButton would be better, but it's only
344          # supported under wxMSW and wxGTK as of v2.4.0.3          # supported under wxMSW and wxGTK as of v2.4.0.3
345          #          #
346          self.__dockButton = wxButton(self.__dockPanel, ID_BUTTON_DOCK, "WWWWWW",          self.bmpDock   = \
347                                       style = wxBU_EXACTFIT | wxADJUST_MINSIZE)              resource.GetBitmapResource(DOCK_BMP, wxBITMAP_TYPE_XPM)
348            self.bmpUnDock = \
349                resource.GetBitmapResource(UNDOCK_BMP, wxBITMAP_TYPE_XPM)
350    
351            if self.bmpDock is not None \
352                and self.bmpUnDock is not None:
353                self.__dockButton = wxBitmapButton(
354                    self.__dockPanel, ID_BUTTON_DOCK,
355                    self.bmpUnDock,
356                    size = wxSize(self.bmpDock.GetWidth() + 4,
357                                  self.bmpDock.GetHeight() + 4),
358                    style = wxBU_EXACTFIT | wxADJUST_MINSIZE)
359            else:
360                self.bmpDock = \
361                self.bmpUnDock = None
362    
363                self.__dockButton = wxButton(
364                    self.__dockPanel, ID_BUTTON_DOCK,
365                    "WW", style = wxBU_EXACTFIT | wxADJUST_MINSIZE)
366    
367            bmp = resource.GetBitmapResource(CLOSE_BMP, wxBITMAP_TYPE_XPM)
368    
369            closeX = wxBitmapButton(self.__dockPanel, ID_BUTTON_CLOSE, bmp,
370                              size = wxSize(bmp.GetWidth() + 4,
371                                            bmp.GetHeight() + 4),
372                              style = wxBU_EXACTFIT | wxADJUST_MINSIZE)
373            closeX.SetToolTip(wxToolTip(_("Close")))
374    
375    
376          closeX = wxButton(self.__dockPanel, ID_BUTTON_CLOSE, "X",          #closeX = wxButton(self.__dockPanel, ID_BUTTON_CLOSE, "X",
377                           style = wxBU_EXACTFIT | wxADJUST_MINSIZE)                           #style = wxBU_EXACTFIT | wxADJUST_MINSIZE)
378    
379          buttonBox.Add(self.__dockButton, 0, wxALIGN_RIGHT, 0)          #buttonBox.Add(self.__dockButton, 0, wxALIGN_RIGHT, 0)
380          buttonBox.Add(closeX, 0, wxALIGN_RIGHT, 0)          #buttonBox.Add(closeX, 0, wxALIGN_RIGHT, 0)
381    
382          if self.__orientation == wxLAYOUT_VERTICAL:          if self.__orientation == wxLAYOUT_VERTICAL:
383              headerBox.Add(text, 0, wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL, 0)              headerBox.Add(text, 0, wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL, 0)
384              headerBox.Add(1, 20, 1, wxGROW)              headerBox.Add(1, 5, 1, wxGROW)
385              headerBox.Add(buttonBox, 0, wxGROW | wxALIGN_RIGHT, 0)              #headerBox.Add(buttonBox, 0, wxGROW | wxALIGN_RIGHT, 0)
386                headerBox.Add(self.__dockButton, 0, wxALIGN_RIGHT, 0)
387                headerBox.Add(closeX, 0, wxALIGN_RIGHT | wxLEFT, 4)
388          else:          else:
389              headerBox.Add(buttonBox, 0, wxGROW, 0)              headerBox.Add(closeX, 0, wxALIGN_RIGHT | wxBOTTOM, 4)
390                headerBox.Add(self.__dockButton, 0, wxALIGN_RIGHT, 0)
391              headerBox.Add(text, 0, wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL, 0)              headerBox.Add(text, 0, wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL, 0)
392    
393          sizer.Add(headerBox, 0, wxGROW, 0)          sizer.Add(headerBox, 0, wxGROW, 0)
# Line 364  class DockFrame(wxFrame): Line 415  class DockFrame(wxFrame):
415    
416          self.openWindows = {}          self.openWindows = {}
417    
418          EVT_SIZE(self, self._OnSashSize)          self.__update_lock = 0
419    
420          self.SetMainWindow(None)          self.SetMainWindow(None)
421    
422    
423            EVT_SIZE(self, self._OnSashSize)
424            EVT_CLOSE(self, self._OnClose)
425    
426      layout2oppSash = {      layout2oppSash = {
427              wxLAYOUT_NONE   : wxSASH_NONE,              wxLAYOUT_NONE   : wxSASH_NONE,
428              wxLAYOUT_TOP    : wxSASH_BOTTOM,              wxLAYOUT_TOP    : wxSASH_BOTTOM,
# Line 375  class DockFrame(wxFrame): Line 430  class DockFrame(wxFrame):
430              wxLAYOUT_RIGHT  : wxSASH_LEFT,              wxLAYOUT_RIGHT  : wxSASH_LEFT,
431              wxLAYOUT_BOTTOM : wxSASH_TOP }              wxLAYOUT_BOTTOM : wxSASH_TOP }
432    
433    
434        def _OnClose(self, event):
435    
436            self.__update_lock += 1
437    
438            #
439            # child windows are not notified when the parent is destroyed
440            # as of v2.4.0.3 so we need to interate over our children
441            # and tell them to go away.
442            #
443            for key in self.openWindows.keys():
444                win = self.openWindows[key]
445                win.Destroy()
446    
447            self.__update_lock -= 1
448    
449            # should really call _UpdateDocks() here but we don't need to
450            # since we're going away
451    
452      def CreateDock(self, name, id, title, align):      def CreateDock(self, name, id, title, align):
453    
454          if align in (wxLAYOUT_NONE, wxLAYOUT_LEFT, wxLAYOUT_RIGHT):          if align in (wxLAYOUT_NONE, wxLAYOUT_LEFT, wxLAYOUT_RIGHT):
# Line 399  class DockFrame(wxFrame): Line 473  class DockFrame(wxFrame):
473      def FindRegisteredDock(self, name):      def FindRegisteredDock(self, name):
474          return self.openWindows.get(name)          return self.openWindows.get(name)
475    
476      def OnDockClose(self, win):      def OnDockDestroy(self, win):
477          del self.openWindows[win.GetName()]          del self.openWindows[win.GetName()]
478          self._UpdateDocks()          self._UpdateDocks()
479    
# Line 409  class DockFrame(wxFrame): Line 483  class DockFrame(wxFrame):
483                    
484      def _UpdateDocks(self):      def _UpdateDocks(self):
485          #print "_UpdateDocks()"          #print "_UpdateDocks()"
486          wxLayoutAlgorithm().LayoutWindow(self, self.__mainWindow)          if self.__update_lock == 0:
487                wxLayoutAlgorithm().LayoutWindow(self, self.__mainWindow)
488    
489      def _OnSashDragged(self, event):      def _OnSashDragged(self, event):
490          if event.GetDragStatus() == wxSASH_STATUS_OUT_OF_RANGE:          if event.GetDragStatus() == wxSASH_STATUS_OUT_OF_RANGE:
# Line 422  class DockFrame(wxFrame): Line 497  class DockFrame(wxFrame):
497          #print dockPanel          #print dockPanel
498          panel = dockPanel.FindWindowById(PANEL_ID)          panel = dockPanel.FindWindowById(PANEL_ID)
499          #print panel          #print panel
500          assert(isinstance(panel, DockPanel))          assert isinstance(panel, DockPanel)
501          win = panel.GetDockParent()          win = panel.GetDockParent()
502          #print win          #print win
503          assert(isinstance(win, DockableWindow))          assert isinstance(win, DockableWindow)
504    
505          assert(win.IsDocked())          assert win.IsDocked()
506    
507          rect = event.GetDragRect()          rect = event.GetDragRect()
508    

Legend:
Removed from v.571  
changed lines
  Added in v.651

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26