Replace toggles with checkboxes

The CheckboxGroup widget state functionality is more readable
This commit is contained in:
usov_i 2021-04-08 16:49:48 +02:00
parent 5b45685257
commit c1b3a28351
3 changed files with 46 additions and 49 deletions

View File

@ -10,6 +10,7 @@ from bokeh.models import (
BasicTicker, BasicTicker,
Button, Button,
CheckboxEditor, CheckboxEditor,
CheckboxGroup,
ColumnDataSource, ColumnDataSource,
CustomJS, CustomJS,
DataRange1d, DataRange1d,
@ -37,7 +38,6 @@ from bokeh.models import (
TableColumn, TableColumn,
TextAreaInput, TextAreaInput,
TextInput, TextInput,
Toggle,
WheelZoomTool, WheelZoomTool,
Whisker, Whisker,
) )
@ -489,11 +489,13 @@ def create():
) )
area_method_radiobutton.on_click(area_method_radiobutton_callback) area_method_radiobutton.on_click(area_method_radiobutton_callback)
def lorentz_toggle_callback(_handler): def lorentz_checkbox_callback(_handler):
_update_preview() _update_preview()
lorentz_toggle = Toggle(label="Lorentz Correction", default_size=145) lorentz_checkbox = CheckboxGroup(
lorentz_toggle.on_click(lorentz_toggle_callback) labels=["Lorentz Correction"], default_size=145, margin=[13, 5, 5, 5]
)
lorentz_checkbox.on_click(lorentz_checkbox_callback)
export_preview_textinput = TextAreaInput(title="Export file preview:", width=500, height=400) export_preview_textinput = TextAreaInput(title="Export file preview:", width=500, height=400)
@ -509,7 +511,7 @@ def create():
export_data, export_data,
temp_file, temp_file,
area_method=AREA_METHODS[int(area_method_radiobutton.active)], area_method=AREA_METHODS[int(area_method_radiobutton.active)],
lorentz=lorentz_toggle.active, lorentz=bool(lorentz_checkbox.active),
hkl_precision=int(hkl_precision_select.value), hkl_precision=int(hkl_precision_select.value),
) )
@ -545,7 +547,7 @@ def create():
Spacer(width=20), Spacer(width=20),
column( column(
row(fit_from_spinner, fit_to_spinner), row(fit_from_spinner, fit_to_spinner),
row(area_method_radiobutton, lorentz_toggle), row(area_method_radiobutton, lorentz_checkbox),
row(fit_button, fit_all_button), row(fit_button, fit_all_button),
), ),
) )

View File

@ -9,6 +9,7 @@ from bokeh.models import (
BoxEditTool, BoxEditTool,
BoxZoomTool, BoxZoomTool,
Button, Button,
CheckboxGroup,
ColumnDataSource, ColumnDataSource,
DataRange1d, DataRange1d,
Div, Div,
@ -22,7 +23,6 @@ from bokeh.models import (
Panel, Panel,
PanTool, PanTool,
Plot, Plot,
RadioButtonGroup,
Range1d, Range1d,
Rect, Rect,
ResetTool, ResetTool,
@ -32,7 +32,6 @@ from bokeh.models import (
TextAreaInput, TextAreaInput,
TextInput, TextInput,
Title, Title,
Toggle,
WheelZoomTool, WheelZoomTool,
) )
from bokeh.palettes import Cividis256, Greys256, Plasma256 # pylint: disable=E0611 from bokeh.palettes import Cividis256, Greys256, Plasma256 # pylint: disable=E0611
@ -91,7 +90,7 @@ def create():
) )
image_source.data.update(image=[current_image]) image_source.data.update(image=[current_image])
if auto_toggle.active: if main_auto_checkbox.active:
im_min = np.min(current_image) im_min = np.min(current_image)
im_max = np.max(current_image) im_max = np.max(current_image)
@ -124,7 +123,7 @@ def create():
overview_plot_x_image_source.data.update(image=[overview_x], dw=[n_x], dh=[n_im]) overview_plot_x_image_source.data.update(image=[overview_x], dw=[n_x], dh=[n_im])
overview_plot_y_image_source.data.update(image=[overview_y], dw=[n_y], dh=[n_im]) overview_plot_y_image_source.data.update(image=[overview_y], dw=[n_y], dh=[n_im])
if proj_auto_toggle.active: if proj_auto_checkbox.active:
im_min = min(np.min(overview_x), np.min(overview_y)) im_min = min(np.min(overview_x), np.min(overview_y))
im_max = max(np.max(overview_x), np.max(overview_y)) im_max = max(np.max(overview_x), np.max(overview_y))
@ -435,8 +434,8 @@ def create():
colormap.value = "plasma" colormap.value = "plasma"
STEP = 1 STEP = 1
# ---- colormap auto toggle button
def auto_toggle_callback(state): def main_auto_checkbox_callback(state):
if state: if state:
display_min_spinner.disabled = True display_min_spinner.disabled = True
display_max_spinner.disabled = True display_max_spinner.disabled = True
@ -446,45 +445,43 @@ def create():
update_image() update_image()
auto_toggle = Toggle( main_auto_checkbox = CheckboxGroup(
label="Main Auto Range", active=True, button_type="default", default_size=125 labels=["Main Auto Range"], active=[0], default_size=145, margin=[10, 5, 0, 5]
) )
auto_toggle.on_click(auto_toggle_callback) main_auto_checkbox.on_click(main_auto_checkbox_callback)
# ---- colormap display max value
def display_max_spinner_callback(_attr, _old_value, new_value): def display_max_spinner_callback(_attr, _old_value, new_value):
display_min_spinner.high = new_value - STEP display_min_spinner.high = new_value - STEP
image_glyph.color_mapper.high = new_value image_glyph.color_mapper.high = new_value
display_max_spinner = Spinner( display_max_spinner = Spinner(
title="Max Value:",
low=0 + STEP, low=0 + STEP,
value=1, value=1,
step=STEP, step=STEP,
disabled=auto_toggle.active, disabled=bool(main_auto_checkbox.active),
default_size=80, default_size=95,
height=31,
) )
display_max_spinner.on_change("value", display_max_spinner_callback) display_max_spinner.on_change("value", display_max_spinner_callback)
# ---- colormap display min value
def display_min_spinner_callback(_attr, _old_value, new_value): def display_min_spinner_callback(_attr, _old_value, new_value):
display_max_spinner.low = new_value + STEP display_max_spinner.low = new_value + STEP
image_glyph.color_mapper.low = new_value image_glyph.color_mapper.low = new_value
display_min_spinner = Spinner( display_min_spinner = Spinner(
title="Min Value:",
low=0, low=0,
high=1 - STEP, high=1 - STEP,
value=0, value=0,
step=STEP, step=STEP,
disabled=auto_toggle.active, disabled=bool(main_auto_checkbox.active),
default_size=80, default_size=95,
height=31,
) )
display_min_spinner.on_change("value", display_min_spinner_callback) display_min_spinner.on_change("value", display_min_spinner_callback)
PROJ_STEP = 0.1 PROJ_STEP = 0.1
# ---- proj colormap auto toggle button
def proj_auto_toggle_callback(state): def proj_auto_checkbox_callback(state):
if state: if state:
proj_display_min_spinner.disabled = True proj_display_min_spinner.disabled = True
proj_display_max_spinner.disabled = True proj_display_max_spinner.disabled = True
@ -494,41 +491,39 @@ def create():
update_overview_plot() update_overview_plot()
proj_auto_toggle = Toggle( proj_auto_checkbox = CheckboxGroup(
label="Proj Auto Range", active=True, button_type="default", default_size=125 labels=["Projections Auto Range"], active=[0], default_size=145, margin=[10, 5, 0, 5]
) )
proj_auto_toggle.on_click(proj_auto_toggle_callback) proj_auto_checkbox.on_click(proj_auto_checkbox_callback)
# ---- proj colormap display max value
def proj_display_max_spinner_callback(_attr, _old_value, new_value): def proj_display_max_spinner_callback(_attr, _old_value, new_value):
proj_display_min_spinner.high = new_value - PROJ_STEP proj_display_min_spinner.high = new_value - PROJ_STEP
overview_plot_x_image_glyph.color_mapper.high = new_value overview_plot_x_image_glyph.color_mapper.high = new_value
overview_plot_y_image_glyph.color_mapper.high = new_value overview_plot_y_image_glyph.color_mapper.high = new_value
proj_display_max_spinner = Spinner( proj_display_max_spinner = Spinner(
title="Max Value:",
low=0 + PROJ_STEP, low=0 + PROJ_STEP,
value=1, value=1,
step=PROJ_STEP, step=PROJ_STEP,
disabled=proj_auto_toggle.active, disabled=bool(proj_auto_checkbox.active),
default_size=80, default_size=95,
height=31,
) )
proj_display_max_spinner.on_change("value", proj_display_max_spinner_callback) proj_display_max_spinner.on_change("value", proj_display_max_spinner_callback)
# ---- proj colormap display min value
def proj_display_min_spinner_callback(_attr, _old_value, new_value): def proj_display_min_spinner_callback(_attr, _old_value, new_value):
proj_display_max_spinner.low = new_value + PROJ_STEP proj_display_max_spinner.low = new_value + PROJ_STEP
overview_plot_x_image_glyph.color_mapper.low = new_value overview_plot_x_image_glyph.color_mapper.low = new_value
overview_plot_y_image_glyph.color_mapper.low = new_value overview_plot_y_image_glyph.color_mapper.low = new_value
proj_display_min_spinner = Spinner( proj_display_min_spinner = Spinner(
title="Min Value:",
low=0, low=0,
high=1 - PROJ_STEP, high=1 - PROJ_STEP,
value=0, value=0,
step=PROJ_STEP, step=PROJ_STEP,
disabled=proj_auto_toggle.active, disabled=bool(proj_auto_checkbox.active),
default_size=80, default_size=95,
height=31,
) )
proj_display_min_spinner.on_change("value", proj_display_min_spinner_callback) proj_display_min_spinner.on_change("value", proj_display_min_spinner_callback)
@ -571,13 +566,11 @@ def create():
# Final layout # Final layout
layout_image = column(gridplot([[proj_v, None], [plot, proj_h]], merge_tools=False)) layout_image = column(gridplot([[proj_v, None], [plot, proj_h]], merge_tools=False))
colormap_layout = column( colormap_layout = column(
row(colormap), colormap,
row(column(Spacer(height=19), auto_toggle), display_max_spinner, display_min_spinner), main_auto_checkbox,
row( row(display_min_spinner, display_max_spinner),
column(Spacer(height=19), proj_auto_toggle), proj_auto_checkbox,
proj_display_max_spinner, row(proj_display_min_spinner, proj_display_max_spinner),
proj_display_min_spinner,
),
) )
hkl_layout = column(geometry_textinput, hkl_button) hkl_layout = column(geometry_textinput, hkl_button)
params_layout = row(mf_spinner, temp_spinner) params_layout = row(mf_spinner, temp_spinner)

View File

@ -11,6 +11,7 @@ from bokeh.models import (
BasicTicker, BasicTicker,
Button, Button,
CheckboxEditor, CheckboxEditor,
CheckboxGroup,
ColumnDataSource, ColumnDataSource,
CustomJS, CustomJS,
DataRange1d, DataRange1d,
@ -40,7 +41,6 @@ from bokeh.models import (
Tabs, Tabs,
TextAreaInput, TextAreaInput,
TextInput, TextInput,
Toggle,
WheelZoomTool, WheelZoomTool,
Whisker, Whisker,
) )
@ -583,11 +583,13 @@ def create():
) )
area_method_radiobutton.on_click(area_method_radiobutton_callback) area_method_radiobutton.on_click(area_method_radiobutton_callback)
def lorentz_toggle_callback(_handler): def lorentz_checkbox_callback(_handler):
_update_preview() _update_preview()
lorentz_toggle = Toggle(label="Lorentz Correction", default_size=145) lorentz_checkbox = CheckboxGroup(
lorentz_toggle.on_click(lorentz_toggle_callback) labels=["Lorentz Correction"], default_size=145, margin=[13, 5, 5, 5]
)
lorentz_checkbox.on_click(lorentz_checkbox_callback)
export_preview_textinput = TextAreaInput(title="Export file preview:", width=450, height=400) export_preview_textinput = TextAreaInput(title="Export file preview:", width=450, height=400)
@ -603,7 +605,7 @@ def create():
export_data, export_data,
temp_file, temp_file,
area_method=AREA_METHODS[int(area_method_radiobutton.active)], area_method=AREA_METHODS[int(area_method_radiobutton.active)],
lorentz=lorentz_toggle.active, lorentz=bool(lorentz_checkbox.active),
) )
exported_content = "" exported_content = ""
@ -630,7 +632,7 @@ def create():
Spacer(width=20), Spacer(width=20),
column( column(
row(fit_from_spinner, fit_to_spinner), row(fit_from_spinner, fit_to_spinner),
row(area_method_radiobutton, lorentz_toggle), row(area_method_radiobutton, lorentz_checkbox),
row(fit_button, fit_all_button), row(fit_button, fit_all_button),
), ),
) )