]> git.saurik.com Git - wxWidgets.git/blobdiff - utils/wxPython/lib/floatbar.py
it is now possible to add custom buttons into wxHtmlHelpFrame's toolbar
[wxWidgets.git] / utils / wxPython / lib / floatbar.py
index fefca18e5985fcb7fc4a99fbde025bc71c4dc17a..c5a83d0b9a263f738bb1220a5389da074583568b 100644 (file)
@@ -8,6 +8,8 @@
 #----------------------------------------------------------------------------
 from wxPython.wx import *
 
+_DOCKTHRESHOLD = 25
+
 class wxFloatBar(wxToolBar):
     """
     wxToolBar subclass which can be dragged off its frame and later
@@ -16,6 +18,7 @@ class wxFloatBar(wxToolBar):
     position. Programmatically, call SetFloatable(true) and then
     Float(true) to float, Float(false) to dock.
     """
+
     def __init__(self,*_args,**_kwargs):
         """
         In addition to the usual arguments, wxFloatBar accepts keyword
@@ -38,134 +41,182 @@ class wxFloatBar(wxToolBar):
             self.title = ""
         EVT_MOUSE_EVENTS(self, self.OnMouse)
         self.parentframe = wxPyTypeCast(args[1], 'wxFrame')
+
+
     def IsFloatable(self):
         return self.floatable
+
+
     def SetFloatable(self, float):
         self.floatable = float
         #Find the size of a title bar.
         if not hasattr(self, 'titleheight'):
-            test = wxFrame(NULL, -1, "TEST")
+            test = wxMiniFrame(NULL, -1, "TEST")
             test.SetClientSize(wxSize(0,0))
             self.titleheight = test.GetSizeTuple()[1]
             test.Destroy()
+
+
     def IsFloating(self):
         return self.floating
+
+
     def Realize(self):
         wxToolBar.Realize(self)
-        self.barheight = -1
+
+
     def GetTitle(self):
         return self.title
+
+
     def SetTitle(self, title):
+        print 'SetTitle', title
         self.title = title
         if self.IsFloating():
             self.floatframe.SetTitle(self.title)
-    def GetHome(self):
-        """
-        Returns the frame which this toolbar will return to when
-        docked, or the parent if currently docked.
-        """
-        if hasattr(self, 'parentframe'):
-            return self.parentframe
-        else:
-            return wxPyTypeCast(self.GetParent(), 'wxFrame')
-    def SetHome(self, frame):
-        """
-        Called when docked, this will remove the toolbar from its
-        current frame and attach it to another.  If called when
-        floating, it will dock to the frame specified when the toolbar
-        window is closed.
-        """
-        if self.IsFloating():
-            self.parentframe = frame
-            self.floatframe.Reparent(frame)
-        else:
-            parent = wxPyTypeCast(self.GetParent(), 'wxFrame')
-            self.Reparent(frame)
-            parent.SetToolBar(None)
-            size = parent.GetSize()
-            parent.SetSize(wxSize(0,0))
-            parent.SetSize(size)
-            frame.SetToolBar(self)
-            size = frame.GetSize()
-            frame.SetSize(wxSize(0,0))
-            frame.SetSize(size)
+
+
+##     def GetHome(self):
+##         """
+##         Returns the frame which this toolbar will return to when
+##         docked, or the parent if currently docked.
+##         """
+##         if hasattr(self, 'parentframe'):
+##             return self.parentframe
+##         else:
+##             return wxPyTypeCast(self.GetParent(), 'wxFrame')
+
+
+##     def SetHome(self, frame):
+##         """
+##         Called when docked, this will remove the toolbar from its
+##         current frame and attach it to another.  If called when
+##         floating, it will dock to the frame specified when the toolbar
+##         window is closed.
+##         """
+##         if self.IsFloating():
+##             self.parentframe = frame
+##             self.floatframe.Reparent(frame)
+##         else:
+##             parent = wxPyTypeCast(self.GetParent(), 'wxFrame')
+##             self.Reparent(frame)
+##             parent.SetToolBar(None)
+##             size = parent.GetSize()
+##             parent.SetSize(wxSize(0,0))
+##             parent.SetSize(size)
+##             frame.SetToolBar(self)
+##             size = frame.GetSize()
+##             frame.SetSize(wxSize(0,0))
+##             frame.SetSize(size)
+
+
     def Float(self, bool):
         "Floats or docks the toolbar programmatically."
         if bool:
             self.parentframe = wxPyTypeCast(self.GetParent(), 'wxFrame')
-            clientsize = self.parentframe.GetClientSizeTuple()
-            self.floatframe = wxMiniFrame(self.parentframe, -1, self.title, wxDefaultPosition, wxDefaultSize, wxTHICK_FRAME)
+            print self.title
+            if self.title:
+                useStyle = wxDEFAULT_FRAME_STYLE
+            else:
+                useStyle = wxTHICK_FRAME
+            self.floatframe = wxFrame(self.parentframe, -1, self.title,
+                                          style = useStyle)
+
             self.Reparent(self.floatframe)
             self.parentframe.SetToolBar(None)
             self.floating = 1
-            size = self.parentframe.GetSize()
+            psize = self.parentframe.GetSize()
             self.parentframe.SetSize(wxSize(0,0))
-            self.parentframe.SetSize(size)
+            self.parentframe.SetSize(psize)
             self.floatframe.SetToolBar(self)
             self.oldcolor = self.GetBackgroundColour()
-            barsize = self.GetSizeTuple()
-            self.floatframe.SetSize(wxSize(barsize[0], barsize[1] + self.titleheight))
-            self.floatframe.SetClientSize(wxSize(barsize[0], barsize[1]))
+
+            w = psize.width
+            h = self.GetSize().height
+            if self.title:
+                h = h + self.titleheight
+            self.floatframe.SetSize(wxSize(w,h))
+            self.floatframe.SetClientSize(self.GetSize())
             newpos = self.parentframe.GetPosition()
-            newpos.y = newpos.y + self.titleheight
+            newpos.y = newpos.y + _DOCKTHRESHOLD * 2
             self.floatframe.SetPosition(newpos)
             self.floatframe.Show(true)
+
             EVT_CLOSE(self.floatframe, self.OnDock)
-#            EVT_MOVE(self.floatframe, self.OnMove)
+            #EVT_MOVE(self.floatframe, self.OnMove)
+
         else:
             self.Reparent(self.parentframe)
             self.parentframe.SetToolBar(self)
             self.floating = 0
+            self.floatframe.SetToolBar(None)
             self.floatframe.Destroy()
             size = self.parentframe.GetSize()
             self.parentframe.SetSize(wxSize(0,0))
             self.parentframe.SetSize(size)
             self.SetBackgroundColour(self.oldcolor)
+
+
     def OnDock(self, e):
         self.Float(0)
         if hasattr(self, 'oldpos'):
             del self.oldpos
 
+
     def OnMove(self, e):
-        homepos = self.parentframe.GetPositionTuple()
-        homepos = homepos[0], homepos[1] + self.titleheight
-        floatpos = self.floatframe.GetPositionTuple()
-        if abs(homepos[0]-floatpos[0]) < 35 and abs(homepos[1]-floatpos[1]) < 35:
-            self._SetFauxBarVisible(true)
-        else:
-            self._SetFauxBarVisible(false)
+        homepos = self.parentframe.ClientToScreen(wxPoint(0,0))
+        floatpos = self.floatframe.GetPosition()
+        if (abs(homepos.x - floatpos.x) < _DOCKTHRESHOLD and
+            abs(homepos.y - floatpos.y) < _DOCKTHRESHOLD):
+            self.Float(0)
+        #homepos = self.parentframe.GetPositionTuple()
+        #homepos = homepos[0], homepos[1] + self.titleheight
+        #floatpos = self.floatframe.GetPositionTuple()
+        #if abs(homepos[0] - floatpos[0]) < 35 and abs(homepos[1] - floatpos[1]) < 35:
+        #    self._SetFauxBarVisible(true)
+        #else:
+        #    self._SetFauxBarVisible(false)
+
 
     def OnMouse(self, e):
         if not self.IsFloatable():
             e.Skip()
             return
-        if e.ButtonDown() or e.ButtonUp() or e.ButtonDClick(1) or e.ButtonDClick(2) or e.ButtonDClick(3):
+
+        if e.ButtonDClick(1) or e.ButtonDClick(2) or e.ButtonDClick(3) or e.ButtonDown() or e.ButtonUp():
             e.Skip()
+
         if e.ButtonDown():
+            self.CaptureMouse()
             self.oldpos = (e.GetX(), e.GetY())
+
         if e.Entering():
             self.oldpos = (e.GetX(), e.GetY())
+
         if e.ButtonUp():
+            self.ReleaseMouse()
             if self.IsFloating():
-                homepos = self.parentframe.GetPositionTuple()
-                homepos = homepos[0], homepos[1] + self.titleheight
-                floatpos = self.floatframe.GetPositionTuple()
-                if abs(homepos[0]-floatpos[0]) < 25 and abs(homepos[1]-floatpos[1]) < 25:
+                homepos = self.parentframe.ClientToScreen(wxPoint(0,0))
+                floatpos = self.floatframe.GetPosition()
+                if (abs(homepos.x - floatpos.x) < _DOCKTHRESHOLD and
+                    abs(homepos.y - floatpos.y) < _DOCKTHRESHOLD):
                     self.Float(0)
                     return
-        if self.IsFloatable():
-            if e.Dragging():
-                if not self.IsFloating():
-                    self.Float(true)
-                    self.oldpos = (e.GetX(), e.GetY())
-                else:
-                    if hasattr(self, 'oldpos'):
-                        loc = self.floatframe.GetPosition()
-                        pt = wxPoint(loc.x - (self.oldpos[0]-e.GetX()), loc.y - (self.oldpos[1]-e.GetY()))
-                        self.floatframe.SetPosition(pt)
+
+        if e.Dragging():
+            if not self.IsFloating():
+                self.Float(true)
+                self.oldpos = (e.GetX(), e.GetY())
+            else:
+                if hasattr(self, 'oldpos'):
+                    loc = self.floatframe.GetPosition()
+                    pt = wxPoint(loc.x - (self.oldpos[0]-e.GetX()), loc.y - (self.oldpos[1]-e.GetY()))
+                    self.floatframe.Move(pt)
+
+
 
     def _SetFauxBarVisible(self, vis):
-#        return
+        return
         if vis:
             if self.parentframe.GetToolBar() == None:
                 if not hasattr(self, 'nullbar'):