diff --git a/lib/GUI.py b/lib/GUI.py index 5d66384..598ee6a 100644 --- a/lib/GUI.py +++ b/lib/GUI.py @@ -3,6 +3,7 @@ from ecolab import registerParallel registerParallel() from ecolab import Parallel, myid +from objectBrowser import Browser # list of windows to update each simulation step windows=[] @@ -34,7 +35,7 @@ def exit(self): self.parallel.exit() exit() -def gui(step): +def gui(step,model=None): simulator=Simulator(step) if myid()>0: return windows.append(ref(runner)) @@ -44,6 +45,8 @@ def gui(step): ttk.Button(buttonBar,text="run",command=simulator).pack(side='left') ttk.Button(buttonBar,text="step",command=simulator.doStep).pack(side='left') ttk.Button(buttonBar,text="stop",command=simulator.stop).pack(side='left') + if model!=None: + ttk.Button(buttonBar,text="browse",command=lambda: Browser(model)).pack(side='left') try: runner.mainloop() except SystemExit: diff --git a/lib/objectBrowser.py b/lib/objectBrowser.py index 181a849..fa99599 100644 --- a/lib/objectBrowser.py +++ b/lib/objectBrowser.py @@ -15,13 +15,43 @@ def doMethod(event): Browser(member,selection[:-1]) else: selection=selection.split('=')[0] - args=json.loads('['+listbox.args.get('1.0','end')+']') - val=getattr(listbox.object,selection)(*args) + member=getattr(listbox.object,selection) + val=member(*args) listbox.delete(index) listbox.insert(index,selection+'='+str(val)) listbox.itemconfigure(index,foreground='blue') + if len(member)>0: + containerBrowser=Tk() + containerBrowser.wm_title(selection) + elements=Listbox(containerBrowser) + elements.pack(fill='both',expand=True) + if '.@keys' in member._list(): + elements.insert('end',member.keys()) + else: + for i in range(len(member)): + elements.insert('end',str(i)) + elements.bind('',doElement) + elements.object=member + elements.title=selection + +def doElement(event): + listbox=event.widget + selectedItems=listbox.curselection() + if len(selectedItems)==0: return + index=selectedItems[0] + selection=listbox.get(index) + selection=selection.split('=')[0] + element=listbox.object[selection] if '.@keys' in listbox.object._list() \ + else listbox.object[int(selection)] + if len(element._list())>0: + Browser(element,f'{listbox.title}[{selection}]') + else: + val=element() + listbox.delete(index) + listbox.insert(index,selection+'='+str(val)) + class Browser: def __init__(self, object, title=''): if str(type(object))!="": diff --git a/models/panmictic_ecolab.py b/models/panmictic_ecolab.py index c65ac29..e60257b 100644 --- a/models/panmictic_ecolab.py +++ b/models/panmictic_ecolab.py @@ -50,10 +50,7 @@ def step(): plot('No. species',ecolab.tstep(),nsp) plot('Density',ecolab.tstep(),ecolab.density(), pens=ecolab.species()) -from objectBrowser import Browser -browser=Browser(ecolab,'ecolab') - -gui(step) +gui(step,ecolab)