]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wxPython/lib/floatbar.py
1 #----------------------------------------------------------------------------
3 # Purpose: Contains floating toolbar class
8 #----------------------------------------------------------------------------
9 from wxPython
.wx
import *
11 if wxPlatform
== '__WXGTK__':
13 # For wxGTK all we have to do is set the wxTB_DOCKABLE flag
15 class wxFloatBar(wxToolBar
):
16 def __init__(self
, parent
, ID
,
17 pos
= wxDefaultPosition
,
21 wxToolBar
.__init
__(self
, parent
, ID
, pos
, size
,
22 style|wxTB_DOCKABLE
, name
)
24 # these other methods just become no-ops
25 def SetFloatable(self
, float):
35 def SetTitle(self
, title
):
41 class wxFloatBar(wxToolBar
):
43 wxToolBar subclass which can be dragged off its frame and later
44 replaced there. Drag on the toolbar to release it, close it like
45 a normal window to make it return to its original
46 position. Programmatically, call SetFloatable(true) and then
47 Float(true) to float, Float(false) to dock.
50 def __init__(self
,*_args
,**_kwargs
):
52 In addition to the usual arguments, wxFloatBar accepts keyword
53 args of: title(string): the title that should appear on the
54 toolbar's frame when it is floating. floatable(bool): whether
55 user actions (i.e., dragging) can float the toolbar or not.
57 args
= (self
,) + _args
58 apply(wxToolBar
.__init
__, args
, _kwargs
)
59 if _kwargs
.has_key('floatable'):
60 self
.floatable
= _kwargs
['floatable']
61 assert type(self
.floatable
) == type(0)
65 if _kwargs
.has_key('title'):
66 self
.title
= _kwargs
['title']
67 assert type(self
.title
) == type("")
70 EVT_MOUSE_EVENTS(self
, self
.OnMouse
)
71 self
.parentframe
= wxPyTypeCast(args
[1], 'wxFrame')
74 def IsFloatable(self
):
78 def SetFloatable(self
, float):
79 self
.floatable
= float
80 #Find the size of a title bar.
81 if not hasattr(self
, 'titleheight'):
82 test
= wxMiniFrame(NULL
, -1, "TEST")
83 test
.SetClientSize(wxSize(0,0))
84 self
.titleheight
= test
.GetSizeTuple()[1]
93 wxToolBar
.Realize(self
)
100 def SetTitle(self
, title
):
101 print 'SetTitle', title
103 if self
.IsFloating():
104 self
.floatframe
.SetTitle(self
.title
)
107 ## def GetHome(self):
109 ## Returns the frame which this toolbar will return to when
110 ## docked, or the parent if currently docked.
112 ## if hasattr(self, 'parentframe'):
113 ## return self.parentframe
115 ## return wxPyTypeCast(self.GetParent(), 'wxFrame')
118 ## def SetHome(self, frame):
120 ## Called when docked, this will remove the toolbar from its
121 ## current frame and attach it to another. If called when
122 ## floating, it will dock to the frame specified when the toolbar
125 ## if self.IsFloating():
126 ## self.parentframe = frame
127 ## self.floatframe.Reparent(frame)
129 ## parent = wxPyTypeCast(self.GetParent(), 'wxFrame')
130 ## self.Reparent(frame)
131 ## parent.SetToolBar(None)
132 ## size = parent.GetSize()
133 ## parent.SetSize(wxSize(0,0))
134 ## parent.SetSize(size)
135 ## frame.SetToolBar(self)
136 ## size = frame.GetSize()
137 ## frame.SetSize(wxSize(0,0))
138 ## frame.SetSize(size)
141 def Float(self
, bool):
142 "Floats or docks the toolbar programmatically."
144 self
.parentframe
= wxPyTypeCast(self
.GetParent(), 'wxFrame')
147 useStyle
= wxDEFAULT_FRAME_STYLE
149 useStyle
= wxTHICK_FRAME
150 self
.floatframe
= wxMiniFrame(self
.parentframe
, -1, self
.title
,
153 self
.Reparent(self
.floatframe
)
154 self
.parentframe
.SetToolBar(None)
156 psize
= self
.parentframe
.GetSize()
157 self
.parentframe
.SetSize(wxSize(0,0))
158 self
.parentframe
.SetSize(psize
)
159 self
.floatframe
.SetToolBar(self
)
160 self
.oldcolor
= self
.GetBackgroundColour()
163 h
= self
.GetSize().height
165 h
= h
+ self
.titleheight
166 self
.floatframe
.SetSize(wxSize(w
,h
))
167 self
.floatframe
.SetClientSize(self
.GetSize())
168 newpos
= self
.parentframe
.GetPosition()
169 newpos
.y
= newpos
.y
+ _DOCKTHRESHOLD
* 2
170 self
.floatframe
.SetPosition(newpos
)
171 self
.floatframe
.Show(true
)
173 EVT_CLOSE(self
.floatframe
, self
.OnDock
)
174 #EVT_MOVE(self.floatframe, self.OnMove)
177 self
.Reparent(self
.parentframe
)
178 self
.parentframe
.SetToolBar(self
)
180 self
.floatframe
.SetToolBar(None)
181 self
.floatframe
.Destroy()
182 size
= self
.parentframe
.GetSize()
183 self
.parentframe
.SetSize(wxSize(0,0))
184 self
.parentframe
.SetSize(size
)
185 self
.SetBackgroundColour(self
.oldcolor
)
190 if hasattr(self
, 'oldpos'):
195 homepos
= self
.parentframe
.ClientToScreen(wxPoint(0,0))
196 floatpos
= self
.floatframe
.GetPosition()
197 if (abs(homepos
.x
- floatpos
.x
) < _DOCKTHRESHOLD
and
198 abs(homepos
.y
- floatpos
.y
) < _DOCKTHRESHOLD
):
200 #homepos = self.parentframe.GetPositionTuple()
201 #homepos = homepos[0], homepos[1] + self.titleheight
202 #floatpos = self.floatframe.GetPositionTuple()
203 #if abs(homepos[0] - floatpos[0]) < 35 and abs(homepos[1] - floatpos[1]) < 35:
204 # self._SetFauxBarVisible(true)
206 # self._SetFauxBarVisible(false)
209 def OnMouse(self
, e
):
210 if not self
.IsFloatable():
214 if e
.ButtonDClick(1) or e
.ButtonDClick(2) or e
.ButtonDClick(3) or e
.ButtonDown() or e
.ButtonUp():
219 self
.oldpos
= (e
.GetX(), e
.GetY())
222 self
.oldpos
= (e
.GetX(), e
.GetY())
226 if self
.IsFloating():
227 homepos
= self
.parentframe
.ClientToScreen(wxPoint(0,0))
228 floatpos
= self
.floatframe
.GetPosition()
229 if (abs(homepos
.x
- floatpos
.x
) < _DOCKTHRESHOLD
and
230 abs(homepos
.y
- floatpos
.y
) < _DOCKTHRESHOLD
):
235 if not self
.IsFloating():
237 self
.oldpos
= (e
.GetX(), e
.GetY())
239 if hasattr(self
, 'oldpos'):
240 loc
= self
.floatframe
.GetPosition()
241 pt
= wxPoint(loc
.x
- (self
.oldpos
[0]-e
.GetX()), loc
.y
- (self
.oldpos
[1]-e
.GetY()))
242 self
.floatframe
.Move(pt
)
246 def _SetFauxBarVisible(self
, vis
):
249 if self
.parentframe
.GetToolBar() == None:
250 if not hasattr(self
, 'nullbar'):
251 self
.nullbar
= wxToolBar(self
.parentframe
, -1)
252 print "Adding fauxbar."
253 self
.nullbar
.Reparent(self
.parentframe
)
255 self
.parentframe
.SetToolBar(self
.nullbar
)
257 col
= wxNamedColour("GREY")
258 self
.nullbar
.SetBackgroundColour(col
)
260 size
= self
.parentframe
.GetSize()
261 self
.parentframe
.SetSize(wxSize(0,0))
262 self
.parentframe
.SetSize(size
)
265 print self
.parentframe
.GetToolBar()
267 if self
.parentframe
.GetToolBar() != None:
268 print "Removing fauxbar"
269 self
.nullbar
.Reparent(self
.floatframe
)
270 self
.parentframe
.SetToolBar(None)
271 size
= self
.parentframe
.GetSize()
272 self
.parentframe
.SetSize(wxSize(0,0))
273 self
.parentframe
.SetSize(size
)