Strange behaviour using ButtonPanel, Button gets "reselected" after I Destroy a modal dialog

Hello,

The message title was so big that I don't have much else to say :wink:

I'm including a small sample, to show what I'm saying here. I don't
know if this was noticed by
someone else, maybe I just couldn't find the answer to this.

I'm placing a ButtonPanel inside a Panel, and this ButtonPanel has
some buttons =) (in this example just one). Each button open an
dialog, and, when this dialog gets Destroyed() the button appears to
be selected again.

Here is a sample to show this:

import wx
import wx.lib.buttonpanel as BP
import cStringIO

MondrianData = """\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00
\x00\x00\x00 \x08\x06\x00\
\x00\x00szz\xf4\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\x00\x00qID\
ATX\x85\xed\xd6;\n\x800\x10E\xd1{\xc5\x8d\xb9r\x97\x16\x0b\xad$\x8a\x82:\x16\
o\xda\x84pB2\x1f\x81Fa\x8c\x9c\x08\x04Z{\xcf\xa72\xbcv\xfa\xc5\x08 \x80r\x80\
\xfc\xa2\x0e\x1c\xe4\xba\xfaX\x1d\xd0\xde]S\x07\x02\xd8>\xe1wa-`\x9fQ\xe9\
\x86\x01\x04\x10\x00\\(Dk\x1b-\x04\xdc\x1d\x07\x14\x98;\x0bS\x7f\x7f\xf9\x13\
\x04\x10@\xf9X\xbe\x00\xc9 \x14K\xc1<={\x00\x00\x00\x00IEND\xaeB`\x82"""

class main(wx.Frame):
聽聽聽聽def __init__(self, *args, **kwargs):
聽聽聽聽聽聽聽聽kwargs["style"] = wx.DEFAULT_FRAME_STYLE
聽聽聽聽聽聽聽聽wx.Frame.__init__(self, *args, **kwargs)
聽聽聽聽聽聽聽聽self.panel_tb = wx.Panel(self, -1)

聽聽聽聽聽聽聽聽self.titlebar = BP.ButtonPanel(self.panel_tb, -1, "",
style=BP.BP_USE_GRADIENT, alignment=BP.BP_ALIGN_LEFT)
聽聽self.titlebar.SetMinSize((-1, 80))

聽聽聽聽聽聽聽聽self.__do_layout()

聽聽聽聽聽聽聽聽stream = cStringIO.StringIO(MondrianData)
聽聽stream = wx.ImageFromStream(stream)
聽聽聽聽聽聽聽聽btn_img = wx.BitmapFromImage(stream)

聽聽聽聽聽聽聽聽self.Freeze()
聽聽聽聽聽聽聽聽btn = BP.ButtonInfo(self.titlebar, wx.NewId(),
聽聽聽聽聽聽btn_img, kind=wx.ITEM_NORMAL,
聽聽聽聽聽聽shortHelp="Test", longHelp="")

聽聽聽聽聽聽聽聽self.titlebar.AddButton(btn)
聽聽聽聽聽聽聽聽btn.SetText("Ha!")
聽聽self.Bind(wx.EVT_BUTTON, self.OnBtn, id=btn.GetId())

聽聽聽聽聽聽聽聽self.titlebar.DoLayout()

聽聽聽聽def OnBtn(self, evt):
聽聽聽聽聽聽聽聽dlg = wx.MessageDialog(self, "test", "testing", wx.OK)
聽聽dlg.ShowModal()
聽聽dlg.Destroy()
聽聽# do something here maybe ?

聽聽聽聽def __do_layout(self):
聽聽聽聽聽聽聽聽sizer_1 = wx.BoxSizer(wx.VERTICAL)
聽聽聽聽聽聽聽聽sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
聽聽聽聽聽聽聽聽sizer_2.Add(self.titlebar, 1, wx.EXPAND, 0)
聽聽聽聽聽聽聽聽self.panel_tb.SetAutoLayout(True)
聽聽聽聽聽聽聽聽self.panel_tb.SetSizer(sizer_2)
聽聽聽聽聽聽聽聽sizer_2.Fit(self.panel_tb)
聽聽聽聽聽聽聽聽sizer_2.SetSizeHints(self.panel_tb)
聽聽聽聽聽聽聽聽sizer_1.Add(self.panel_tb, 0, wx.EXPAND, 0)
聽聽聽聽聽聽聽聽self.SetAutoLayout(True)
聽聽聽聽聽聽聽聽self.SetSizer(sizer_1)
聽聽聽聽聽聽聽聽sizer_1.Fit(self)
聽聽聽聽聽聽聽聽sizer_1.SetSizeHints(self)
聽聽聽聽聽聽聽聽self.Layout()

class MyApp(wx.App):
聽聽聽聽def OnInit(self):
聽聽聽聽聽聽聽聽Main = main(None, -1, "")
聽聽聽聽聽聽聽聽Main.Show()
聽聽聽聽聽聽聽聽return 1

if __name__ == "__main__":
聽聽聽聽app = MyApp(0)
聽聽聽聽app.MainLoop()

路路路

--
-- Guilherme H. Polo Goncalves

I'm sorry but gmail breaks the image stream, but you can test with any image.

Guilherme Polo wrote:

Hello,

The message title was so big that I don't have much else to say :wink:

I'm including a small sample, to show what I'm saying here. I don't
know if this was noticed by
someone else, maybe I just couldn't find the answer to this.

I'm placing a ButtonPanel inside a Panel, and this ButtonPanel has
some buttons =) (in this example just one). Each button open an
dialog, and, when this dialog gets Destroyed() the button appears to
be selected again.

This is because of the order of things done in the button panel's mouse event handlers. Essentially it sends the button event and then it does a few other things for adjusting the button's state from "pressed" to "hover" as if the mouse were still inside the bounds of the button. Since your event handler blocks on a modal dialog then that extra stuff doesn't happen until after the dialog is closed, by which time the mouse has moved on to another part of the screen and so the ButtonPanel misses the motion and leave events. I'll rearrange the code in the ButtonPanel's EVT_LEFT_UP handler so the event is the last thing it does, but in the meantime you can work around this by not showing your dialog immediately, just move that code into another method and have it be invoked later with wx.CallAfter.

路路路

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

Guilherme Polo wrote:

I'm sorry but gmail breaks the image stream, but you can test with any image.

In the future you can avoid this by attaching your source code, not pasting it.

路路路

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

Thanks Robin =)