0

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()
GreenAsJade
  • 14,459
  • 11
  • 63
  • 98
Samyak
  • 109
  • 2
  • 8
  • I'm having trouble connecting the error message you've shown us with the code the you've shown us. Can you clarify how they are related? I was expecting the error message to be referring to some of this code you've shown us. – GreenAsJade Feb 02 '14 at 12:00
  • Dear GreenAsJade, Thanks a lot for giving time to my problem and trying my code. I have found the error myself after trying for a long time. I am sorry for not providing you 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. – Samyak Feb 02 '14 at 13:12
  • I'm glad your problem is solved. When confronted with a situation where you can't post the entire code, it can be useful to strip the problem down to an amount of code you can post: often this will help you find the problem anyhow :) – GreenAsJade Feb 02 '14 at 21:15

1 Answers1

0

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.

Samyak
  • 109
  • 2
  • 8