]>
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.
19 NOTE: This module is *not* supported in any way. Use it however you
20 wish, but be warned that dealing with any consequences is
30 ################################################\
31 # This module is not supported in any way! |
33 # See cource code for wx.lib.floatbar for more |
35 ################################################/
39 warnings
.warn(warningmsg
, DeprecationWarning, stacklevel
=2)
41 if wx
.Platform
== '__WXGTK__':
43 # For wxGTK all we have to do is set the wxTB_DOCKABLE flag
45 class wxFloatBar(wx
.ToolBar
):
46 def __init__(self
, parent
, ID
,
47 pos
= wx
.DefaultPosition
,
48 size
= wx
.DefaultSize
,
51 wx
.ToolBar
.__init
__(self
, parent
, ID
, pos
, size
,
52 style|wx
.TB_DOCKABLE
, name
)
54 # these other methods just become no-ops
55 def SetFloatable(self
, float):
65 def SetTitle(self
, title
):
71 class wxFloatBar(wx
.ToolBar
):
73 wxToolBar subclass which can be dragged off its frame and later
74 replaced there. Drag on the toolbar to release it, close it like
75 a normal window to make it return to its original
76 position. Programmatically, call SetFloatable(True) and then
77 Float(True) to float, Float(False) to dock.
80 def __init__(self
,*_args
,**_kwargs
):
82 In addition to the usual arguments, wxFloatBar accepts keyword
83 args of: title(string): the title that should appear on the
84 toolbar's frame when it is floating. floatable(bool): whether
85 user actions (i.e., dragging) can float the toolbar or not.
87 args
= (self
,) + _args
88 apply(wx
.ToolBar
.__init
__, args
, _kwargs
)
89 if _kwargs
.has_key('floatable'):
90 self
.floatable
= _kwargs
['floatable']
91 assert type(self
.floatable
) == type(0)
95 if _kwargs
.has_key('title'):
96 self
.title
= _kwargs
['title']
97 assert type(self
.title
) == type("")
100 self
.Bind(wx
.EVT_MOUSE_EVENTS
, self
.OnMouse
)
101 self
.parentframe
= args
[1]
104 def IsFloatable(self
):
105 return self
.floatable
108 def SetFloatable(self
, float):
109 self
.floatable
= float
110 #Find the size of a title bar.
111 if not hasattr(self
, 'titleheight'):
112 test
= wx
.MiniFrame(None, -1, "TEST")
113 test
.SetClientSize((0,0))
114 self
.titleheight
= test
.GetSize()[1]
118 def IsFloating(self
):
123 wx
.ToolBar
.Realize(self
)
130 def SetTitle(self
, title
):
131 print 'SetTitle', title
133 if self
.IsFloating():
134 self
.floatframe
.SetTitle(self
.title
)
137 ## def GetHome(self):
139 ## Returns the frame which this toolbar will return to when
140 ## docked, or the parent if currently docked.
142 ## if hasattr(self, 'parentframe'):
143 ## return self.parentframe
145 ## return (self.GetParent())
148 ## def SetHome(self, frame):
150 ## Called when docked, this will remove the toolbar from its
151 ## current frame and attach it to another. If called when
152 ## floating, it will dock to the frame specified when the toolbar
155 ## if self.IsFloating():
156 ## self.parentframe = frame
157 ## self.floatframe.Reparent(frame)
159 ## parent = self.GetParent()
160 ## self.Reparent(frame)
161 ## parent.SetToolBar(None)
162 ## size = parent.GetSize()
163 ## parent.SetSize(wxSize(0,0))
164 ## parent.SetSize(size)
165 ## frame.SetToolBar(self)
166 ## size = frame.GetSize()
167 ## frame.SetSize(wxSize(0,0))
168 ## frame.SetSize(size)
171 def Float(self
, bool):
172 "Floats or docks the toolbar programmatically."
174 self
.parentframe
= self
.GetParent()
177 useStyle
= wx
.DEFAULT_FRAME_STYLE
179 useStyle
= wx
.THICK_FRAME
180 self
.floatframe
= wx
.MiniFrame(self
.parentframe
, -1, self
.title
,
183 self
.Reparent(self
.floatframe
)
184 self
.parentframe
.SetToolBar(None)
186 psize
= self
.parentframe
.GetSize()
187 self
.parentframe
.SetSize((0,0))
188 self
.parentframe
.SetSize(psize
)
189 self
.floatframe
.SetToolBar(self
)
190 self
.oldcolor
= self
.GetBackgroundColour()
193 h
= self
.GetSize()[1]
195 h
= h
+ self
.titleheight
196 self
.floatframe
.SetSize((w
,h
))
197 self
.floatframe
.SetClientSize(self
.GetSize())
198 newpos
= self
.parentframe
.GetPosition()
199 newpos
.y
= newpos
.y
+ _DOCKTHRESHOLD
* 2
200 self
.floatframe
.SetPosition(newpos
)
201 self
.floatframe
.Show(True)
203 self
.floatframe
.Bind(wx
.EVT_CLOSE
, self
.OnDock
)
204 #self.floatframe.Bind(wx.EVT_MOVE, self.OnMove)
207 self
.Reparent(self
.parentframe
)
208 self
.parentframe
.SetToolBar(self
)
210 self
.floatframe
.SetToolBar(None)
211 self
.floatframe
.Destroy()
212 size
= self
.parentframe
.GetSize()
213 self
.parentframe
.SetSize((0,0))
214 self
.parentframe
.SetSize(size
)
215 self
.SetBackgroundColour(self
.oldcolor
)
220 if hasattr(self
, 'oldpos'):
225 homepos
= self
.parentframe
.ClientToScreen((0,0))
226 floatpos
= self
.floatframe
.GetPosition()
227 if (abs(homepos
.x
- floatpos
.x
) < _DOCKTHRESHOLD
and
228 abs(homepos
.y
- floatpos
.y
) < _DOCKTHRESHOLD
):
230 #homepos = self.parentframe.GetPositionTuple()
231 #homepos = homepos[0], homepos[1] + self.titleheight
232 #floatpos = self.floatframe.GetPositionTuple()
233 #if abs(homepos[0] - floatpos[0]) < 35 and abs(homepos[1] - floatpos[1]) < 35:
234 # self._SetFauxBarVisible(True)
236 # self._SetFauxBarVisible(False)
239 def OnMouse(self
, e
):
240 if not self
.IsFloatable():
244 if e
.ButtonDClick(1) or e
.ButtonDClick(2) or e
.ButtonDClick(3) or e
.ButtonDown() or e
.ButtonUp():
249 self
.oldpos
= (e
.GetX(), e
.GetY())
252 self
.oldpos
= (e
.GetX(), e
.GetY())
256 if self
.IsFloating():
257 homepos
= self
.parentframe
.ClientToScreen((0,0))
258 floatpos
= self
.floatframe
.GetPosition()
259 if (abs(homepos
.x
- floatpos
.x
) < _DOCKTHRESHOLD
and
260 abs(homepos
.y
- floatpos
.y
) < _DOCKTHRESHOLD
):
265 if not self
.IsFloating():
267 self
.oldpos
= (e
.GetX(), e
.GetY())
269 if hasattr(self
, 'oldpos'):
270 loc
= self
.floatframe
.GetPosition()
271 pt
= (loc
.x
- (self
.oldpos
[0]-e
.GetX()), loc
.y
- (self
.oldpos
[1]-e
.GetY()))
272 self
.floatframe
.Move(pt
)
276 def _SetFauxBarVisible(self
, vis
):
279 if self
.parentframe
.GetToolBar() == None:
280 if not hasattr(self
, 'nullbar'):
281 self
.nullbar
= wx
.ToolBar(self
.parentframe
, -1)
282 print "Adding fauxbar."
283 self
.nullbar
.Reparent(self
.parentframe
)
285 self
.parentframe
.SetToolBar(self
.nullbar
)
287 col
= wx
.NamedColour("GREY")
288 self
.nullbar
.SetBackgroundColour(col
)
290 size
= self
.parentframe
.GetSize()
291 self
.parentframe
.SetSize((0,0))
292 self
.parentframe
.SetSize(size
)
295 print self
.parentframe
.GetToolBar()
297 if self
.parentframe
.GetToolBar() != None:
298 print "Removing fauxbar"
299 self
.nullbar
.Reparent(self
.floatframe
)
300 self
.parentframe
.SetToolBar(None)
301 size
= self
.parentframe
.GetSize()
302 self
.parentframe
.SetSize((0,0))
303 self
.parentframe
.SetSize(size
)