How to manually set the toggle state of wxpython platebutton

I am building an application using platebutton iin wxpython. The problem is that I am not able to manually SetState of the toogle buton. I used SetState(0) but it does not change the state of toggle button. Any help would be great. Thanks.I have attached a sample code file also. Also, the code is written below too.

Sample code:

import wx

import wx.lib.platebtn as platebtn

class Toolbar(wx.Panel):

def __init__(self, parent):

    wx.Panel.__init__(self, parent, -1)

    sizer = wx.BoxSizer(wx.VERTICAL)

    self.SetSizer(sizer)

    self.infinity= platebtn.PlateButton(self, -1, label='Button', size = (80,40), style= platebtn.PB_STYLE_TOGGLE)

    self.infinity.Bind(wx.EVT_TOGGLEBUTTON, self.OnInfinityToggled)

    sizer.Add(self.infinity, 0)

def OnInfinityToggled(self,event):

    if event.GetEventObject().IsPressed():

        self.popupmenu = wx.Menu()

        Session = self.popupmenu.Append(-1, "Session")

        Session2= self.popupmenu.Append(-1, "Session2")

        self.Bind(wx.EVT_MENU, self.SessionMenu, Session)

        self.Bind(wx.EVT_MENU, self.SessionMenu, Session2)

        self.PopupMenu(self.popupmenu,(2,20))

        self.Bind(wx.EVT_MENU_CLOSE, self.SessionMenu)

    else:

        pass

def SessionMenu(self, event):

    self.infinity.SetState(0)

    self.infinity.Raise()

    self.infinity.Refresh()

if name == ‘main’:

app = wx.PySimpleApp(0)

f = wx.Frame(None)

p = Toolbar(f)

f.Show()

app.MainLoop()

platebtn.py (1.33 KB)

I’m guessing that you don’t really want the “toggle” feature here.
When you have a toggle button, you have to push the button once to
set, and push it again to release. If you just want a button that
brings up a menu, then remove platebtn.PB_STYLE_TOGGLE and use
EVT_BUTTON instead of EVT_TOGGLEBUTTON.
You should also add event.Skip() to the end of your event handlers,
although that doesn’t affect the problem you see here.
Now, it turns out that the problem you describe is actually a design
flaw in the platebtn control. When you call SetState, that does
immediately change the look and feel of the button, but it does not
change the “pressed” state. So, when the menu goes away and the
button gains focus again, it sees that the button is still
“pressed”, and changes the state. The documentation does say that
the state you enter with “SetState” will be overridden by mouse
actions. The control needs to have another API to let the user
manipulate the the _pressed state, simulating a left-click.

···

Samyak Jain wrote:

I am
building an application using platebutton iin wxpython. The
problem is that I am not able to manually SetState of the
toogle buton. I used SetState(0) but it does not change the
state of toggle button. Any help would be great. Thanks.I have
attached a sample code file also. Also, the code is written
below too.

-- Tim Roberts, Providenza & Boekelheide, Inc.

timr@probo.com