]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/lib/foldmenu.py
1 # 12/07/2003 - Jeff Grimmett (grimmtooth@softhome.net)
3 # o 2.5 Compatability changes
7 from wx
.lib
.evtmgr
import eventManager
9 class FoldOutWindow(wx
.PopupWindow
):
10 def __init__(self
,parent
,style
=0):
11 wx
.PopupWindow
.__init
__(self
,parent
,style
)
12 self
.SetAutoLayout(True)
13 self
.sizer
=wx
.BoxSizer(wx
.HORIZONTAL
)
14 self
.SetSizer(self
.sizer
, deleteOld
=False)
18 self
.Bind(wx
.EVT_ENTER_WINDOW
, self
.evEnter
)
19 self
.Bind(wx
.EVT_LEAVE_WINDOW
, self
.evLeave
)
22 faceClr
= wx
.SystemSettings_GetSystemColour(wx
.SYS_COLOUR_WINDOW
)
23 self
.SetBackgroundColour(faceClr
)
25 def AddButton(self
,bitmap
,handler
=None):
27 btn
=wx
.BitmapButton(self
,id,bitmap
)
28 self
.sizer
.Add(btn
, 1, wx
.ALIGN_CENTER|wx
.ALL|wx
.EXPAND
, 2)
29 self
.Bind(wx
.EVT_BUTTON
, self
.OnBtnClick
, btn
)
34 self
.handlers
[id]=handler
39 if not self
.IsShown():
42 def OnBtnClick(self
,event
):
43 id=event
.GetEventObject().GetId()
45 if self
.handlers
.has_key(id):
46 self
.handlers
[id](event
)
52 def evEnter(self
,event
):
54 self
.rect
=self
.GetRect()
57 def evLeave(self
,event
):
59 if not self
.rect
.Inside(self
.ClientToScreen(event
.GetPosition())):
68 class FoldOutMenu(wx
.BitmapButton
):
69 def __init__(self
,parent
,id,bitmap
,pos
= wx
.DefaultPosition
,
70 size
= wx
.DefaultSize
, style
= wx
.BU_AUTODRAW
,
71 validator
= wx
.DefaultValidator
, name
= "button"):
73 wx
.BitmapButton
.__init
__(self
, parent
, id, bitmap
, pos
, size
, style
,
77 self
.parent
.Bind(wx
.EVT_BUTTON
, self
.click
, self
)
78 self
.popwin
=FoldOutWindow(self
.parent
)
80 def AddButton(self
,bitmap
,handler
=None):
81 return self
.popwin
.AddButton(bitmap
,handler
=handler
)
83 def click(self
,event
):
84 pos
=self
.GetPosition()
87 pos
.y
=pos
.y
+sz
.height
/2
88 self
.popwin
.Position(pos
,sz
)