wxWidgets / Phoenix

wxPython's Project Phoenix. A new implementation of wxPython, better, stronger, faster than he was before.
http://wxpython.org/
2.21k stars 509 forks source link

RibbonButtonBar.DeleteButton fails in 4.2.1 #2511

Closed rufuswilson closed 4 months ago

rufuswilson commented 4 months ago

Operating system: Mac osx 12.7.2 wxPython version & source: 4.2.1 pypi Python version & source: 3.9.18 homebrew

Description of the problem:

Calling the DeleteButton of a RibbonButtonBar causes the following error

File "..../python3.9/site-packages/wx/lib/agw/ribbon/buttonbar.py", line 614, in DeleteButton
    self._buttons.pop(button)
TypeError: 'RibbonButtonBarButtonBase' object cannot be interpreted as an integer
Code Example (click to expand) ```python import traceback import wx import wx.lib.agw.ribbon as RB class MyFrame(wx.Frame): ICON_SIZE = wx.Size(32, 32) def __init__( self, parent, id=-1, title="Ribbon Demo", pos=wx.DefaultPosition, size=(800, 600), style=wx.DEFAULT_FRAME_STYLE, ): wx.Frame.__init__(self, parent, id, title, pos, size, style) self._ribbon = RB.RibbonBar(self, wx.ID_ANY) home = RB.RibbonPage(self._ribbon, wx.ID_ANY, "Examples") selection_panel = RB.RibbonPanel( home, wx.ID_ANY, "Test", ) self.selection = RB.RibbonButtonBar(selection_panel) self.BUTTON_DELETE = wx.NewIdRef(count=1) self.selection.AddSimpleButton( self.BUTTON_DELETE, "Delete Button", wx.ArtProvider.GetBitmap( id=wx.ART_DEL_BOOKMARK, client=wx.ART_BUTTON, size=MyFrame.ICON_SIZE ), "", ) self.BUTTON_DEMO = wx.NewIdRef(count=1) self.demobutton = self.selection.AddSimpleButton( self.BUTTON_DEMO, "Demo", wx.ArtProvider.GetBitmap( id=wx.ART_NEW, client=wx.ART_BUTTON, size=MyFrame.ICON_SIZE ), "", ) self._ribbon.Realize() self._logwindow = wx.TextCtrl( self, wx.ID_ANY, "", wx.DefaultPosition, wx.DefaultSize, wx.TE_MULTILINE | wx.TE_READONLY | wx.TE_LEFT | wx.TE_BESTWRAP | wx.BORDER_NONE, ) s = wx.BoxSizer(wx.VERTICAL) s.Add(self._ribbon, 0, wx.EXPAND) s.Add(self._logwindow, 1, wx.EXPAND) self.SetSizer(s) self.selection.Bind( RB.EVT_RIBBONBUTTONBAR_CLICKED, self.onDelete, id=self.BUTTON_DELETE, ) def onDelete(self, event): try: self.selection.DeleteButton(self.demobutton.id) except Exception as ex: self._logwindow.AppendText(traceback.format_exc()) self._logwindow.AppendText("\n") app = wx.App(0) frame = MyFrame(None) app.SetTopWindow(frame) frame.Show() app.MainLoop() ```