]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/lib/foldmenu.py
3 from wx
.lib
.evtmgr
import eventManager
5 class FoldOutWindow(wx
.PopupWindow
):
6 def __init__(self
,parent
,style
=0):
7 wx
.PopupWindow
.__init
__(self
,parent
,style
)
8 self
.SetAutoLayout(True)
9 self
.sizer
=wx
.BoxSizer(wx
.HORIZONTAL
)
10 self
.SetSizer(self
.sizer
, deleteOld
=False)
14 wx
.EVT_ENTER_WINDOW(self
,self
.evEnter
)
15 wx
.EVT_LEAVE_WINDOW(self
,self
.evLeave
)
18 faceClr
= wx
.SystemSettings_GetSystemColour(wx
.SYS_COLOUR_WINDOW
)
19 self
.SetBackgroundColour(faceClr
)
21 def AddButton(self
,bitmap
,handler
=None):
23 btn
=wx
.BitmapButton(self
,id,bitmap
)
24 self
.sizer
.Add(btn
, 1, wx
.ALIGN_CENTER|wx
.ALL|wx
.EXPAND
, 2)
25 wx
.EVT_BUTTON(self
,id,self
.OnBtnClick
)
29 self
.handlers
[id]=handler
33 if not self
.IsShown():
36 def OnBtnClick(self
,event
):
37 id=event
.GetEventObject().GetId()
38 if self
.handlers
.has_key(id):
39 self
.handlers
[id](event
)
44 def evEnter(self
,event
):
46 self
.rect
=self
.GetRect()
49 def evLeave(self
,event
):
51 if not self
.rect
.Inside(self
.ClientToScreen(event
.GetPosition())):
59 class FoldOutMenu(wx
.BitmapButton
):
60 def __init__(self
,parent
,id,bitmap
,pos
= wx
.DefaultPosition
,
61 size
= wx
.DefaultSize
, style
= wx
.BU_AUTODRAW
,
62 validator
= wx
.DefaultValidator
, name
= "button"):
63 wx
.BitmapButton
.__init
__(self
, parent
, id, bitmap
, pos
, size
, style
,
66 wx
.EVT_BUTTON(self
.parent
, self
.GetId(), self
.click
)
67 self
.popwin
=FoldOutWindow(self
.parent
)
69 def AddButton(self
,bitmap
,handler
=None):
70 return self
.popwin
.AddButton(bitmap
,handler
=handler
)
72 def click(self
,event
):
73 pos
=self
.GetPosition()
76 pos
.y
=pos
.y
+sz
.height
/2
77 self
.popwin
.Position(pos
,sz
)