Skip to content

Commit

Permalink
more gui developments (not working yet)
Browse files Browse the repository at this point in the history
  • Loading branch information
ojdf committed Sep 25, 2024
1 parent cc659ed commit 5f9f13e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 6 deletions.
46 changes: 40 additions & 6 deletions gui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
import fast
import numpy

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


def load_config(e: events.UploadEventArguments):
Expand All @@ -13,7 +14,8 @@ def load_config(e: events.UploadEventArguments):
c = fast.conf.ConfigParser(locals()['p']).config

for param in c:
CONFIG[param] = c[param]
CONFIG[param].value = c[param]
change_value(CONFIG[param], c[param], ELEMENTS[param])


def add_number_box_bounds(param):
Expand Down Expand Up @@ -109,12 +111,33 @@ def add_param(param):
return elements


def change_value(param, value, elems):

if value in ["auto" or "opt"] or numpy.isinf(value) or value is None:
elems[0].set_value(None)
elems[1].set_value(True)

elif value in [True, False] or isinstance(value, str):
elems[0].set_value(value)

elif isinstance(value, numpy.ndarray):
for elem, val in zip(elems, value):
elem.set_value(val)




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

value = e.value

# convert to int for certain values
if param.name in ["NPXLS", "NITER", "NCHUNKS", "FFTW_THREADS", "SEED"]:
if type(value) is float:
value = int(value)

# different rules for checkboxes
if type(s) == ui.checkbox:
if e.value:
Expand All @@ -137,8 +160,15 @@ def handle_change(e, param, elems):
print(param)

def init_sim():
sim = fast.Fast(CONFIG)
return sim
try:
SIM = fast.Fast(fast.conf.FastConfig(CONFIG))
except Exception as e:
with ui.dialog() as dialog, ui.card():
ui.label("Error in initialising simulation:")
ui.label(e.args[0])
ui.button('Close', on_click=dialog.close)
dialog.open()


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

Expand All @@ -151,6 +181,8 @@ def init_sim():

with ui.tab_panel(config_tab):

ui.button("PRINT DEBUG", on_click=lambda x: print(CONFIG))

with ui.column().classes("justify-center"):
ui.upload(label="Load Config File", on_upload=load_config).props('accept=.py')

Expand All @@ -162,7 +194,9 @@ def init_sim():

ui.label(c)

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

CONFIG[param.name] = param

if param._category == c:

Expand All @@ -171,7 +205,7 @@ def init_sim():
for elem in elems:
elem.on_value_change(lambda e, param=param,
elems=elems: handle_change(e, param, elems))


with ui.tab_panel(sim_tab):
ui.button("Initialise", on_click=init_sim)
Expand Down
15 changes: 15 additions & 0 deletions gui/gui_params.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

class GUIParam():
"""
Base class for GUI params. Brings together FAST parameter and GUI elements
so that they stay in sync.
Parameters:
param (FASTParam): FAST config parameter object
"""
def __init__(self, param):

self.elements = []
self.param = param


0 comments on commit 5f9f13e

Please sign in to comment.