]> git.saurik.com Git - wxWidgets.git/blame - wxPython/wx/lib/foldmenu.py
Give BitmapButton its own demo, get rid of ErrorDialogs
[wxWidgets.git] / wxPython / wx / lib / foldmenu.py
CommitLineData
b881fc78
RD
1# 12/07/2003 - Jeff Grimmett (grimmtooth@softhome.net)
2#
3# o 2.5 Compatability changes
4#
d14a1e28
RD
5
6import wx
7from wx.lib.evtmgr import eventManager
8
9class 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)
15 self.handlers={}
16 self.InitColors()
17 self.inWindow=False
b881fc78
RD
18 self.Bind(wx.EVT_ENTER_WINDOW, self.evEnter)
19 self.Bind(wx.EVT_LEAVE_WINDOW, self.evLeave)
d14a1e28
RD
20
21 def InitColors(self):
b881fc78 22 faceClr = wx.SystemSettings_GetSystemColour(wx.SYS_COLOUR_WINDOW)
d14a1e28
RD
23 self.SetBackgroundColour(faceClr)
24
25 def AddButton(self,bitmap,handler=None):
26 id=wx.NewId()
27 btn=wx.BitmapButton(self,id,bitmap)
28 self.sizer.Add(btn, 1, wx.ALIGN_CENTER|wx.ALL|wx.EXPAND, 2)
b881fc78 29 self.Bind(wx.EVT_BUTTON, self.OnBtnClick, btn)
d14a1e28
RD
30 self.sizer.Fit(self)
31 self.Layout()
b881fc78 32
d14a1e28
RD
33 if handler:
34 self.handlers[id]=handler
b881fc78 35
d14a1e28
RD
36 return id
37
38 def Popup(self):
39 if not self.IsShown():
40 self.Show()
41
42 def OnBtnClick(self,event):
43 id=event.GetEventObject().GetId()
b881fc78 44
d14a1e28
RD
45 if self.handlers.has_key(id):
46 self.handlers[id](event)
b881fc78 47
d14a1e28
RD
48 self.Hide()
49 self.inWindow=False
50 event.Skip()
51
52 def evEnter(self,event):
53 self.inWindow=True
54 self.rect=self.GetRect()
55 event.Skip()
56
57 def evLeave(self,event):
58 if self.inWindow:
59 if not self.rect.Inside(self.ClientToScreen(event.GetPosition())):
60 self.Hide()
b881fc78 61
d14a1e28
RD
62 event.Skip()
63
64
65
66
67
68class 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"):
b881fc78 72
d14a1e28
RD
73 wx.BitmapButton.__init__(self, parent, id, bitmap, pos, size, style,
74 validator, name)
b881fc78 75
d14a1e28 76 self.parent=parent
b881fc78 77 self.parent.Bind(wx.EVT_BUTTON, self.click, self)
d14a1e28
RD
78 self.popwin=FoldOutWindow(self.parent)
79
80 def AddButton(self,bitmap,handler=None):
81 return self.popwin.AddButton(bitmap,handler=handler)
82
83 def click(self,event):
84 pos=self.GetPosition()
85 sz=self.GetSize()
86 pos.x=pos.x+sz.width
87 pos.y=pos.y+sz.height/2
88 self.popwin.Position(pos,sz)
89 self.popwin.Popup()