]> git.saurik.com Git - wxWidgets.git/blame_incremental - wxPython/wx/lib/foldmenu.py
SetSizeHints fix
[wxWidgets.git] / wxPython / wx / lib / foldmenu.py
... / ...
CommitLineData
1# 12/07/2003 - Jeff Grimmett (grimmtooth@softhome.net)
2#
3# o 2.5 Compatability changes
4#
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
18 self.Bind(wx.EVT_ENTER_WINDOW, self.evEnter)
19 self.Bind(wx.EVT_LEAVE_WINDOW, self.evLeave)
20
21 def InitColors(self):
22 faceClr = wx.SystemSettings_GetSystemColour(wx.SYS_COLOUR_WINDOW)
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)
29 self.Bind(wx.EVT_BUTTON, self.OnBtnClick, btn)
30 self.sizer.Fit(self)
31 self.Layout()
32
33 if handler:
34 self.handlers[id]=handler
35
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()
44
45 if self.handlers.has_key(id):
46 self.handlers[id](event)
47
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()
61
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"):
72
73 wx.BitmapButton.__init__(self, parent, id, bitmap, pos, size, style,
74 validator, name)
75
76 self.parent=parent
77 self.parent.Bind(wx.EVT_BUTTON, self.click, self)
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()