Pregunta

I am building a GUI using wxribbon of wxpython. The wxribbon is dynamic and user can add pages and panels. When user closes the ribbon, I am saving names and number of pages and panels in a json file before destroying the ribbon. On restoring the state, I read from json file and recreate my ribbon state, but when user want to now make changes to ribbon panel, only the last recreated panel works and for all the panels before the last one, I get following error :

 **self.Bind(wx.EVT_MENU, lambda event: self.RemoveGroupBox(event, panel), RemoveGroupBox)
  File "C:/Users/Samyak/Desktop/Japan_SRC/test/src/GUI/Trial Ribbon.py", line 327, in RemoveGroupBox
    for child in newpanel.GetChildren():
  File "C:\Python27\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 14619, in __getattr__
    raise PyDeadObjectError(self.attrStr % self._name)
wx._core.PyDeadObjectError: The C++ part of the RibbonPanel object has been deleted, attribute access no longer allowed.**

The code I am using to restore my ribbon state is as follows: Please help me... Thanks a lot

    if os.path.exists(CONFIGFILE):
        with open(CONFIGFILE, 'r') as f:
            data = json.load(f)
        self.newpanel = []
        for Page in data['pages']:
            label = Page['label']
            name = Page['name']
            newpage = RB.RibbonPage(self._ribbon,wx.ID_ANY, Page['label'],Bitmap("eye.xpm"))
                for panels in Page['Panel']:
                    pagelabel = panels['labelpanel']
                    self.newpanel.append(RB.RibbonPanel(newpage,wx.ID_ANY,pagelabel,Bitmap("selection_panel.xpm")))
                    length = len(self.newpanel)
                    self.newpanel[length-1].Bind(wx.EVT_RIGHT_UP, lambda event: self.RightClickRibbonPageBox(event, self.newpanel[length-1]))                

        currentpage = data['activepage']
        self._ribbon.SetActivePage(currentpage)
        self._ribbon.Realize()
¿Fue útil?

Solución

I have found the error myself after trying for a long time. I am sorry for not providing the entire code as it was really big. The problem I was having was that I was not checking the condition of

"if isinstance(child, RB.RibbonPanel):".

while recreating ribbon from json file.After using it everything works fine.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top