/[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 657 by jonathan, Fri Apr 11 18:29:57 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    
# Line 197  class DockableWindow(Publisher): Line 211  class DockableWindow(Publisher):
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    
218      def IsDocked(self):      def IsDocked(self):
# Line 213  class DockableWindow(Publisher): Line 229  class DockableWindow(Publisher):
229    
230      def SetDockSize(self, rect = None):      def SetDockSize(self, rect = None):
231    
232            print "---------------"
233          #          #
234          # adjust the size to get the          # adjust the size to get the
235          w0, h0 = self.__dockPanel.GetBestSize()          w0, h0 = self.__dockPanel.GetBestSize()
236            print w0, h0
237          w, h = self.__panel.GetBestSize()          w, h = self.__panel.GetBestSize()
238            print w, h
239            #w0, h0 = self.__dockPanel.GetBestSize()
240            #w0 = h0 = 0
241            #w, h = self.__dockPanel.GetBestSize()
242    
243          #print (w0, h0), (w, h)          #print (w0, h0), (w, h)
244    
# Line 238  class DockableWindow(Publisher): Line 260  class DockableWindow(Publisher):
260          rw += 8 # XXX: without this the sash isn't visible!?!?!?!          rw += 8 # XXX: without this the sash isn't visible!?!?!?!
261          rh += 8 # XXX: without this the sash isn't visible!?!?!?!          rh += 8 # XXX: without this the sash isn't visible!?!?!?!
262                                                                                                                                                                                
263            print rw, rh
264    
265          self.__dockWindow.SetDefaultSize(wxSize(rw, rh))          self.__dockWindow.SetDefaultSize(wxSize(rw, rh))
266    
267    
# Line 245  class DockableWindow(Publisher): Line 269  class DockableWindow(Publisher):
269          self.__panel.Destroy()          self.__panel.Destroy()
270          self.__floatWindow.Destroy()          self.__floatWindow.Destroy()
271          self.__dockWindow.Destroy()          self.__dockWindow.Destroy()
272          self.__parent.OnDockClose(self)          self.__parent.OnDockDestroy(self)
273                    
274      ##      ##
275      # Event handlers      # Event handlers
276      #      #
277    
278      def _OnButtonClose(self, event):      def _OnButtonClose(self, event):
279          self.Close()          #self.Close()
280            self.Show(False)
281    
282      def _OnClose(self, force = False):      def _OnClose(self, force = False):
283          self.Destroy()          self.Show(False)
284    
285      def _OnToggleDock(self, event):      def _OnToggleDock(self, event):
286          self.__CheckAllGood()          self.__CheckAllGood()
# Line 298  class DockableWindow(Publisher): Line 323  class DockableWindow(Publisher):
323          self.__dockPanel = wxPanel(self.__topWindow, -1, style=wxSUNKEN_BORDER)          self.__dockPanel = wxPanel(self.__topWindow, -1, style=wxSUNKEN_BORDER)
324          #self.__dockPanel.SetBackgroundColour(wxColour(255, 0, 0))          #self.__dockPanel.SetBackgroundColour(wxColour(255, 0, 0))
325    
326            self.__panel.Reparent(self.__dockPanel)
327            self.__panel.SetId(PANEL_ID)
328    
329          if self.__orientation == wxLAYOUT_VERTICAL:          if self.__orientation == wxLAYOUT_VERTICAL:
330              sizer = wxBoxSizer(wxVERTICAL)              sizer = wxBoxSizer(wxVERTICAL)
331              headerBoxOrient = wxHORIZONTAL              headerBoxOrient = wxHORIZONTAL
# Line 309  class DockableWindow(Publisher): Line 337  class DockableWindow(Publisher):
337          headerBox = wxStaticBoxSizer(          headerBox = wxStaticBoxSizer(
338                          wxStaticBox(self.__dockPanel, -1, ""), headerBoxOrient)                          wxStaticBox(self.__dockPanel, -1, ""), headerBoxOrient)
339    
340          buttonBox = wxBoxSizer(wxHORIZONTAL)          #buttonBox = wxBoxSizer(wxHORIZONTAL)
341    
342          #          #
343          # ideally, we should be able to rotate this text depending on          # ideally, we should be able to rotate this text depending on
344          # our orientation          # our orientation
345          #          #
346          text = wxStaticText(self.__dockPanel, -1, self.GetTitle(),          text = wxStaticText(self.__dockPanel, -1, self.GetTitle(),
347                               style = wxSIMPLE_BORDER | wxALIGN_CENTRE)                               style = wxALIGN_CENTRE)
348    
349            font = text.GetFont()
350            font.SetPointSize(10)
351            text.SetFont(font)
352    
353          #          #
354          # Perhaps using wxToggleButton would be better, but it's only          # Perhaps using wxToggleButton would be better, but it's only
355          # supported under wxMSW and wxGTK as of v2.4.0.3          # supported under wxMSW and wxGTK as of v2.4.0.3
356          #          #
357          self.__dockButton = wxButton(self.__dockPanel, ID_BUTTON_DOCK, "WWWWWW",          self.__bmpDock   = \
358                                       style = wxBU_EXACTFIT | wxADJUST_MINSIZE)              resource.GetBitmapResource(DOCK_BMP, wxBITMAP_TYPE_XPM)
359            self.__bmpUnDock = \
360                resource.GetBitmapResource(UNDOCK_BMP, wxBITMAP_TYPE_XPM)
361    
362            if self.__bmpDock is not None \
363                and self.__bmpUnDock is not None:
364                self.__dockButton = wxBitmapButton(
365                    self.__dockPanel, ID_BUTTON_DOCK,
366                    self.__bmpUnDock,
367                    size = wxSize(self.__bmpDock.GetWidth() + 4,
368                                  self.__bmpDock.GetHeight() + 4),
369                    style = wxBU_EXACTFIT | wxADJUST_MINSIZE)
370            else:
371                self.__bmpDock = \
372                self.__bmpUnDock = None
373    
374                self.__dockButton = wxButton(
375                    self.__dockPanel, ID_BUTTON_DOCK,
376                    "WW", style = wxBU_EXACTFIT | wxADJUST_MINSIZE)
377    
378            bmp = resource.GetBitmapResource(CLOSE_BMP, wxBITMAP_TYPE_XPM)
379    
380          closeX = wxButton(self.__dockPanel, ID_BUTTON_CLOSE, "X",          closeX = wxBitmapButton(self.__dockPanel, ID_BUTTON_CLOSE, bmp,
381                           style = wxBU_EXACTFIT | wxADJUST_MINSIZE)                            size = wxSize(bmp.GetWidth() + 4,
382                                            bmp.GetHeight() + 4),
383                              style = wxBU_EXACTFIT | wxADJUST_MINSIZE)
384            closeX.SetToolTip(wxToolTip(_("Close")))
385    
386          buttonBox.Add(self.__dockButton, 0, wxALIGN_RIGHT, 0)  
387          buttonBox.Add(closeX, 0, wxALIGN_RIGHT, 0)          #closeX = wxButton(self.__dockPanel, ID_BUTTON_CLOSE, "X",
388                             #style = wxBU_EXACTFIT | wxADJUST_MINSIZE)
389    
390            #buttonBox.Add(self.__dockButton, 0, wxALIGN_RIGHT, 0)
391            #buttonBox.Add(closeX, 0, wxALIGN_RIGHT, 0)
392    
393          if self.__orientation == wxLAYOUT_VERTICAL:          if self.__orientation == wxLAYOUT_VERTICAL:
394              headerBox.Add(text, 0, wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL, 0)              headerBox.Add(text, 0, wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL, 0)
395              headerBox.Add(1, 20, 1, wxGROW)              headerBox.Add(1, 5, 1, wxGROW)
396              headerBox.Add(buttonBox, 0, wxGROW | wxALIGN_RIGHT, 0)              headerBox.Add(self.__dockButton, 0, wxALIGN_RIGHT, 0)
397                headerBox.Add(closeX, 0, wxALIGN_RIGHT | wxLEFT, 4)
398          else:          else:
399              headerBox.Add(buttonBox, 0, wxGROW, 0)              headerBox.Add(closeX, 0, wxALIGN_RIGHT | wxBOTTOM, 4)
400                headerBox.Add(self.__dockButton, 0, wxALIGN_RIGHT, 0)
401              headerBox.Add(text, 0, wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL, 0)              headerBox.Add(text, 0, wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL, 0)
402    
403          sizer.Add(headerBox, 0, wxGROW, 0)          sizer.Add(headerBox, 0, wxGROW, 0)
404    
         self.__panel.Reparent(self.__dockPanel)  
         self.__panel.SetId(PANEL_ID)  
405    
406          sizer.Add(self.__panel, 1, wxGROW, 0)          sizer.Add(self.__panel, 1, wxGROW, 0)
407    
408          sizer.Fit(self.__dockPanel)          #sizer.Fit(self.__dockPanel)
409    
410          self.__dockPanel.SetSizer(sizer)          self.__panel.SetAutoLayout(True)
411          self.__dockPanel.SetAutoLayout(True)          sizer.SetSizeHints(self.__panel)
412    
413          sizer.SetSizeHints(self.__dockPanel)          self.__dockPanel.SetSizerAndFit(sizer)
414            #self.__dockPanel.SetAutoLayout(True)
415            #sizer.SetSizeHints(self.__dockPanel)
416    
417          EVT_BUTTON(self.__dockPanel, ID_BUTTON_DOCK, self._OnToggleDock)          EVT_BUTTON(self.__dockPanel, ID_BUTTON_DOCK, self._OnToggleDock)
418          EVT_BUTTON(self.__dockPanel, ID_BUTTON_CLOSE, self._OnButtonClose)          EVT_BUTTON(self.__dockPanel, ID_BUTTON_CLOSE, self._OnButtonClose)
# Line 422  class DockFrame(wxFrame): Line 483  class DockFrame(wxFrame):
483      def FindRegisteredDock(self, name):      def FindRegisteredDock(self, name):
484          return self.openWindows.get(name)          return self.openWindows.get(name)
485    
486      def OnDockClose(self, win):      def OnDockDestroy(self, win):
487          del self.openWindows[win.GetName()]          del self.openWindows[win.GetName()]
488          self._UpdateDocks()          self._UpdateDocks()
489    
# Line 446  class DockFrame(wxFrame): Line 507  class DockFrame(wxFrame):
507          #print dockPanel          #print dockPanel
508          panel = dockPanel.FindWindowById(PANEL_ID)          panel = dockPanel.FindWindowById(PANEL_ID)
509          #print panel          #print panel
510          assert(isinstance(panel, DockPanel))          assert isinstance(panel, DockPanel)
511          win = panel.GetDockParent()          win = panel.GetDockParent()
512          #print win          #print win
513          assert(isinstance(win, DockableWindow))          assert isinstance(win, DockableWindow)
514    
515          assert(win.IsDocked())          assert win.IsDocked()
516    
517          rect = event.GetDragRect()          rect = event.GetDragRect()
518    

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26