[wxPython-users] Re: Firing events from buttons in a ButtonPanel

Robin Dunn robin at alldunn.com
Thu Mar 1 10:20:51 PST 2007


Guilherme Polo wrote:
> Again me ;)
> 
> Well, just to fix what I've experiencing I changed the following...
> 
> Inside Class ButtonPanel:
> 
>     def OnLeftUp(self, event):
>         ...
>         #if hit.GetStatus() == "Pressed" # changed to:
>         if hit.GetStatus() == "Pressed" or hit.GetStatus() == "Hover":
>           ...
> 
> Probably this isn't the right way to fix it, but I'm using this "my own bad fix"
> till it gets really fixed.

The problem with this fix is you can get a button event even if the 
button was never in the pressed state, for example press the mouse 
button on the ButtonPanel but outside of any button, then drag over to a 
button and release the mouse button.

A better fix is to not set the hover state if the button is already in 
the pressed state:

Index: wxPython/wx/lib/buttonpanel.py
===================================================================
RCS file: 
/pack/cvsroots/wxwidgets/wxWidgets/wxPython/wx/lib/buttonpanel.py,v
retrieving revision 1.7.4.1
diff -u -4 -r1.7.4.1 buttonpanel.py
--- wxPython/wx/lib/buttonpanel.py	2007/02/26 23:23:57	1.7.4.1
+++ wxPython/wx/lib/buttonpanel.py	2007/03/01 17:54:49
@@ -1764,9 +1764,10 @@
          if tabId != self._currentButton:
              self.RepaintOldSelection()

          if btn.GetRect().Contains(event.GetPosition()):
-            btn.SetStatus("Hover")
+            if btn.GetStatus() != "Pressed":
+                btn.SetStatus("Hover")
          else:
              btn.SetStatus("Normal")

          if tabId != self._currentButton:



-- 
Robin Dunn
Software Craftsman
http://wxPython.org  Java give you jitters?  Relax with wxPython!





More information about the wxpython-users mailing list