]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/lib/floatbar.py
1 #----------------------------------------------------------------------------
3 # Purpose: Contains floating toolbar class
8 #----------------------------------------------------------------------------
10 NOTE: This module is *not* supported in any way. Use it however you
11 wish, but be warned that dealing with any consequences is
16 from wxPython
.wx
import *
18 if wxPlatform
== '__WXGTK__':
20 # For wxGTK all we have to do is set the wxTB_DOCKABLE flag
22 class wxFloatBar(wxToolBar
):
23 def __init__(self
, parent
, ID
,
24 pos
= wxDefaultPosition
,
28 wxToolBar
.__init
__(self
, parent
, ID
, pos
, size
,
29 style|wxTB_DOCKABLE
, name
)
31 # these other methods just become no-ops
32 def SetFloatable(self
, float):
42 def SetTitle(self
, title
):
48 class wxFloatBar(wxToolBar
):
50 wxToolBar subclass which can be dragged off its frame and later
51 replaced there. Drag on the toolbar to release it, close it like
52 a normal window to make it return to its original
53 position. Programmatically, call SetFloatable(True) and then
54 Float(True) to float, Float(False) to dock.
57 def __init__(self
,*_args
,**_kwargs
):
59 In addition to the usual arguments, wxFloatBar accepts keyword
60 args of: title(string): the title that should appear on the
61 toolbar's frame when it is floating. floatable(bool): whether
62 user actions (i.e., dragging) can float the toolbar or not.
64 args
= (self
,) + _args
65 apply(wxToolBar
.__init
__, args
, _kwargs
)
66 if _kwargs
.has_key('floatable'):
67 self
.floatable
= _kwargs
['floatable']
68 assert type(self
.floatable
) == type(0)
72 if _kwargs
.has_key('title'):
73 self
.title
= _kwargs
['title']
74 assert type(self
.title
) == type("")
77 EVT_MOUSE_EVENTS(self
, self
.OnMouse
)
78 self
.parentframe
= wxPyTypeCast(args
[1], 'wxFrame')
81 def IsFloatable(self
):
85 def SetFloatable(self
, float):
86 self
.floatable
= float
87 #Find the size of a title bar.
88 if not hasattr(self
, 'titleheight'):
89 test
= wxMiniFrame(NULL
, -1, "TEST")
90 test
.SetClientSize(wxSize(0,0))
91 self
.titleheight
= test
.GetSizeTuple()[1]
100 wxToolBar
.Realize(self
)
107 def SetTitle(self
, title
):
108 print 'SetTitle', title
110 if self
.IsFloating():
111 self
.floatframe
.SetTitle(self
.title
)
114 ## def GetHome(self):
116 ## Returns the frame which this toolbar will return to when
117 ## docked, or the parent if currently docked.
119 ## if hasattr(self, 'parentframe'):
120 ## return self.parentframe
122 ## return wxPyTypeCast(self.GetParent(), 'wxFrame')
125 ## def SetHome(self, frame):
127 ## Called when docked, this will remove the toolbar from its
128 ## current frame and attach it to another. If called when
129 ## floating, it will dock to the frame specified when the toolbar
132 ## if self.IsFloating():
133 ## self.parentframe = frame
134 ## self.floatframe.Reparent(frame)
136 ## parent = wxPyTypeCast(self.GetParent(), 'wxFrame')
137 ## self.Reparent(frame)
138 ## parent.SetToolBar(None)
139 ## size = parent.GetSize()
140 ## parent.SetSize(wxSize(0,0))
141 ## parent.SetSize(size)
142 ## frame.SetToolBar(self)
143 ## size = frame.GetSize()
144 ## frame.SetSize(wxSize(0,0))
145 ## frame.SetSize(size)
148 def Float(self
, bool):
149 "Floats or docks the toolbar programmatically."
151 self
.parentframe
= wxPyTypeCast(self
.GetParent(), 'wxFrame')
154 useStyle
= wxDEFAULT_FRAME_STYLE
156 useStyle
= wxTHICK_FRAME
157 self
.floatframe
= wxMiniFrame(self
.parentframe
, -1, self
.title
,
160 self
.Reparent(self
.floatframe
)
161 self
.parentframe
.SetToolBar(None)
163 psize
= self
.parentframe
.GetSize()
164 self
.parentframe
.SetSize(wxSize(0,0))
165 self
.parentframe
.SetSize(psize
)
166 self
.floatframe
.SetToolBar(self
)
167 self
.oldcolor
= self
.GetBackgroundColour()
170 h
= self
.GetSize().height
172 h
= h
+ self
.titleheight
173 self
.floatframe
.SetSize(wxSize(w
,h
))
174 self
.floatframe
.SetClientSize(self
.GetSize())
175 newpos
= self
.parentframe
.GetPosition()
176 newpos
.y
= newpos
.y
+ _DOCKTHRESHOLD
* 2
177 self
.floatframe
.SetPosition(newpos
)
178 self
.floatframe
.Show(True)
180 EVT_CLOSE(self
.floatframe
, self
.OnDock
)
181 #EVT_MOVE(self.floatframe, self.OnMove)
184 self
.Reparent(self
.parentframe
)
185 self
.parentframe
.SetToolBar(self
)
187 self
.floatframe
.SetToolBar(None)
188 self
.floatframe
.Destroy()
189 size
= self
.parentframe
.GetSize()
190 self
.parentframe
.SetSize(wxSize(0,0))
191 self
.parentframe
.SetSize(size
)
192 self
.SetBackgroundColour(self
.oldcolor
)
197 if hasattr(self
, 'oldpos'):
202 homepos
= self
.parentframe
.ClientToScreen(wxPoint(0,0))
203 floatpos
= self
.floatframe
.GetPosition()
204 if (abs(homepos
.x
- floatpos
.x
) < _DOCKTHRESHOLD
and
205 abs(homepos
.y
- floatpos
.y
) < _DOCKTHRESHOLD
):
207 #homepos = self.parentframe.GetPositionTuple()
208 #homepos = homepos[0], homepos[1] + self.titleheight
209 #floatpos = self.floatframe.GetPositionTuple()
210 #if abs(homepos[0] - floatpos[0]) < 35 and abs(homepos[1] - floatpos[1]) < 35:
211 # self._SetFauxBarVisible(True)
213 # self._SetFauxBarVisible(False)
216 def OnMouse(self
, e
):
217 if not self
.IsFloatable():
221 if e
.ButtonDClick(1) or e
.ButtonDClick(2) or e
.ButtonDClick(3) or e
.ButtonDown() or e
.ButtonUp():
226 self
.oldpos
= (e
.GetX(), e
.GetY())
229 self
.oldpos
= (e
.GetX(), e
.GetY())
233 if self
.IsFloating():
234 homepos
= self
.parentframe
.ClientToScreen(wxPoint(0,0))
235 floatpos
= self
.floatframe
.GetPosition()
236 if (abs(homepos
.x
- floatpos
.x
) < _DOCKTHRESHOLD
and
237 abs(homepos
.y
- floatpos
.y
) < _DOCKTHRESHOLD
):
242 if not self
.IsFloating():
244 self
.oldpos
= (e
.GetX(), e
.GetY())
246 if hasattr(self
, 'oldpos'):
247 loc
= self
.floatframe
.GetPosition()
248 pt
= wxPoint(loc
.x
- (self
.oldpos
[0]-e
.GetX()), loc
.y
- (self
.oldpos
[1]-e
.GetY()))
249 self
.floatframe
.Move(pt
)
253 def _SetFauxBarVisible(self
, vis
):
256 if self
.parentframe
.GetToolBar() == None:
257 if not hasattr(self
, 'nullbar'):
258 self
.nullbar
= wxToolBar(self
.parentframe
, -1)
259 print "Adding fauxbar."
260 self
.nullbar
.Reparent(self
.parentframe
)
262 self
.parentframe
.SetToolBar(self
.nullbar
)
264 col
= wxNamedColour("GREY")
265 self
.nullbar
.SetBackgroundColour(col
)
267 size
= self
.parentframe
.GetSize()
268 self
.parentframe
.SetSize(wxSize(0,0))
269 self
.parentframe
.SetSize(size
)
272 print self
.parentframe
.GetToolBar()
274 if self
.parentframe
.GetToolBar() != None:
275 print "Removing fauxbar"
276 self
.nullbar
.Reparent(self
.floatframe
)
277 self
.parentframe
.SetToolBar(None)
278 size
= self
.parentframe
.GetSize()
279 self
.parentframe
.SetSize(wxSize(0,0))
280 self
.parentframe
.SetSize(size
)