]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/lib/floatbar.py
1 #----------------------------------------------------------------------------
3 # Purpose: Contains floating toolbar class
8 #----------------------------------------------------------------------------
9 # 12/02/2003 - Jeff Grimmett (grimmtooth@softhome.net)
11 # o 2.5 Compatability changes
13 # 12/07/2003 - Jeff Grimmett (grimmtooth@softhome.net)
15 # o Added deprecation warning.
17 # 12/18/2003 - Jeff Grimmett (grimmtooth@softhome.net)
19 # o wxFloatBar -> FloatBar
23 NOTE: This module is *not* supported in any way. Use it however you
24 wish, but be warned that dealing with any consequences is
34 ################################################\
35 # This module is not supported in any way! |
37 # See cource code for wx.lib.floatbar for more |
39 ################################################/
43 warnings
.warn(warningmsg
, DeprecationWarning, stacklevel
=2)
45 if wx
.Platform
== '__WXGTK__':
47 # For wxGTK all we have to do is set the wxTB_DOCKABLE flag
49 class FloatBar(wx
.ToolBar
):
50 def __init__(self
, parent
, ID
,
51 pos
= wx
.DefaultPosition
,
52 size
= wx
.DefaultSize
,
55 wx
.ToolBar
.__init
__(self
, parent
, ID
, pos
, size
,
56 style|wx
.TB_DOCKABLE
, name
)
58 # these other methods just become no-ops
59 def SetFloatable(self
, float):
69 def SetTitle(self
, title
):
75 class FloatBar(wx
.ToolBar
):
77 wxToolBar subclass which can be dragged off its frame and later
78 replaced there. Drag on the toolbar to release it, close it like
79 a normal window to make it return to its original
80 position. Programmatically, call SetFloatable(True) and then
81 Float(True) to float, Float(False) to dock.
84 def __init__(self
,*_args
,**_kwargs
):
86 In addition to the usual arguments, wxFloatBar accepts keyword
87 args of: title(string): the title that should appear on the
88 toolbar's frame when it is floating. floatable(bool): whether
89 user actions (i.e., dragging) can float the toolbar or not.
91 args
= (self
,) + _args
92 apply(wx
.ToolBar
.__init
__, args
, _kwargs
)
93 if _kwargs
.has_key('floatable'):
94 self
.floatable
= _kwargs
['floatable']
95 assert type(self
.floatable
) == type(0)
99 if _kwargs
.has_key('title'):
100 self
.title
= _kwargs
['title']
101 assert type(self
.title
) == type("")
104 self
.Bind(wx
.EVT_MOUSE_EVENTS
, self
.OnMouse
)
105 self
.parentframe
= args
[1]
108 def IsFloatable(self
):
109 return self
.floatable
112 def SetFloatable(self
, float):
113 self
.floatable
= float
114 #Find the size of a title bar.
115 if not hasattr(self
, 'titleheight'):
116 test
= wx
.MiniFrame(None, -1, "TEST")
117 test
.SetClientSize((0,0))
118 self
.titleheight
= test
.GetSize()[1]
122 def IsFloating(self
):
127 wx
.ToolBar
.Realize(self
)
134 def SetTitle(self
, title
):
135 print 'SetTitle', title
137 if self
.IsFloating():
138 self
.floatframe
.SetTitle(self
.title
)
141 ## def GetHome(self):
143 ## Returns the frame which this toolbar will return to when
144 ## docked, or the parent if currently docked.
146 ## if hasattr(self, 'parentframe'):
147 ## return self.parentframe
149 ## return (self.GetParent())
152 ## def SetHome(self, frame):
154 ## Called when docked, this will remove the toolbar from its
155 ## current frame and attach it to another. If called when
156 ## floating, it will dock to the frame specified when the toolbar
159 ## if self.IsFloating():
160 ## self.parentframe = frame
161 ## self.floatframe.Reparent(frame)
163 ## parent = self.GetParent()
164 ## self.Reparent(frame)
165 ## parent.SetToolBar(None)
166 ## size = parent.GetSize()
167 ## parent.SetSize(wxSize(0,0))
168 ## parent.SetSize(size)
169 ## frame.SetToolBar(self)
170 ## size = frame.GetSize()
171 ## frame.SetSize(wxSize(0,0))
172 ## frame.SetSize(size)
175 def Float(self
, bool):
176 "Floats or docks the toolbar programmatically."
178 self
.parentframe
= self
.GetParent()
181 useStyle
= wx
.DEFAULT_FRAME_STYLE
183 useStyle
= wx
.THICK_FRAME
184 self
.floatframe
= wx
.MiniFrame(self
.parentframe
, -1, self
.title
,
187 self
.Reparent(self
.floatframe
)
188 self
.parentframe
.SetToolBar(None)
190 psize
= self
.parentframe
.GetSize()
191 self
.parentframe
.SetSize((0,0))
192 self
.parentframe
.SetSize(psize
)
193 self
.floatframe
.SetToolBar(self
)
194 self
.oldcolor
= self
.GetBackgroundColour()
197 h
= self
.GetSize()[1]
199 h
= h
+ self
.titleheight
200 self
.floatframe
.SetSize((w
,h
))
201 self
.floatframe
.SetClientSize(self
.GetSize())
202 newpos
= self
.parentframe
.GetPosition()
203 newpos
.y
= newpos
.y
+ _DOCKTHRESHOLD
* 2
204 self
.floatframe
.SetPosition(newpos
)
205 self
.floatframe
.Show(True)
207 self
.floatframe
.Bind(wx
.EVT_CLOSE
, self
.OnDock
)
208 #self.floatframe.Bind(wx.EVT_MOVE, self.OnMove)
211 self
.Reparent(self
.parentframe
)
212 self
.parentframe
.SetToolBar(self
)
214 self
.floatframe
.SetToolBar(None)
215 self
.floatframe
.Destroy()
216 size
= self
.parentframe
.GetSize()
217 self
.parentframe
.SetSize((0,0))
218 self
.parentframe
.SetSize(size
)
219 self
.SetBackgroundColour(self
.oldcolor
)
224 if hasattr(self
, 'oldpos'):
229 homepos
= self
.parentframe
.ClientToScreen((0,0))
230 floatpos
= self
.floatframe
.GetPosition()
231 if (abs(homepos
.x
- floatpos
.x
) < _DOCKTHRESHOLD
and
232 abs(homepos
.y
- floatpos
.y
) < _DOCKTHRESHOLD
):
234 #homepos = self.parentframe.GetPositionTuple()
235 #homepos = homepos[0], homepos[1] + self.titleheight
236 #floatpos = self.floatframe.GetPositionTuple()
237 #if abs(homepos[0] - floatpos[0]) < 35 and abs(homepos[1] - floatpos[1]) < 35:
238 # self._SetFauxBarVisible(True)
240 # self._SetFauxBarVisible(False)
243 def OnMouse(self
, e
):
244 if not self
.IsFloatable():
248 if e
.ButtonDClick(1) or e
.ButtonDClick(2) or e
.ButtonDClick(3) or e
.ButtonDown() or e
.ButtonUp():
253 self
.oldpos
= (e
.GetX(), e
.GetY())
256 self
.oldpos
= (e
.GetX(), e
.GetY())
260 if self
.IsFloating():
261 homepos
= self
.parentframe
.ClientToScreen((0,0))
262 floatpos
= self
.floatframe
.GetPosition()
263 if (abs(homepos
.x
- floatpos
.x
) < _DOCKTHRESHOLD
and
264 abs(homepos
.y
- floatpos
.y
) < _DOCKTHRESHOLD
):
269 if not self
.IsFloating():
271 self
.oldpos
= (e
.GetX(), e
.GetY())
273 if hasattr(self
, 'oldpos'):
274 loc
= self
.floatframe
.GetPosition()
275 pt
= (loc
.x
- (self
.oldpos
[0]-e
.GetX()), loc
.y
- (self
.oldpos
[1]-e
.GetY()))
276 self
.floatframe
.Move(pt
)
280 def _SetFauxBarVisible(self
, vis
):
283 if self
.parentframe
.GetToolBar() == None:
284 if not hasattr(self
, 'nullbar'):
285 self
.nullbar
= wx
.ToolBar(self
.parentframe
, -1)
286 print "Adding fauxbar."
287 self
.nullbar
.Reparent(self
.parentframe
)
289 self
.parentframe
.SetToolBar(self
.nullbar
)
291 col
= wx
.NamedColour("GREY")
292 self
.nullbar
.SetBackgroundColour(col
)
294 size
= self
.parentframe
.GetSize()
295 self
.parentframe
.SetSize((0,0))
296 self
.parentframe
.SetSize(size
)
299 print self
.parentframe
.GetToolBar()
301 if self
.parentframe
.GetToolBar() != None:
302 print "Removing fauxbar"
303 self
.nullbar
.Reparent(self
.floatframe
)
304 self
.parentframe
.SetToolBar(None)
305 size
= self
.parentframe
.GetSize()
306 self
.parentframe
.SetSize((0,0))
307 self
.parentframe
.SetSize(size
)