Skip to content

Commit

Permalink
gui development
Browse files Browse the repository at this point in the history
  • Loading branch information
ojdf committed Sep 2, 2024
1 parent 41c2e5b commit cc659ed
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
6 changes: 3 additions & 3 deletions fast/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,11 @@ def __repr__(self):
PARAMS = [
FastParam("NPXLS", "auto", "Simulation", bounds=[0,None], allowed_values=["auto"]),
FastParam("DX", "auto", "Simulation", bounds=[0,None], allowed_values=["auto"], unit="m/pixel"),
FastParam("NITER", 1000, "Simulation", bounds=[0,None]),
FastParam("NCHUNKS", 10, "Simulation", bounds=[0,None]),
FastParam("NITER", 1000, "Simulation", bounds=[1,None]),
FastParam("NCHUNKS", 10, "Simulation", bounds=[1,None]),
FastParam("SUBHARM", False, "Simulation"),
FastParam("FFTW", False, "Simulation"),
FastParam("FFTW_THREADS", 1, "Simulation", bounds=[0,None]),
FastParam("FFTW_THREADS", 1, "Simulation", bounds=[1,None]),
FastParam("TEMPORAL", False, "Simulation"),
FastParam("DT", 0.001, "Simulation", bounds=[0,None], unit="s"),
FastParam("LOGFILE", None, "Simulation", allowed_values=[None, "*"]),
Expand Down
46 changes: 39 additions & 7 deletions gui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
import fast
import numpy

CONFIG = None
CONFIG = fast.conf.PARAMS
CATEGORIES = list(dict.fromkeys([i._category for i in fast.conf.PARAMS]).keys())
ELEMENTS = {}


def load_config(e: events.UploadEventArguments):
content = e.content.read().decode()
exec(content, locals())
CONFIG = fast.conf.ConfigParser(locals()['p']).config
print(CONFIG)
c = fast.conf.ConfigParser(locals()['p']).config

for param in c:
CONFIG[param] = c[param]


def add_number_box_bounds(param):
Expand Down Expand Up @@ -107,9 +109,38 @@ def add_param(param):
return elements


def handle_change(e, param):
def handle_change(e, param, elems):
print(e, param)
s = e.sender

value = e.value

# different rules for checkboxes
if type(s) == ui.checkbox:
if e.value:
# if checked, set number value to None
value = s.text
if value == "None":
value = None
elems[0].set_value(None)
else:
# if unchecked, force number value to be entered (is this possible?)
elems[0].run_method("focus")

try:
param.value = value
s.clear()
except ValueError as err:
with s:
ui.tooltip(err.args[0]).classes("bg-red")

print(param)

def init_sim():
sim = fast.Fast(CONFIG)
return sim

ui.label(f"FAST {fast.__version__}").classes("font-mono text-4xl")

with ui.tabs().classes("w-full") as tabs:
config_tab = ui.tab("Configuration")
Expand All @@ -131,18 +162,19 @@ def handle_change(e, param):

ui.label(c)

for param in fast.conf.PARAMS:
for param in CONFIG:

if param._category == c:

elems = add_param(param)
ELEMENTS[param.name] = elems
for elem in elems:
elem.on_value_change(lambda e, param=param: handle_change(e, param))
elem.on_value_change(lambda e, param=param,
elems=elems: handle_change(e, param, elems))


with ui.tab_panel(sim_tab):
ui.label("Simulation")
ui.button("Initialise", on_click=init_sim)

with ui.tab_panel(results_tab):
ui.label("Results")
Expand Down

0 comments on commit cc659ed

Please sign in to comment.