more floatbar tweaks

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4481 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
1999-11-12 06:23:28 +00:00
parent c8f1f08817
commit 8c58829804

View File

@@ -8,6 +8,8 @@
#---------------------------------------------------------------------------- #----------------------------------------------------------------------------
from wxPython.wx import * from wxPython.wx import *
_DOCKTHRESHOLD = 25
class wxFloatBar(wxToolBar): class wxFloatBar(wxToolBar):
""" """
wxToolBar subclass which can be dragged off its frame and later wxToolBar subclass which can be dragged off its frame and later
@@ -40,116 +42,139 @@ class wxFloatBar(wxToolBar):
EVT_MOUSE_EVENTS(self, self.OnMouse) EVT_MOUSE_EVENTS(self, self.OnMouse)
self.parentframe = wxPyTypeCast(args[1], 'wxFrame') self.parentframe = wxPyTypeCast(args[1], 'wxFrame')
def IsFloatable(self): def IsFloatable(self):
return self.floatable return self.floatable
def SetFloatable(self, float): def SetFloatable(self, float):
self.floatable = float self.floatable = float
#Find the size of a title bar. #Find the size of a title bar.
if not hasattr(self, 'titleheight'): if not hasattr(self, 'titleheight'):
test = wxFrame(NULL, -1, "TEST") test = wxMiniFrame(NULL, -1, "TEST")
test.SetClientSize(wxSize(0,0)) test.SetClientSize(wxSize(0,0))
self.titleheight = test.GetSizeTuple()[1] self.titleheight = test.GetSizeTuple()[1]
test.Destroy() test.Destroy()
def IsFloating(self): def IsFloating(self):
return self.floating return self.floating
def Realize(self): def Realize(self):
wxToolBar.Realize(self) wxToolBar.Realize(self)
self.barheight = -1
def GetTitle(self): def GetTitle(self):
return self.title return self.title
def SetTitle(self, title): def SetTitle(self, title):
self.title = title self.title = title
if self.IsFloating(): if self.IsFloating():
self.floatframe.SetTitle(self.title) 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): ## def GetHome(self):
""" ## """
Called when docked, this will remove the toolbar from its ## Returns the frame which this toolbar will return to when
current frame and attach it to another. If called when ## docked, or the parent if currently docked.
floating, it will dock to the frame specified when the toolbar ## """
window is closed. ## if hasattr(self, 'parentframe'):
""" ## return self.parentframe
if self.IsFloating(): ## else:
self.parentframe = frame ## return wxPyTypeCast(self.GetParent(), 'wxFrame')
self.floatframe.Reparent(frame)
else:
parent = wxPyTypeCast(self.GetParent(), 'wxFrame') ## def SetHome(self, frame):
self.Reparent(frame) ## """
parent.SetToolBar(None) ## Called when docked, this will remove the toolbar from its
size = parent.GetSize() ## current frame and attach it to another. If called when
parent.SetSize(wxSize(0,0)) ## floating, it will dock to the frame specified when the toolbar
parent.SetSize(size) ## window is closed.
frame.SetToolBar(self) ## """
size = frame.GetSize() ## if self.IsFloating():
frame.SetSize(wxSize(0,0)) ## self.parentframe = frame
frame.SetSize(size) ## 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): def Float(self, bool):
"Floats or docks the toolbar programmatically." "Floats or docks the toolbar programmatically."
if bool: if bool:
self.parentframe = wxPyTypeCast(self.GetParent(), 'wxFrame') self.parentframe = wxPyTypeCast(self.GetParent(), 'wxFrame')
clientsize = self.parentframe.GetClientSizeTuple()
if self.title: if self.title:
useStyle = wxDEFAULT_FRAME_STYLE useStyle = wxDEFAULT_FRAME_STYLE
else: else:
useStyle = 0 #wxTHICK_FRAME useStyle = 0 #wxTHICK_FRAME
self.floatframe = wxMiniFrame(self.parentframe, -1, self.title, self.floatframe = wxMiniFrame(self.parentframe, -1, self.title,
style = useStyle) style = useStyle)
self.Reparent(self.floatframe) self.Reparent(self.floatframe)
self.parentframe.SetToolBar(None) self.parentframe.SetToolBar(None)
self.floating = 1 self.floating = 1
size = self.parentframe.GetSize() psize = self.parentframe.GetSize()
self.parentframe.SetSize(wxSize(0,0)) self.parentframe.SetSize(wxSize(0,0))
self.parentframe.SetSize(size) self.parentframe.SetSize(psize)
self.floatframe.SetToolBar(self) self.floatframe.SetToolBar(self)
self.oldcolor = self.GetBackgroundColour() self.oldcolor = self.GetBackgroundColour()
barsize = self.GetSizeTuple()
self.floatframe.SetSize(wxSize(barsize[0], barsize[1] + self.titleheight)) w = psize.width
self.floatframe.SetClientSize(wxSize(barsize[0], barsize[1])) 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 = self.parentframe.GetPosition()
newpos.y = newpos.y + self.titleheight newpos.y = newpos.y + _DOCKTHRESHOLD * 2
self.floatframe.SetPosition(newpos) self.floatframe.SetPosition(newpos)
self.floatframe.Show(true) self.floatframe.Show(true)
EVT_CLOSE(self.floatframe, self.OnDock) EVT_CLOSE(self.floatframe, self.OnDock)
EVT_MOVE(self.floatframe, self.OnMove) #EVT_MOVE(self.floatframe, self.OnMove)
else: else:
self.Reparent(self.parentframe) self.Reparent(self.parentframe)
self.parentframe.SetToolBar(self) self.parentframe.SetToolBar(self)
self.floating = 0 self.floating = 0
self.floatframe.SetToolBar(None)
self.floatframe.Destroy() self.floatframe.Destroy()
size = self.parentframe.GetSize() size = self.parentframe.GetSize()
self.parentframe.SetSize(wxSize(0,0)) self.parentframe.SetSize(wxSize(0,0))
self.parentframe.SetSize(size) self.parentframe.SetSize(size)
self.SetBackgroundColour(self.oldcolor) self.SetBackgroundColour(self.oldcolor)
def OnDock(self, e): def OnDock(self, e):
self.Float(0) self.Float(0)
if hasattr(self, 'oldpos'): if hasattr(self, 'oldpos'):
del self.oldpos del self.oldpos
def OnMove(self, e): def OnMove(self, e):
homepos = self.parentframe.GetPositionTuple() homepos = self.parentframe.ClientToScreen(wxPoint(0,0))
homepos = homepos[0], homepos[1] + self.titleheight floatpos = self.floatframe.GetPosition()
floatpos = self.floatframe.GetPositionTuple() if (abs(homepos.x - floatpos.x) < _DOCKTHRESHOLD and
if abs(homepos[0] - floatpos[0]) < 35 and abs(homepos[1] - floatpos[1]) < 35: abs(homepos.y - floatpos.y) < _DOCKTHRESHOLD):
self._SetFauxBarVisible(true) self.Float(0)
else: #homepos = self.parentframe.GetPositionTuple()
self._SetFauxBarVisible(false) #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): def OnMouse(self, e):
if not self.IsFloatable(): if not self.IsFloatable():
@@ -165,10 +190,10 @@ class wxFloatBar(wxToolBar):
if e.ButtonUp(): if e.ButtonUp():
self.ReleaseMouse() self.ReleaseMouse()
if self.IsFloating(): if self.IsFloating():
homepos = self.parentframe.GetPositionTuple() homepos = self.parentframe.ClientToScreen(wxPoint(0,0))
homepos = homepos[0], homepos[1] + self.titleheight floatpos = self.floatframe.GetPosition()
floatpos = self.floatframe.GetPositionTuple() if (abs(homepos.x - floatpos.x) < _DOCKTHRESHOLD and
if abs(homepos[0]-floatpos[0]) < 25 and abs(homepos[1]-floatpos[1]) < 25: abs(homepos.y - floatpos.y) < _DOCKTHRESHOLD):
self.Float(0) self.Float(0)
return return
if self.IsFloatable(): if self.IsFloatable():
@@ -182,6 +207,7 @@ class wxFloatBar(wxToolBar):
pt = wxPoint(loc.x - (self.oldpos[0]-e.GetX()), loc.y - (self.oldpos[1]-e.GetY())) pt = wxPoint(loc.x - (self.oldpos[0]-e.GetX()), loc.y - (self.oldpos[1]-e.GetY()))
self.floatframe.SetPosition(pt) self.floatframe.SetPosition(pt)
def _SetFauxBarVisible(self, vis): def _SetFauxBarVisible(self, vis):
return return
if vis: if vis: