diff --git a/pyzebra/app/app.py b/pyzebra/app/app.py index bc797b6..8a78459 100644 --- a/pyzebra/app/app.py +++ b/pyzebra/app/app.py @@ -4,7 +4,7 @@ from io import StringIO from bokeh.io import curdoc from bokeh.layouts import column, row -from bokeh.models import Tabs, TextAreaInput +from bokeh.models import Panel, Tabs, TextAreaInput, TextInput import panel_ccl_integrate import panel_hdf_anatric @@ -13,7 +13,6 @@ import panel_hdf_viewer import panel_param_study import panel_spind - doc = curdoc() sys.stdout = StringIO() @@ -26,11 +25,15 @@ bokeh_logger = logging.getLogger("bokeh") bokeh_logger.addHandler(bokeh_handler) bokeh_log_textareainput = TextAreaInput(title="server output:", height=150) +proposal_textinput = TextInput(title="Proposal number:", width=210) +doc.proposal_textinput = proposal_textinput + # Final layout doc.add_root( column( Tabs( tabs=[ + Panel(child=proposal_textinput, title="user config"), panel_hdf_viewer.create(), panel_hdf_anatric.create(), panel_ccl_integrate.create(), diff --git a/pyzebra/app/panel_ccl_integrate.py b/pyzebra/app/panel_ccl_integrate.py index 8e36147..8d8105d 100644 --- a/pyzebra/app/panel_ccl_integrate.py +++ b/pyzebra/app/panel_ccl_integrate.py @@ -105,7 +105,7 @@ def create(): def proposal_textinput_callback(_attr, _old, _new): file_select_update_for_proposal() - proposal_textinput = TextInput(title="Proposal number:", width=210) + proposal_textinput = doc.proposal_textinput proposal_textinput.on_change("value", proposal_textinput_callback) def _init_datatable(): @@ -163,7 +163,6 @@ def create(): def upload_button_callback(_attr, _old, new): nonlocal det_data det_data = [] - proposal_textinput.value = "" for f_str, f_name in zip(new, upload_button.filename): with io.StringIO(base64.b64decode(f_str).decode()) as file: base, ext = os.path.splitext(f_name) @@ -598,7 +597,6 @@ def create(): ) import_layout = column( - proposal_textinput, file_select, row(file_open_button, file_append_button), upload_div, diff --git a/pyzebra/app/panel_hdf_param_study.py b/pyzebra/app/panel_hdf_param_study.py index 8768734..7985322 100644 --- a/pyzebra/app/panel_hdf_param_study.py +++ b/pyzebra/app/panel_hdf_param_study.py @@ -56,42 +56,60 @@ def create(): num_formatter = NumberFormatter(format="0.00", nan_format="") - def file_select_update_for_proposal(): - proposal = proposal_textinput.value.strip() - if not proposal: - return + def file_select_update(): + if data_source.value == "proposal number": + proposal = proposal_textinput.value.strip() + if not proposal: + file_select.options = [] + return - for zebra_proposals_path in pyzebra.ZEBRA_PROPOSALS_PATHS: - proposal_path = os.path.join(zebra_proposals_path, proposal) - if os.path.isdir(proposal_path): - # found it - break - else: - raise ValueError(f"Can not find data for proposal '{proposal}'.") + for zebra_proposals_path in pyzebra.ZEBRA_PROPOSALS_PATHS: + proposal_path = os.path.join(zebra_proposals_path, proposal) + if os.path.isdir(proposal_path): + # found it + break + else: + raise ValueError(f"Can not find data for proposal '{proposal}'.") - file_list = [] - for file in os.listdir(proposal_path): - if file.endswith(".hdf"): - file_list.append((os.path.join(proposal_path, file), file)) - file_select.options = file_list + file_list = [] + for file in os.listdir(proposal_path): + if file.endswith(".hdf"): + file_list.append((os.path.join(proposal_path, file), file)) + file_select.options = file_list - doc.add_periodic_callback(file_select_update_for_proposal, 5000) + else: # "cami file" + if not cami_meta: + file_select.options = [] + return + + file_list = cami_meta["filelist"] + file_select.options = [(entry, os.path.basename(entry)) for entry in file_list] + + def data_source_callback(_attr, _old, _new): + file_select_update() + + data_source = Select( + title="Data Source:", + value="proposal number", + options=["proposal number", "cami file"], + width=210, + ) + data_source.on_change("value", data_source_callback) + + doc.add_periodic_callback(file_select_update, 5000) def proposal_textinput_callback(_attr, _old, _new): - nonlocal cami_meta - cami_meta = {} - file_select_update_for_proposal() + file_select_update() - proposal_textinput = TextInput(title="Proposal number:", width=210) + proposal_textinput = doc.proposal_textinput proposal_textinput.on_change("value", proposal_textinput_callback) def upload_button_callback(_attr, _old, new): nonlocal cami_meta - proposal_textinput.value = "" with io.StringIO(base64.b64decode(new).decode()) as file: cami_meta = pyzebra.parse_h5meta(file) - file_list = cami_meta["filelist"] - file_select.options = [(entry, os.path.basename(entry)) for entry in file_list] + data_source.value = "cami file" + file_select_update() upload_div = Div(text="or upload .cami file:", margin=(5, 5, 0, 5)) upload_button = FileInput(accept=".cami", width=200) @@ -603,7 +621,7 @@ def create(): # Final layout import_layout = column( - proposal_textinput, + data_source, upload_div, upload_button, file_select, diff --git a/pyzebra/app/panel_hdf_viewer.py b/pyzebra/app/panel_hdf_viewer.py index 8377712..37a325a 100644 --- a/pyzebra/app/panel_hdf_viewer.py +++ b/pyzebra/app/panel_hdf_viewer.py @@ -59,42 +59,60 @@ def create(): num_formatter = NumberFormatter(format="0.00", nan_format="") - def file_select_update_for_proposal(): - proposal = proposal_textinput.value.strip() - if not proposal: - return + def file_select_update(): + if data_source.value == "proposal number": + proposal = proposal_textinput.value.strip() + if not proposal: + file_select.options = [] + return - for zebra_proposals_path in pyzebra.ZEBRA_PROPOSALS_PATHS: - proposal_path = os.path.join(zebra_proposals_path, proposal) - if os.path.isdir(proposal_path): - # found it - break - else: - raise ValueError(f"Can not find data for proposal '{proposal}'.") + for zebra_proposals_path in pyzebra.ZEBRA_PROPOSALS_PATHS: + proposal_path = os.path.join(zebra_proposals_path, proposal) + if os.path.isdir(proposal_path): + # found it + break + else: + raise ValueError(f"Can not find data for proposal '{proposal}'.") - file_list = [] - for file in os.listdir(proposal_path): - if file.endswith(".hdf"): - file_list.append((os.path.join(proposal_path, file), file)) - file_select.options = file_list + file_list = [] + for file in os.listdir(proposal_path): + if file.endswith(".hdf"): + file_list.append((os.path.join(proposal_path, file), file)) + file_select.options = file_list - doc.add_periodic_callback(file_select_update_for_proposal, 5000) + else: # "cami file" + if not cami_meta: + file_select.options = [] + return + + file_list = cami_meta["filelist"] + file_select.options = [(entry, os.path.basename(entry)) for entry in file_list] + + def data_source_callback(_attr, _old, _new): + file_select_update() + + data_source = Select( + title="Data Source:", + value="proposal number", + options=["proposal number", "cami file"], + width=210, + ) + data_source.on_change("value", data_source_callback) + + doc.add_periodic_callback(file_select_update, 5000) def proposal_textinput_callback(_attr, _old, _new): - nonlocal cami_meta - cami_meta = {} - file_select_update_for_proposal() + file_select_update() - proposal_textinput = TextInput(title="Proposal number:", width=210) + proposal_textinput = doc.proposal_textinput proposal_textinput.on_change("value", proposal_textinput_callback) def upload_button_callback(_attr, _old, new): nonlocal cami_meta - proposal_textinput.value = "" with io.StringIO(base64.b64decode(new).decode()) as file: cami_meta = pyzebra.parse_h5meta(file) - file_list = cami_meta["filelist"] - file_select.options = [(entry, os.path.basename(entry)) for entry in file_list] + data_source.value = "cami file" + file_select_update() upload_div = Div(text="or upload .cami file:", margin=(5, 5, 0, 5)) upload_button = FileInput(accept=".cami", width=200) @@ -731,7 +749,7 @@ def create(): ) # Final layout - import_layout = column(proposal_textinput, upload_div, upload_button, file_select) + import_layout = column(data_source, upload_div, upload_button, file_select) layout_image = column(gridplot([[proj_v, None], [plot, proj_h]], merge_tools=False)) colormap_layout = column( colormap, diff --git a/pyzebra/app/panel_param_study.py b/pyzebra/app/panel_param_study.py index 5b78aa6..fdc6372 100644 --- a/pyzebra/app/panel_param_study.py +++ b/pyzebra/app/panel_param_study.py @@ -115,7 +115,7 @@ def create(): def proposal_textinput_callback(_attr, _old, _new): file_select_update_for_proposal() - proposal_textinput = TextInput(title="Proposal number:", width=210) + proposal_textinput = doc.proposal_textinput proposal_textinput.on_change("value", proposal_textinput_callback) def _init_datatable(): @@ -178,7 +178,6 @@ def create(): def upload_button_callback(_attr, _old, new): nonlocal det_data det_data = [] - proposal_textinput.value = "" for f_str, f_name in zip(new, upload_button.filename): with io.StringIO(base64.b64decode(f_str).decode()) as file: base, ext = os.path.splitext(f_name) @@ -748,7 +747,6 @@ def create(): scan_layout = column(scan_table, row(monitor_spinner, scan_motor_select, param_select)) import_layout = column( - proposal_textinput, file_select, row(file_open_button, file_append_button), upload_div,