Add Apply button to proposal selection
This commit is contained in:
parent
a73c34b06f
commit
a77a40618d
@ -1,11 +1,8 @@
|
||||
from pyzebra.anatric import *
|
||||
from pyzebra.ccl_io import *
|
||||
from pyzebra.h5 import *
|
||||
from pyzebra.xtal import *
|
||||
from pyzebra.ccl_process import *
|
||||
|
||||
ZEBRA_PROPOSALS_PATHS = [
|
||||
f"/afs/psi.ch/project/sinqdata/{year}/zebra/" for year in (2016, 2017, 2018, 2020, 2021)
|
||||
]
|
||||
from pyzebra.h5 import *
|
||||
from pyzebra.utils import *
|
||||
from pyzebra.xtal import *
|
||||
|
||||
__version__ = "0.5.0"
|
||||
|
@ -2,9 +2,10 @@ import logging
|
||||
import sys
|
||||
from io import StringIO
|
||||
|
||||
import pyzebra
|
||||
from bokeh.io import curdoc
|
||||
from bokeh.layouts import column, row
|
||||
from bokeh.models import Panel, Tabs, TextAreaInput, TextInput
|
||||
from bokeh.models import Button, Panel, Tabs, TextAreaInput, TextInput
|
||||
|
||||
import panel_ccl_integrate
|
||||
import panel_hdf_anatric
|
||||
@ -25,15 +26,32 @@ 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)
|
||||
def proposal_textinput_callback(_attr, _old, _new):
|
||||
apply_button.disabled = False
|
||||
|
||||
proposal_textinput = TextInput(title="Proposal number:", name="")
|
||||
proposal_textinput.on_change("value_input", proposal_textinput_callback)
|
||||
doc.proposal_textinput = proposal_textinput
|
||||
|
||||
def apply_button_callback():
|
||||
try:
|
||||
proposal_path = pyzebra.find_proposal_path(proposal_textinput.value)
|
||||
except ValueError as e:
|
||||
print(e)
|
||||
return
|
||||
|
||||
proposal_textinput.name = proposal_path
|
||||
apply_button.disabled = True
|
||||
|
||||
apply_button = Button(label="Apply", button_type="primary")
|
||||
apply_button.on_click(apply_button_callback)
|
||||
|
||||
# Final layout
|
||||
doc.add_root(
|
||||
column(
|
||||
Tabs(
|
||||
tabs=[
|
||||
Panel(child=proposal_textinput, title="user config"),
|
||||
Panel(child=column(proposal_textinput, apply_button), title="user config"),
|
||||
panel_hdf_viewer.create(),
|
||||
panel_hdf_anatric.create(),
|
||||
panel_ccl_integrate.create(),
|
||||
|
@ -76,28 +76,19 @@ def create():
|
||||
js_data = ColumnDataSource(data=dict(content=["", ""], fname=["", ""], ext=["", ""]))
|
||||
|
||||
def file_select_update_for_proposal():
|
||||
proposal = proposal_textinput.value.strip()
|
||||
if not proposal:
|
||||
proposal_path = proposal_textinput.name
|
||||
if proposal_path:
|
||||
file_list = []
|
||||
for file in os.listdir(proposal_path):
|
||||
if file.endswith((".ccl", ".dat")):
|
||||
file_list.append((os.path.join(proposal_path, file), file))
|
||||
file_select.options = file_list
|
||||
file_open_button.disabled = False
|
||||
file_append_button.disabled = False
|
||||
else:
|
||||
file_select.options = []
|
||||
file_open_button.disabled = True
|
||||
file_append_button.disabled = True
|
||||
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}'.")
|
||||
|
||||
file_list = []
|
||||
for file in os.listdir(proposal_path):
|
||||
if file.endswith((".ccl", ".dat")):
|
||||
file_list.append((os.path.join(proposal_path, file), file))
|
||||
file_select.options = file_list
|
||||
file_open_button.disabled = False
|
||||
file_append_button.disabled = False
|
||||
|
||||
doc.add_periodic_callback(file_select_update_for_proposal, 5000)
|
||||
|
||||
@ -105,7 +96,7 @@ def create():
|
||||
file_select_update_for_proposal()
|
||||
|
||||
proposal_textinput = doc.proposal_textinput
|
||||
proposal_textinput.on_change("value", proposal_textinput_callback)
|
||||
proposal_textinput.on_change("name", proposal_textinput_callback)
|
||||
|
||||
def _init_datatable():
|
||||
scan_list = [s["idx"] for s in det_data]
|
||||
|
@ -57,24 +57,15 @@ def create():
|
||||
|
||||
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
|
||||
proposal_path = proposal_textinput.name
|
||||
if proposal_path:
|
||||
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
|
||||
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_select.options = []
|
||||
|
||||
else: # "cami file"
|
||||
if not cami_meta:
|
||||
@ -101,7 +92,7 @@ def create():
|
||||
file_select_update()
|
||||
|
||||
proposal_textinput = doc.proposal_textinput
|
||||
proposal_textinput.on_change("value", proposal_textinput_callback)
|
||||
proposal_textinput.on_change("name", proposal_textinput_callback)
|
||||
|
||||
def upload_button_callback(_attr, _old, new):
|
||||
nonlocal cami_meta
|
||||
|
@ -60,24 +60,15 @@ def create():
|
||||
|
||||
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
|
||||
proposal_path = proposal_textinput.name
|
||||
if proposal_path:
|
||||
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
|
||||
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_select.options = []
|
||||
|
||||
else: # "cami file"
|
||||
if not cami_meta:
|
||||
@ -104,7 +95,7 @@ def create():
|
||||
file_select_update()
|
||||
|
||||
proposal_textinput = doc.proposal_textinput
|
||||
proposal_textinput.on_change("value", proposal_textinput_callback)
|
||||
proposal_textinput.on_change("name", proposal_textinput_callback)
|
||||
|
||||
def upload_button_callback(_attr, _old, new):
|
||||
nonlocal cami_meta
|
||||
|
@ -86,28 +86,19 @@ def create():
|
||||
js_data = ColumnDataSource(data=dict(content=[""], fname=[""], ext=[""]))
|
||||
|
||||
def file_select_update_for_proposal():
|
||||
proposal = proposal_textinput.value.strip()
|
||||
if not proposal:
|
||||
proposal_path = proposal_textinput.name
|
||||
if proposal_path:
|
||||
file_list = []
|
||||
for file in os.listdir(proposal_path):
|
||||
if file.endswith((".ccl", ".dat")):
|
||||
file_list.append((os.path.join(proposal_path, file), file))
|
||||
file_select.options = file_list
|
||||
file_open_button.disabled = False
|
||||
file_append_button.disabled = False
|
||||
else:
|
||||
file_select.options = []
|
||||
file_open_button.disabled = True
|
||||
file_append_button.disabled = True
|
||||
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}'.")
|
||||
|
||||
file_list = []
|
||||
for file in os.listdir(proposal_path):
|
||||
if file.endswith((".ccl", ".dat")):
|
||||
file_list.append((os.path.join(proposal_path, file), file))
|
||||
file_select.options = file_list
|
||||
file_open_button.disabled = False
|
||||
file_append_button.disabled = False
|
||||
|
||||
doc.add_periodic_callback(file_select_update_for_proposal, 5000)
|
||||
|
||||
@ -115,7 +106,7 @@ def create():
|
||||
file_select_update_for_proposal()
|
||||
|
||||
proposal_textinput = doc.proposal_textinput
|
||||
proposal_textinput.on_change("value", proposal_textinput_callback)
|
||||
proposal_textinput.on_change("name", proposal_textinput_callback)
|
||||
|
||||
def _init_datatable():
|
||||
scan_list = [s["idx"] for s in det_data]
|
||||
|
20
pyzebra/utils.py
Normal file
20
pyzebra/utils.py
Normal file
@ -0,0 +1,20 @@
|
||||
import os
|
||||
|
||||
ZEBRA_PROPOSALS_PATHS = [
|
||||
f"/afs/psi.ch/project/sinqdata/{year}/zebra/" for year in (2016, 2017, 2018, 2020, 2021)
|
||||
]
|
||||
|
||||
def find_proposal_path(proposal):
|
||||
proposal = proposal.strip()
|
||||
if proposal:
|
||||
for zebra_proposals_path in 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}'.")
|
||||
else:
|
||||
proposal_path = ""
|
||||
|
||||
return proposal_path
|
Loading…
x
Reference in New Issue
Block a user