2003-12-16 19:34:40 -05:00
|
|
|
# 12/07/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
|
|
|
#
|
|
|
|
# o 2.5 Compatability changes
|
|
|
|
#
|
2003-11-12 16:34:20 -05:00
|
|
|
|
|
|
|
import wx
|
|
|
|
from wx.lib.evtmgr import eventManager
|
|
|
|
|
|
|
|
class FoldOutWindow(wx.PopupWindow):
|
|
|
|
def __init__(self,parent,style=0):
|
|
|
|
wx.PopupWindow.__init__(self,parent,style)
|
|
|
|
self.SetAutoLayout(True)
|
|
|
|
self.sizer=wx.BoxSizer(wx.HORIZONTAL)
|
|
|
|
self.SetSizer(self.sizer, deleteOld=False)
|
|
|
|
self.handlers={}
|
|
|
|
self.InitColors()
|
|
|
|
self.inWindow=False
|
2003-12-16 19:34:40 -05:00
|
|
|
self.Bind(wx.EVT_ENTER_WINDOW, self.evEnter)
|
|
|
|
self.Bind(wx.EVT_LEAVE_WINDOW, self.evLeave)
|
2003-11-12 16:34:20 -05:00
|
|
|
|
|
|
|
def InitColors(self):
|
2004-12-23 15:19:17 -05:00
|
|
|
faceClr = wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOW)
|
2003-11-12 16:34:20 -05:00
|
|
|
self.SetBackgroundColour(faceClr)
|
|
|
|
|
|
|
|
def AddButton(self,bitmap,handler=None):
|
|
|
|
id=wx.NewId()
|
|
|
|
btn=wx.BitmapButton(self,id,bitmap)
|
|
|
|
self.sizer.Add(btn, 1, wx.ALIGN_CENTER|wx.ALL|wx.EXPAND, 2)
|
2003-12-16 19:34:40 -05:00
|
|
|
self.Bind(wx.EVT_BUTTON, self.OnBtnClick, btn)
|
2003-11-12 16:34:20 -05:00
|
|
|
self.sizer.Fit(self)
|
|
|
|
self.Layout()
|
2003-12-16 19:34:40 -05:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
if handler:
|
|
|
|
self.handlers[id]=handler
|
2003-12-16 19:34:40 -05:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
return id
|
|
|
|
|
|
|
|
def Popup(self):
|
|
|
|
if not self.IsShown():
|
|
|
|
self.Show()
|
|
|
|
|
|
|
|
def OnBtnClick(self,event):
|
|
|
|
id=event.GetEventObject().GetId()
|
2003-12-16 19:34:40 -05:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
if self.handlers.has_key(id):
|
|
|
|
self.handlers[id](event)
|
2003-12-16 19:34:40 -05:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
self.Hide()
|
|
|
|
self.inWindow=False
|
|
|
|
event.Skip()
|
|
|
|
|
|
|
|
def evEnter(self,event):
|
|
|
|
self.inWindow=True
|
|
|
|
self.rect=self.GetRect()
|
|
|
|
event.Skip()
|
|
|
|
|
|
|
|
def evLeave(self,event):
|
|
|
|
if self.inWindow:
|
|
|
|
if not self.rect.Inside(self.ClientToScreen(event.GetPosition())):
|
|
|
|
self.Hide()
|
2003-12-16 19:34:40 -05:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
event.Skip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class FoldOutMenu(wx.BitmapButton):
|
|
|
|
def __init__(self,parent,id,bitmap,pos = wx.DefaultPosition,
|
|
|
|
size = wx.DefaultSize, style = wx.BU_AUTODRAW,
|
|
|
|
validator = wx.DefaultValidator, name = "button"):
|
2003-12-16 19:34:40 -05:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
wx.BitmapButton.__init__(self, parent, id, bitmap, pos, size, style,
|
|
|
|
validator, name)
|
2003-12-16 19:34:40 -05:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
self.parent=parent
|
2003-12-16 19:34:40 -05:00
|
|
|
self.parent.Bind(wx.EVT_BUTTON, self.click, self)
|
2003-11-12 16:34:20 -05:00
|
|
|
self.popwin=FoldOutWindow(self.parent)
|
|
|
|
|
|
|
|
def AddButton(self,bitmap,handler=None):
|
|
|
|
return self.popwin.AddButton(bitmap,handler=handler)
|
|
|
|
|
|
|
|
def click(self,event):
|
|
|
|
pos=self.GetPosition()
|
|
|
|
sz=self.GetSize()
|
|
|
|
pos.x=pos.x+sz.width
|
|
|
|
pos.y=pos.y+sz.height/2
|
|
|
|
self.popwin.Position(pos,sz)
|
|
|
|
self.popwin.Popup()
|