Add download option for hkl/mhkl files
This commit is contained in:
@@ -8,6 +8,8 @@ from bokeh.layouts import column, row
|
|||||||
from bokeh.models import (
|
from bokeh.models import (
|
||||||
Button,
|
Button,
|
||||||
CheckboxGroup,
|
CheckboxGroup,
|
||||||
|
ColumnDataSource,
|
||||||
|
CustomJS,
|
||||||
DataRange1d,
|
DataRange1d,
|
||||||
Div,
|
Div,
|
||||||
FileInput,
|
FileInput,
|
||||||
@@ -25,11 +27,33 @@ from bokeh.models import (
|
|||||||
import pyzebra
|
import pyzebra
|
||||||
|
|
||||||
|
|
||||||
|
javaScript = """
|
||||||
|
let j = 0;
|
||||||
|
for (let i = 0; i < js_data.data['fname'].length; i++) {
|
||||||
|
if (js_data.data['content'][i] === "") continue;
|
||||||
|
|
||||||
|
setTimeout(function() {
|
||||||
|
const blob = new Blob([js_data.data['content'][i]], {type: 'text/plain'})
|
||||||
|
const link = document.createElement('a');
|
||||||
|
document.body.appendChild(link);
|
||||||
|
const url = window.URL.createObjectURL(blob);
|
||||||
|
link.href = url;
|
||||||
|
link.download = js_data.data['fname'][i];
|
||||||
|
link.click();
|
||||||
|
window.URL.revokeObjectURL(url);
|
||||||
|
document.body.removeChild(link);
|
||||||
|
}, 100 * j)
|
||||||
|
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
def create():
|
def create():
|
||||||
ang_lims = None
|
ang_lims = None
|
||||||
cif_data = None
|
cif_data = None
|
||||||
params = None
|
params = None
|
||||||
res_files = {}
|
res_files = {}
|
||||||
|
js_data = ColumnDataSource(data=dict(content=[""], fname=[""]))
|
||||||
|
|
||||||
anglim_div = Div(text="Angular min/max limits:")
|
anglim_div = Div(text="Angular min/max limits:")
|
||||||
sttgamma_ti = TextInput(title="stt/gamma", width=100)
|
sttgamma_ti = TextInput(title="stt/gamma", width=100)
|
||||||
@@ -223,13 +247,17 @@ def create():
|
|||||||
sorting_go = Button(label="GO", button_type="primary", width=50)
|
sorting_go = Button(label="GO", button_type="primary", width=50)
|
||||||
|
|
||||||
def created_lists_callback(_attr, _old, new):
|
def created_lists_callback(_attr, _old, new):
|
||||||
preview_lists.value = res_files[new[0]]
|
sel_file = new[0]
|
||||||
|
file_text = res_files[sel_file]
|
||||||
|
preview_lists.value = file_text
|
||||||
|
js_data.data.update(content=[file_text], fname=[sel_file])
|
||||||
|
|
||||||
created_lists = MultiSelect(title="Created lists:", width=200, height=150)
|
created_lists = MultiSelect(title="Created lists:", width=200, height=150)
|
||||||
created_lists.on_change("value", created_lists_callback)
|
created_lists.on_change("value", created_lists_callback)
|
||||||
preview_lists = TextAreaInput(title="Preview selected list:", width=600, height=150)
|
preview_lists = TextAreaInput(title="Preview selected list:", width=600, height=150)
|
||||||
|
|
||||||
download_file = Button(label="Download file", button_type="success", width=200)
|
download_file = Button(label="Download file", button_type="success", width=200)
|
||||||
|
download_file.js_on_click(CustomJS(args={"js_data": js_data}, code=javaScript))
|
||||||
plot_list = Button(label="Plot selected list", button_type="primary", width=200)
|
plot_list = Button(label="Plot selected list", button_type="primary", width=200)
|
||||||
|
|
||||||
measured_data_div = Div(text="Measured data:")
|
measured_data_div = Div(text="Measured data:")
|
||||||
|
|||||||
Reference in New Issue
Block a user