Simplify data provision for js file export
This commit is contained in:
parent
ce5cff05a7
commit
d606230feb
@ -46,16 +46,19 @@ from pyzebra.ccl_io import AREA_METHODS
|
|||||||
|
|
||||||
|
|
||||||
javaScript = """
|
javaScript = """
|
||||||
if (js_data.data['content'][0] === "") return 0;
|
for (let i = 0; i < js_data.data['fname'].length; i++) {
|
||||||
const blob = new Blob(js_data.data['content'], {type: 'text/plain'})
|
if (js_data.data['content'][i] === "") continue;
|
||||||
const link = document.createElement('a');
|
|
||||||
document.body.appendChild(link);
|
const blob = new Blob([js_data.data['content'][i]], {type: 'text/plain'})
|
||||||
const url = window.URL.createObjectURL(blob);
|
const link = document.createElement('a');
|
||||||
link.href = url;
|
document.body.appendChild(link);
|
||||||
link.download = js_data.data['fname'][0];
|
const url = window.URL.createObjectURL(blob);
|
||||||
link.click();
|
link.href = url;
|
||||||
window.URL.revokeObjectURL(url);
|
link.download = js_data.data['fname'][i];
|
||||||
document.body.removeChild(link);
|
link.click();
|
||||||
|
window.URL.revokeObjectURL(url);
|
||||||
|
document.body.removeChild(link);
|
||||||
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
PROPOSAL_PATH = "/afs/psi.ch/project/sinqdata/2020/zebra/"
|
PROPOSAL_PATH = "/afs/psi.ch/project/sinqdata/2020/zebra/"
|
||||||
@ -64,10 +67,7 @@ PROPOSAL_PATH = "/afs/psi.ch/project/sinqdata/2020/zebra/"
|
|||||||
def create():
|
def create():
|
||||||
det_data = {}
|
det_data = {}
|
||||||
fit_params = {}
|
fit_params = {}
|
||||||
js_data = {
|
js_data = ColumnDataSource(data=dict(content=["", ""], fname=["", ""]))
|
||||||
".comm": ColumnDataSource(data=dict(content=[""], fname=[""])),
|
|
||||||
".incomm": ColumnDataSource(data=dict(content=[""], fname=[""])),
|
|
||||||
}
|
|
||||||
|
|
||||||
def proposal_textinput_callback(_attr, _old, new):
|
def proposal_textinput_callback(_attr, _old, new):
|
||||||
ccl_path = os.path.join(PROPOSAL_PATH, new.strip())
|
ccl_path = os.path.join(PROPOSAL_PATH, new.strip())
|
||||||
@ -116,8 +116,7 @@ def create():
|
|||||||
det_data = pyzebra.parse_1D(file, ext)
|
det_data = pyzebra.parse_1D(file, ext)
|
||||||
pyzebra.normalize_dataset(det_data, monitor_spinner.value)
|
pyzebra.normalize_dataset(det_data, monitor_spinner.value)
|
||||||
pyzebra.merge_duplicates(det_data)
|
pyzebra.merge_duplicates(det_data)
|
||||||
js_data[".comm"].data.update(fname=[base + ".comm"])
|
js_data.data.update(fname=[base + ".comm", base + ".incomm"])
|
||||||
js_data[".incomm"].data.update(fname=[base + ".incomm"])
|
|
||||||
|
|
||||||
_init_datatable()
|
_init_datatable()
|
||||||
|
|
||||||
@ -152,8 +151,7 @@ def create():
|
|||||||
det_data = pyzebra.parse_1D(file, ext)
|
det_data = pyzebra.parse_1D(file, ext)
|
||||||
pyzebra.normalize_dataset(det_data, monitor_spinner.value)
|
pyzebra.normalize_dataset(det_data, monitor_spinner.value)
|
||||||
pyzebra.merge_duplicates(det_data)
|
pyzebra.merge_duplicates(det_data)
|
||||||
js_data[".comm"].data.update(fname=[base + ".comm"])
|
js_data.data.update(fname=[base + ".comm", base + ".incomm"])
|
||||||
js_data[".incomm"].data.update(fname=[base + ".incomm"])
|
|
||||||
|
|
||||||
_init_datatable()
|
_init_datatable()
|
||||||
|
|
||||||
@ -477,6 +475,7 @@ def create():
|
|||||||
)
|
)
|
||||||
|
|
||||||
exported_content = ""
|
exported_content = ""
|
||||||
|
file_content = []
|
||||||
for ext in (".comm", ".incomm"):
|
for ext in (".comm", ".incomm"):
|
||||||
fname = temp_file + ext
|
fname = temp_file + ext
|
||||||
if os.path.isfile(fname):
|
if os.path.isfile(fname):
|
||||||
@ -485,9 +484,9 @@ def create():
|
|||||||
exported_content += f"{ext} file:\n" + content
|
exported_content += f"{ext} file:\n" + content
|
||||||
else:
|
else:
|
||||||
content = ""
|
content = ""
|
||||||
|
file_content.append(content)
|
||||||
|
|
||||||
js_data[ext].data.update(content=[content])
|
js_data.data.update(content=file_content)
|
||||||
|
|
||||||
export_preview_textinput.value = exported_content
|
export_preview_textinput.value = exported_content
|
||||||
|
|
||||||
preview_button = Button(label="Preview", default_size=200)
|
preview_button = Button(label="Preview", default_size=200)
|
||||||
@ -498,8 +497,7 @@ def create():
|
|||||||
)
|
)
|
||||||
|
|
||||||
save_button = Button(label="Download preview", button_type="success", default_size=200)
|
save_button = Button(label="Download preview", button_type="success", default_size=200)
|
||||||
save_button.js_on_click(CustomJS(args={"js_data": js_data[".comm"]}, code=javaScript))
|
save_button.js_on_click(CustomJS(args={"js_data": js_data}, code=javaScript))
|
||||||
save_button.js_on_click(CustomJS(args={"js_data": js_data[".incomm"]}, code=javaScript))
|
|
||||||
|
|
||||||
fitpeak_controls = row(
|
fitpeak_controls = row(
|
||||||
column(fitparams_add_dropdown, fitparams_select, fitparams_remove_button),
|
column(fitparams_add_dropdown, fitparams_select, fitparams_remove_button),
|
||||||
|
@ -51,16 +51,19 @@ import pyzebra
|
|||||||
from pyzebra.ccl_io import AREA_METHODS
|
from pyzebra.ccl_io import AREA_METHODS
|
||||||
|
|
||||||
javaScript = """
|
javaScript = """
|
||||||
if (js_data.data['content'][0] === "") return 0;
|
for (let i = 0; i < js_data.data['fname'].length; i++) {
|
||||||
const blob = new Blob(js_data.data['content'], {type: 'text/plain'})
|
if (js_data.data['content'][i] === "") continue;
|
||||||
const link = document.createElement('a');
|
|
||||||
document.body.appendChild(link);
|
const blob = new Blob([js_data.data['content'][i]], {type: 'text/plain'})
|
||||||
const url = window.URL.createObjectURL(blob);
|
const link = document.createElement('a');
|
||||||
link.href = url;
|
document.body.appendChild(link);
|
||||||
link.download = js_data.data['fname'][0];
|
const url = window.URL.createObjectURL(blob);
|
||||||
link.click();
|
link.href = url;
|
||||||
window.URL.revokeObjectURL(url);
|
link.download = js_data.data['fname'][i];
|
||||||
document.body.removeChild(link);
|
link.click();
|
||||||
|
window.URL.revokeObjectURL(url);
|
||||||
|
document.body.removeChild(link);
|
||||||
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
PROPOSAL_PATH = "/afs/psi.ch/project/sinqdata/2020/zebra/"
|
PROPOSAL_PATH = "/afs/psi.ch/project/sinqdata/2020/zebra/"
|
||||||
@ -74,10 +77,7 @@ def color_palette(n_colors):
|
|||||||
def create():
|
def create():
|
||||||
det_data = []
|
det_data = []
|
||||||
fit_params = {}
|
fit_params = {}
|
||||||
js_data = {
|
js_data = ColumnDataSource(data=dict(content=["", ""], fname=["", ""]))
|
||||||
".comm": ColumnDataSource(data=dict(content=[""], fname=[""])),
|
|
||||||
".incomm": ColumnDataSource(data=dict(content=[""], fname=[""])),
|
|
||||||
}
|
|
||||||
|
|
||||||
def proposal_textinput_callback(_attr, _old, new):
|
def proposal_textinput_callback(_attr, _old, new):
|
||||||
full_proposal_path = os.path.join(PROPOSAL_PATH, new.strip())
|
full_proposal_path = os.path.join(PROPOSAL_PATH, new.strip())
|
||||||
@ -127,8 +127,7 @@ def create():
|
|||||||
else:
|
else:
|
||||||
det_data = pyzebra.parse_1D(file, ext)
|
det_data = pyzebra.parse_1D(file, ext)
|
||||||
pyzebra.normalize_dataset(det_data, monitor_spinner.value)
|
pyzebra.normalize_dataset(det_data, monitor_spinner.value)
|
||||||
js_data[".comm"].data.update(fname=[base + ".comm"])
|
js_data.data.update(fname=[base + ".comm", base + ".incomm"])
|
||||||
js_data[".incomm"].data.update(fname=[base + ".incomm"])
|
|
||||||
|
|
||||||
_init_datatable()
|
_init_datatable()
|
||||||
|
|
||||||
@ -162,8 +161,7 @@ def create():
|
|||||||
else:
|
else:
|
||||||
det_data = pyzebra.parse_1D(file, ext)
|
det_data = pyzebra.parse_1D(file, ext)
|
||||||
pyzebra.normalize_dataset(det_data, monitor_spinner.value)
|
pyzebra.normalize_dataset(det_data, monitor_spinner.value)
|
||||||
js_data[".comm"].data.update(fname=[base + ".comm"])
|
js_data.data.update(fname=[base + ".comm", base + ".incomm"])
|
||||||
js_data[".incomm"].data.update(fname=[base + ".incomm"])
|
|
||||||
|
|
||||||
_init_datatable()
|
_init_datatable()
|
||||||
|
|
||||||
@ -571,6 +569,7 @@ def create():
|
|||||||
)
|
)
|
||||||
|
|
||||||
exported_content = ""
|
exported_content = ""
|
||||||
|
file_content = []
|
||||||
for ext in (".comm", ".incomm"):
|
for ext in (".comm", ".incomm"):
|
||||||
fname = temp_file + ext
|
fname = temp_file + ext
|
||||||
if os.path.isfile(fname):
|
if os.path.isfile(fname):
|
||||||
@ -579,17 +578,16 @@ def create():
|
|||||||
exported_content += f"{ext} file:\n" + content
|
exported_content += f"{ext} file:\n" + content
|
||||||
else:
|
else:
|
||||||
content = ""
|
content = ""
|
||||||
|
file_content.append(content)
|
||||||
|
|
||||||
js_data[ext].data.update(content=[content])
|
js_data.data.update(content=file_content)
|
||||||
|
|
||||||
export_preview_textinput.value = exported_content
|
export_preview_textinput.value = exported_content
|
||||||
|
|
||||||
preview_button = Button(label="Preview", default_size=220)
|
preview_button = Button(label="Preview", default_size=220)
|
||||||
preview_button.on_click(preview_button_callback)
|
preview_button.on_click(preview_button_callback)
|
||||||
|
|
||||||
save_button = Button(label="Download preview", button_type="success", default_size=220)
|
save_button = Button(label="Download preview", button_type="success", default_size=220)
|
||||||
save_button.js_on_click(CustomJS(args={"js_data": js_data[".comm"]}, code=javaScript))
|
save_button.js_on_click(CustomJS(args={"js_data": js_data}, code=javaScript))
|
||||||
save_button.js_on_click(CustomJS(args={"js_data": js_data[".incomm"]}, code=javaScript))
|
|
||||||
|
|
||||||
fitpeak_controls = row(
|
fitpeak_controls = row(
|
||||||
column(fitparams_add_dropdown, fitparams_select, fitparams_remove_button),
|
column(fitparams_add_dropdown, fitparams_select, fitparams_remove_button),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user