I am writing a wxpython GUI application where I have used wxribbon which is dynamic in nature. It(the ribbon) allows users to add panels and then in each panel add buttons according to their need. Now when user closes the window, I want to save the current state of ribbon with the number and names of tabs, panels(in each tab) and then buttons(in each panel) and then load it when user again runs the application. I am able to save only page till now as I am not able to find a correct way to nest for loops while writing json file. Here is a sample code of what I am doing. Any help will be great.. Thank You...
def save(self):
pages = [{'label': child.GetLabel()}
for child in self._ribbon.GetChildren()
if isinstance(child, RB.RibbonPage)]
#panels = [] #It will be nested above inside each page
#buttons = [] #It will be nested inside each panel
activepage = self._ribbon.GetActivePage()
data = {
'activepage':activepage,
'pages':pages,
}
with open(CONFIGFILE, 'w') as f:
json.dump(data, f)
def load(self):
with open(CONFIGFILE, 'r') as f:
data = json.load(f)
for Page in data['pages']:
label = Page['label']
newpage = RB.RibbonPage(self._ribbon,wx.ID_ANY, Page['label'],Bitmap("eye.xpm"))
currentpage = data['activepage']
self._ribbon.SetActivePage(currentpage)
self._ribbon.Realize()