Skip to content

Commit

Permalink
Added optional model bowser to GUI bar
Browse files Browse the repository at this point in the history
Added container browser
  • Loading branch information
highperformancecoder committed Oct 9, 2024
1 parent a96b7f9 commit 5722e7f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
5 changes: 4 additions & 1 deletion lib/GUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=[]
Expand Down Expand Up @@ -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))
Expand All @@ -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:
Expand Down
34 changes: 32 additions & 2 deletions lib/objectBrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('<Double-Button-1>',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))!="<class 'CppWrapperType'>":
Expand Down
5 changes: 1 addition & 4 deletions models/panmictic_ecolab.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)



0 comments on commit 5722e7f

Please sign in to comment.