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