]>
git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/lib/floatbar.py
7d462233c6aee9a5baadfc9b54680867cacd9447
1 #----------------------------------------------------------------------------
3 # Purpose: Contains floating toolbar class
8 #----------------------------------------------------------------------------
9 from wxPython
.wx
import *
11 if wxPlatform
== '__WXGTK__':
12 msg
= "Due to a bug in wxGTK this class is not available on that "\
13 "platform for this release. Sorry."
14 raise ImportError, msg
19 class wxFloatBar(wxToolBar
):
21 wxToolBar subclass which can be dragged off its frame and later
22 replaced there. Drag on the toolbar to release it, close it like
23 a normal window to make it return to its original
24 position. Programmatically, call SetFloatable(true) and then
25 Float(true) to float, Float(false) to dock.
28 def __init__(self
,*_args
,**_kwargs
):
30 In addition to the usual arguments, wxFloatBar accepts keyword
31 args of: title(string): the title that should appear on the
32 toolbar's frame when it is floating. floatable(bool): whether
33 user actions (i.e., dragging) can float the toolbar or not.
35 args
= (self
,) + _args
36 apply(wxToolBar
.__init
__, args
, _kwargs
)
37 if _kwargs
.has_key('floatable'):
38 self
.floatable
= _kwargs
['floatable']
39 assert type(self
.floatable
) == type(0)
43 if _kwargs
.has_key('title'):
44 self
.title
= _kwargs
['title']
45 assert type(self
.title
) == type("")
48 EVT_MOUSE_EVENTS(self
, self
.OnMouse
)
49 self
.parentframe
= wxPyTypeCast(args
[1], 'wxFrame')
52 def IsFloatable(self
):
56 def SetFloatable(self
, float):
57 self
.floatable
= float
58 #Find the size of a title bar.
59 if not hasattr(self
, 'titleheight'):
60 test
= wxMiniFrame(NULL
, -1, "TEST")
61 test
.SetClientSize(wxSize(0,0))
62 self
.titleheight
= test
.GetSizeTuple()[1]
71 wxToolBar
.Realize(self
)
78 def SetTitle(self
, title
):
79 print 'SetTitle', title
82 self
.floatframe
.SetTitle(self
.title
)
87 ## Returns the frame which this toolbar will return to when
88 ## docked, or the parent if currently docked.
90 ## if hasattr(self, 'parentframe'):
91 ## return self.parentframe
93 ## return wxPyTypeCast(self.GetParent(), 'wxFrame')
96 ## def SetHome(self, frame):
98 ## Called when docked, this will remove the toolbar from its
99 ## current frame and attach it to another. If called when
100 ## floating, it will dock to the frame specified when the toolbar
103 ## if self.IsFloating():
104 ## self.parentframe = frame
105 ## self.floatframe.Reparent(frame)
107 ## parent = wxPyTypeCast(self.GetParent(), 'wxFrame')
108 ## self.Reparent(frame)
109 ## parent.SetToolBar(None)
110 ## size = parent.GetSize()
111 ## parent.SetSize(wxSize(0,0))
112 ## parent.SetSize(size)
113 ## frame.SetToolBar(self)
114 ## size = frame.GetSize()
115 ## frame.SetSize(wxSize(0,0))
116 ## frame.SetSize(size)
119 def Float(self
, bool):
120 "Floats or docks the toolbar programmatically."
122 self
.parentframe
= wxPyTypeCast(self
.GetParent(), 'wxFrame')
125 useStyle
= wxDEFAULT_FRAME_STYLE
127 useStyle
= wxTHICK_FRAME
128 self
.floatframe
= wxFrame(self
.parentframe
, -1, self
.title
,
131 self
.Reparent(self
.floatframe
)
132 self
.parentframe
.SetToolBar(None)
134 psize
= self
.parentframe
.GetSize()
135 self
.parentframe
.SetSize(wxSize(0,0))
136 self
.parentframe
.SetSize(psize
)
137 self
.floatframe
.SetToolBar(self
)
138 self
.oldcolor
= self
.GetBackgroundColour()
141 h
= self
.GetSize().height
143 h
= h
+ self
.titleheight
144 self
.floatframe
.SetSize(wxSize(w
,h
))
145 self
.floatframe
.SetClientSize(self
.GetSize())
146 newpos
= self
.parentframe
.GetPosition()
147 newpos
.y
= newpos
.y
+ _DOCKTHRESHOLD
* 2
148 self
.floatframe
.SetPosition(newpos
)
149 self
.floatframe
.Show(true
)
151 EVT_CLOSE(self
.floatframe
, self
.OnDock
)
152 #EVT_MOVE(self.floatframe, self.OnMove)
155 self
.Reparent(self
.parentframe
)
156 self
.parentframe
.SetToolBar(self
)
158 self
.floatframe
.SetToolBar(None)
159 self
.floatframe
.Destroy()
160 size
= self
.parentframe
.GetSize()
161 self
.parentframe
.SetSize(wxSize(0,0))
162 self
.parentframe
.SetSize(size
)
163 self
.SetBackgroundColour(self
.oldcolor
)
168 if hasattr(self
, 'oldpos'):
173 homepos
= self
.parentframe
.ClientToScreen(wxPoint(0,0))
174 floatpos
= self
.floatframe
.GetPosition()
175 if (abs(homepos
.x
- floatpos
.x
) < _DOCKTHRESHOLD
and
176 abs(homepos
.y
- floatpos
.y
) < _DOCKTHRESHOLD
):
178 #homepos = self.parentframe.GetPositionTuple()
179 #homepos = homepos[0], homepos[1] + self.titleheight
180 #floatpos = self.floatframe.GetPositionTuple()
181 #if abs(homepos[0] - floatpos[0]) < 35 and abs(homepos[1] - floatpos[1]) < 35:
182 # self._SetFauxBarVisible(true)
184 # self._SetFauxBarVisible(false)
187 def OnMouse(self
, e
):
188 if not self
.IsFloatable():
192 if e
.ButtonDClick(1) or e
.ButtonDClick(2) or e
.ButtonDClick(3) or e
.ButtonDown() or e
.ButtonUp():
197 self
.oldpos
= (e
.GetX(), e
.GetY())
200 self
.oldpos
= (e
.GetX(), e
.GetY())
204 if self
.IsFloating():
205 homepos
= self
.parentframe
.ClientToScreen(wxPoint(0,0))
206 floatpos
= self
.floatframe
.GetPosition()
207 if (abs(homepos
.x
- floatpos
.x
) < _DOCKTHRESHOLD
and
208 abs(homepos
.y
- floatpos
.y
) < _DOCKTHRESHOLD
):
213 if not self
.IsFloating():
215 self
.oldpos
= (e
.GetX(), e
.GetY())
217 if hasattr(self
, 'oldpos'):
218 loc
= self
.floatframe
.GetPosition()
219 pt
= wxPoint(loc
.x
- (self
.oldpos
[0]-e
.GetX()), loc
.y
- (self
.oldpos
[1]-e
.GetY()))
220 self
.floatframe
.Move(pt
)
224 def _SetFauxBarVisible(self
, vis
):
227 if self
.parentframe
.GetToolBar() == None:
228 if not hasattr(self
, 'nullbar'):
229 self
.nullbar
= wxToolBar(self
.parentframe
, -1)
230 print "Adding fauxbar."
231 self
.nullbar
.Reparent(self
.parentframe
)
233 self
.parentframe
.SetToolBar(self
.nullbar
)
235 col
= wxNamedColour("GREY")
236 self
.nullbar
.SetBackgroundColour(col
)
238 size
= self
.parentframe
.GetSize()
239 self
.parentframe
.SetSize(wxSize(0,0))
240 self
.parentframe
.SetSize(size
)
243 print self
.parentframe
.GetToolBar()
245 if self
.parentframe
.GetToolBar() != None:
246 print "Removing fauxbar"
247 self
.nullbar
.Reparent(self
.floatframe
)
248 self
.parentframe
.SetToolBar(None)
249 size
= self
.parentframe
.GetSize()
250 self
.parentframe
.SetSize(wxSize(0,0))
251 self
.parentframe
.SetSize(size
)