]> git.saurik.com Git - wxWidgets.git/blame - wxPython/wx/lib/floatbar.py
Reworked how stock objects are initialized. They now have an
[wxWidgets.git] / wxPython / wx / lib / floatbar.py
CommitLineData
d14a1e28
RD
1#----------------------------------------------------------------------------
2# Name: floatbar.py
3# Purpose: Contains floating toolbar class
4#
5# Author: Bryn Keller
6#
7# Created: 10/4/99
8#----------------------------------------------------------------------------
b881fc78
RD
9# 12/02/2003 - Jeff Grimmett (grimmtooth@softhome.net)
10#
11# o 2.5 Compatability changes
12#
13# 12/07/2003 - Jeff Grimmett (grimmtooth@softhome.net)
14#
15# o Added deprecation warning.
16#
17
d14a1e28
RD
18"""
19NOTE: This module is *not* supported in any way. Use it however you
20 wish, but be warned that dealing with any consequences is
21 entirly up to you.
22 --Robin
23"""
24
b881fc78
RD
25import warnings
26import wx
27
28warningmsg = r"""\
29
30################################################\
31# This module is not supported in any way! |
32# |
33# See cource code for wx.lib.floatbar for more |
34# information. |
35################################################/
36
37"""
d14a1e28 38
b881fc78
RD
39warnings.warn(warningmsg, DeprecationWarning, stacklevel=2)
40
41if wx.Platform == '__WXGTK__':
d14a1e28
RD
42 #
43 # For wxGTK all we have to do is set the wxTB_DOCKABLE flag
44 #
b881fc78 45 class wxFloatBar(wx.ToolBar):
d14a1e28 46 def __init__(self, parent, ID,
b881fc78
RD
47 pos = wx.DefaultPosition,
48 size = wx.DefaultSize,
d14a1e28
RD
49 style = 0,
50 name = 'toolbar'):
b881fc78
RD
51 wx.ToolBar.__init__(self, parent, ID, pos, size,
52 style|wx.TB_DOCKABLE, name)
d14a1e28
RD
53
54 # these other methods just become no-ops
55 def SetFloatable(self, float):
56 pass
57
58 def IsFloating(self):
59 return 1
60
61 def GetTitle(self):
62 return ""
63
64
65 def SetTitle(self, title):
66 pass
67
68else:
69 _DOCKTHRESHOLD = 25
70
b881fc78 71 class wxFloatBar(wx.ToolBar):
d14a1e28
RD
72 """
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.
78 """
79
80 def __init__(self,*_args,**_kwargs):
81 """
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.
86 """
87 args = (self,) + _args
b881fc78 88 apply(wx.ToolBar.__init__, args, _kwargs)
d14a1e28
RD
89 if _kwargs.has_key('floatable'):
90 self.floatable = _kwargs['floatable']
91 assert type(self.floatable) == type(0)
92 else:
93 self.floatable = 0
94 self.floating = 0
95 if _kwargs.has_key('title'):
96 self.title = _kwargs['title']
97 assert type(self.title) == type("")
98 else:
99 self.title = ""
b881fc78
RD
100 self.Bind(wx.EVT_MOUSE_EVENTS, self.OnMouse)
101 self.parentframe = args[1]
d14a1e28
RD
102
103
104 def IsFloatable(self):
105 return self.floatable
106
107
108 def SetFloatable(self, float):
109 self.floatable = float
110 #Find the size of a title bar.
111 if not hasattr(self, 'titleheight'):
b881fc78
RD
112 test = wx.MiniFrame(None, -1, "TEST")
113 test.SetClientSize((0,0))
114 self.titleheight = test.GetSize()[1]
d14a1e28
RD
115 test.Destroy()
116
117
118 def IsFloating(self):
119 return self.floating
120
121
122 def Realize(self):
b881fc78 123 wx.ToolBar.Realize(self)
d14a1e28
RD
124
125
126 def GetTitle(self):
127 return self.title
128
129
130 def SetTitle(self, title):
131 print 'SetTitle', title
132 self.title = title
133 if self.IsFloating():
134 self.floatframe.SetTitle(self.title)
135
136
137 ## def GetHome(self):
138 ## """
139 ## Returns the frame which this toolbar will return to when
140 ## docked, or the parent if currently docked.
141 ## """
142 ## if hasattr(self, 'parentframe'):
143 ## return self.parentframe
144 ## else:
b881fc78 145 ## return (self.GetParent())
d14a1e28
RD
146
147
148 ## def SetHome(self, frame):
149 ## """
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
153 ## window is closed.
154 ## """
155 ## if self.IsFloating():
156 ## self.parentframe = frame
157 ## self.floatframe.Reparent(frame)
158 ## else:
b881fc78 159 ## parent = self.GetParent()
d14a1e28
RD
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)
169
170
171 def Float(self, bool):
172 "Floats or docks the toolbar programmatically."
173 if bool:
b881fc78 174 self.parentframe = self.GetParent()
d14a1e28
RD
175 print self.title
176 if self.title:
b881fc78 177 useStyle = wx.DEFAULT_FRAME_STYLE
d14a1e28 178 else:
b881fc78
RD
179 useStyle = wx.THICK_FRAME
180 self.floatframe = wx.MiniFrame(self.parentframe, -1, self.title,
d14a1e28
RD
181 style = useStyle)
182
183 self.Reparent(self.floatframe)
184 self.parentframe.SetToolBar(None)
185 self.floating = 1
186 psize = self.parentframe.GetSize()
b881fc78 187 self.parentframe.SetSize((0,0))
d14a1e28
RD
188 self.parentframe.SetSize(psize)
189 self.floatframe.SetToolBar(self)
190 self.oldcolor = self.GetBackgroundColour()
191
b881fc78
RD
192 w = psize[0]
193 h = self.GetSize()[1]
d14a1e28
RD
194 if self.title:
195 h = h + self.titleheight
b881fc78 196 self.floatframe.SetSize((w,h))
d14a1e28
RD
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)
202
b881fc78
RD
203 self.floatframe.Bind(wx.EVT_CLOSE, self.OnDock)
204 #self.floatframe.Bind(wx.EVT_MOVE, self.OnMove)
d14a1e28
RD
205
206 else:
207 self.Reparent(self.parentframe)
208 self.parentframe.SetToolBar(self)
209 self.floating = 0
210 self.floatframe.SetToolBar(None)
211 self.floatframe.Destroy()
212 size = self.parentframe.GetSize()
b881fc78 213 self.parentframe.SetSize((0,0))
d14a1e28
RD
214 self.parentframe.SetSize(size)
215 self.SetBackgroundColour(self.oldcolor)
216
217
218 def OnDock(self, e):
219 self.Float(0)
220 if hasattr(self, 'oldpos'):
221 del self.oldpos
222
223
224 def OnMove(self, e):
b881fc78 225 homepos = self.parentframe.ClientToScreen((0,0))
d14a1e28
RD
226 floatpos = self.floatframe.GetPosition()
227 if (abs(homepos.x - floatpos.x) < _DOCKTHRESHOLD and
228 abs(homepos.y - floatpos.y) < _DOCKTHRESHOLD):
229 self.Float(0)
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)
235 #else:
236 # self._SetFauxBarVisible(False)
237
238
239 def OnMouse(self, e):
240 if not self.IsFloatable():
241 e.Skip()
242 return
243
244 if e.ButtonDClick(1) or e.ButtonDClick(2) or e.ButtonDClick(3) or e.ButtonDown() or e.ButtonUp():
245 e.Skip()
246
247 if e.ButtonDown():
248 self.CaptureMouse()
249 self.oldpos = (e.GetX(), e.GetY())
250
251 if e.Entering():
252 self.oldpos = (e.GetX(), e.GetY())
253
254 if e.ButtonUp():
255 self.ReleaseMouse()
256 if self.IsFloating():
b881fc78 257 homepos = self.parentframe.ClientToScreen((0,0))
d14a1e28
RD
258 floatpos = self.floatframe.GetPosition()
259 if (abs(homepos.x - floatpos.x) < _DOCKTHRESHOLD and
260 abs(homepos.y - floatpos.y) < _DOCKTHRESHOLD):
261 self.Float(0)
262 return
263
264 if e.Dragging():
265 if not self.IsFloating():
266 self.Float(True)
267 self.oldpos = (e.GetX(), e.GetY())
268 else:
269 if hasattr(self, 'oldpos'):
270 loc = self.floatframe.GetPosition()
b881fc78 271 pt = (loc.x - (self.oldpos[0]-e.GetX()), loc.y - (self.oldpos[1]-e.GetY()))
d14a1e28
RD
272 self.floatframe.Move(pt)
273
274
275
276 def _SetFauxBarVisible(self, vis):
277 return
278 if vis:
279 if self.parentframe.GetToolBar() == None:
280 if not hasattr(self, 'nullbar'):
b881fc78 281 self.nullbar = wx.ToolBar(self.parentframe, -1)
d14a1e28
RD
282 print "Adding fauxbar."
283 self.nullbar.Reparent(self.parentframe)
284 print "Reparented."
285 self.parentframe.SetToolBar(self.nullbar)
286 print "Set toolbar"
b881fc78 287 col = wx.NamedColour("GREY")
d14a1e28
RD
288 self.nullbar.SetBackgroundColour(col)
289 print "Set color"
290 size = self.parentframe.GetSize()
b881fc78 291 self.parentframe.SetSize((0,0))
d14a1e28
RD
292 self.parentframe.SetSize(size)
293 print "Set size"
294 else:
295 print self.parentframe.GetToolBar()
296 else:
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()
b881fc78 302 self.parentframe.SetSize((0,0))
d14a1e28
RD
303 self.parentframe.SetSize(size)
304
1fded56b 305
1fded56b 306