So it's like this: I want to create an 'activebutton' widget with the following properties.
* The button itself is text that changes foreground color when the mouse hovers over it.
* If the mouse hovers for more than 200ms, a PopupMenu appears that allows the user to select a subitem corresponding to the button.
That is, if the button says "file", the PopupMenu might say "New", "Save", etc.
* If the user moves off the PopupMenu, it goes away.
Unfortunately, I can't manage the last one. And, documentation for PopupMenu's seems to be scarce on the 'Net. I'm relying mostly on http://www.wxpython.org/onlinedocs.php, but there are at least two classes (wx.PopupWindow, wx.PopupTransientWindow) that I can't find there, AND the help(...) files are remarkably verbose, yet sparse on useful detail. Grrr....
Any thoughts greatly appreciated.
import wx
class ActiveButton(wx.StaticText):
def __init__(self, parent, id=wx.ID_ANY, label="An ActiveButton",
pos=wx.DefaultPosition,size=wx.DefaultSize,style=0):
wx.StaticText.__init__(self, parent=parent, id=id, label=label,
pos=pos,size=size,style=style)
self.SetForegroundColour(wx.Color(255,0,0))
self.Bind(wx.EVT_ENTER_WINDOW,self.OnEnter)
self.Bind(wx.EVT_LEAVE_WINDOW,self.OnLeave)
self.timer = wx.Timer(self, id=1)
self.Bind(wx.EVT_TIMER, self.CreateMenu)
self.menu=wx.Menu()
def OnEnter(self, event):
if not self.timer.IsRunning():
self.timer.Start(200,oneShot=True)
self.SetForegroundColour(wx.Color(0,255,0)) # delightful color scheme
self.Refresh()
def OnLeave(self,event):
self.SetForegroundColour(wx.Color(255,0,0))
self.Refresh()
self.timer.Stop()
# should also dismiss PopupMenu
def CreateMenu(self, event):
m = self.PopupMenu(self.menu,(-65,0))
print m # prints True or False!
def AddItem(self,text,id=None,handler=None):
if id == None:
id = wx.NewId()
self.menu.Append(id,text)
wx.EVT_MENU(self.menu,id,handler)