bec-widgets 0.99.1__py3-none-any.whl → 0.99.9__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- .gitlab-ci.yml +0 -1
- CHANGELOG.md +76 -70
- PKG-INFO +2 -2
- bec_widgets/cli/client.py +3 -3
- bec_widgets/qt_utils/toolbar.py +11 -5
- bec_widgets/utils/bec_widget.py +11 -2
- bec_widgets/utils/colors.py +18 -2
- bec_widgets/utils/plugin_templates/plugin.template +2 -2
- bec_widgets/widgets/bec_queue/bec_queue.py +2 -0
- bec_widgets/widgets/bec_queue/bec_queue_plugin.py +1 -1
- bec_widgets/widgets/bec_status_box/bec_status_box.py +2 -0
- bec_widgets/widgets/bec_status_box/bec_status_box_plugin.py +1 -1
- bec_widgets/widgets/color_button/color_button.py +2 -0
- bec_widgets/widgets/color_button/color_button_plugin.py +1 -1
- bec_widgets/widgets/colormap_selector/colormap_selector.py +1 -0
- bec_widgets/widgets/colormap_selector/colormap_selector_plugin.py +1 -1
- bec_widgets/widgets/dark_mode_button/dark_mode_button.py +12 -3
- bec_widgets/widgets/dark_mode_button/dark_mode_button_plugin.py +1 -1
- bec_widgets/widgets/device_browser/device_browser.py +2 -0
- bec_widgets/widgets/device_browser/device_browser_plugin.py +1 -1
- bec_widgets/widgets/device_combobox/device_combo_box_plugin.py +1 -1
- bec_widgets/widgets/device_combobox/device_combobox.py +2 -0
- bec_widgets/widgets/device_line_edit/device_line_edit.py +2 -0
- bec_widgets/widgets/device_line_edit/device_line_edit_plugin.py +1 -1
- bec_widgets/widgets/dock/dock.py +1 -0
- bec_widgets/widgets/dock/dock_area.py +30 -10
- bec_widgets/widgets/dock/dock_area_plugin.py +1 -1
- bec_widgets/widgets/figure/figure.py +1 -1
- bec_widgets/widgets/figure/plots/waveform/waveform.py +12 -7
- bec_widgets/widgets/figure/plots/waveform/waveform_curve.py +3 -3
- bec_widgets/widgets/image/bec_image_widget_plugin.py +1 -1
- bec_widgets/widgets/image/image_widget.py +1 -0
- bec_widgets/widgets/motor_map/bec_motor_map_widget_plugin.py +1 -1
- bec_widgets/widgets/motor_map/motor_map_widget.py +1 -0
- bec_widgets/widgets/position_indicator/position_indicator.py +2 -0
- bec_widgets/widgets/position_indicator/position_indicator_plugin.py +1 -1
- bec_widgets/widgets/positioner_box/positioner_box.py +1 -0
- bec_widgets/widgets/positioner_box/positioner_box_plugin.py +1 -1
- bec_widgets/widgets/positioner_box/positioner_control_line.py +2 -0
- bec_widgets/widgets/positioner_box/positioner_control_line_plugin.py +1 -1
- bec_widgets/widgets/ring_progress_bar/ring_progress_bar.py +1 -0
- bec_widgets/widgets/ring_progress_bar/ring_progress_bar_plugin.py +1 -1
- bec_widgets/widgets/scan_control/scan_control.py +2 -0
- bec_widgets/widgets/scan_control/scan_control_plugin.py +1 -4
- bec_widgets/widgets/spinner/spinner.py +2 -0
- bec_widgets/widgets/spinner/spinner_widget_plugin.py +1 -1
- bec_widgets/widgets/stop_button/stop_button.py +2 -0
- bec_widgets/widgets/stop_button/stop_button_plugin.py +1 -1
- bec_widgets/widgets/text_box/text_box.py +1 -0
- bec_widgets/widgets/text_box/text_box_plugin.py +1 -1
- bec_widgets/widgets/toggle/toggle.py +1 -0
- bec_widgets/widgets/toggle/toggle_switch_plugin.py +1 -1
- bec_widgets/widgets/vscode/vs_code_editor_plugin.py +1 -1
- bec_widgets/widgets/vscode/vscode.py +1 -0
- bec_widgets/widgets/waveform/bec_waveform_widget_plugin.py +1 -1
- bec_widgets/widgets/waveform/waveform_popups/curve_dialog/curve_dialog.py +14 -13
- bec_widgets/widgets/waveform/waveform_widget.py +3 -2
- bec_widgets/widgets/website/website.py +42 -10
- bec_widgets/widgets/website/website_widget_plugin.py +1 -1
- {bec_widgets-0.99.1.dist-info → bec_widgets-0.99.9.dist-info}/METADATA +2 -2
- bec_widgets-0.99.9.dist-info/RECORD +231 -0
- pyproject.toml +7 -2
- bec_widgets/assets/toolbar_icons/add.svg +0 -3
- bec_widgets/assets/toolbar_icons/attach_all.svg +0 -3
- bec_widgets/assets/toolbar_icons/auto_range.svg +0 -3
- bec_widgets/assets/toolbar_icons/compare.svg +0 -3
- bec_widgets/assets/toolbar_icons/connection.svg +0 -4
- bec_widgets/assets/toolbar_icons/device_line_edit.svg +0 -3
- bec_widgets/assets/toolbar_icons/drag_pan_mode.svg +0 -3
- bec_widgets/assets/toolbar_icons/export.svg +0 -9
- bec_widgets/assets/toolbar_icons/fft.svg +0 -11
- bec_widgets/assets/toolbar_icons/fitting_parameters.svg +0 -3
- bec_widgets/assets/toolbar_icons/history.svg +0 -4
- bec_widgets/assets/toolbar_icons/image.svg +0 -3
- bec_widgets/assets/toolbar_icons/image_autorange.svg +0 -3
- bec_widgets/assets/toolbar_icons/import.svg +0 -9
- bec_widgets/assets/toolbar_icons/line_axis.svg +0 -3
- bec_widgets/assets/toolbar_icons/line_curve.svg +0 -3
- bec_widgets/assets/toolbar_icons/lock_aspect_ratio.svg +0 -3
- bec_widgets/assets/toolbar_icons/log_scale.png +0 -0
- bec_widgets/assets/toolbar_icons/motor_map.svg +0 -3
- bec_widgets/assets/toolbar_icons/photo_library.svg +0 -3
- bec_widgets/assets/toolbar_icons/positioner_box.svg +0 -3
- bec_widgets/assets/toolbar_icons/progress.svg +0 -3
- bec_widgets/assets/toolbar_icons/queue.svg +0 -3
- bec_widgets/assets/toolbar_icons/rectangle_mode.svg +0 -3
- bec_widgets/assets/toolbar_icons/remove.svg +0 -5
- bec_widgets/assets/toolbar_icons/reset_settings.svg +0 -3
- bec_widgets/assets/toolbar_icons/restore_state.svg +0 -3
- bec_widgets/assets/toolbar_icons/ring_progress.svg +0 -3
- bec_widgets/assets/toolbar_icons/rotate_left.svg +0 -3
- bec_widgets/assets/toolbar_icons/rotate_right.svg +0 -3
- bec_widgets/assets/toolbar_icons/save.svg +0 -3
- bec_widgets/assets/toolbar_icons/save_state.svg +0 -3
- bec_widgets/assets/toolbar_icons/scan_control.svg +0 -3
- bec_widgets/assets/toolbar_icons/settings.svg +0 -4
- bec_widgets/assets/toolbar_icons/status.svg +0 -3
- bec_widgets/assets/toolbar_icons/terminal.svg +0 -3
- bec_widgets/assets/toolbar_icons/transform.svg +0 -3
- bec_widgets/assets/toolbar_icons/waveform.svg +0 -3
- bec_widgets-0.99.1.dist-info/RECORD +0 -415
- docs/Makefile +0 -20
- docs/_static/custom.css +0 -170
- docs/_templates/custom-class-template.rst +0 -34
- docs/_templates/custom-module-template.rst +0 -66
- docs/api_reference/api_reference.md +0 -12
- docs/assets/apps_48dp.svg +0 -1
- docs/assets/display_settings_48dp.svg +0 -1
- docs/assets/index_api.svg +0 -97
- docs/assets/index_contribute.svg +0 -76
- docs/assets/index_getting_started.svg +0 -66
- docs/assets/index_user_guide.svg +0 -67
- docs/assets/rocket_launch_48dp.svg +0 -1
- docs/assets/widget_screenshots/buttons.png +0 -0
- docs/assets/widget_screenshots/device_box.png +0 -0
- docs/assets/widget_screenshots/device_browser.png +0 -0
- docs/assets/widget_screenshots/device_inputs.png +0 -0
- docs/assets/widget_screenshots/dock_area.png +0 -0
- docs/assets/widget_screenshots/figure.png +0 -0
- docs/assets/widget_screenshots/image_widget.png +0 -0
- docs/assets/widget_screenshots/motor_map_widget.png +0 -0
- docs/assets/widget_screenshots/position_indicator.png +0 -0
- docs/assets/widget_screenshots/queue.png +0 -0
- docs/assets/widget_screenshots/ring_progress_bar.png +0 -0
- docs/assets/widget_screenshots/scan_controller.png +0 -0
- docs/assets/widget_screenshots/spinner.gif +0 -0
- docs/assets/widget_screenshots/status_box.png +0 -0
- docs/assets/widget_screenshots/text_box.png +0 -0
- docs/assets/widget_screenshots/toggle.png +0 -0
- docs/assets/widget_screenshots/waveform_widget.png +0 -0
- docs/assets/widget_screenshots/website.png +0 -0
- docs/conf.py +0 -82
- docs/developer/developer.md +0 -52
- docs/developer/introduction/concepts.md +0 -14
- docs/developer/introduction/contributing.md +0 -28
- docs/developer/introduction/introduction.md +0 -16
- docs/developer/introduction/useful_links.md +0 -23
- docs/developer/widget_development/bec_dispatcher.md +0 -143
- docs/developer/widget_development/widget_development.md +0 -13
- docs/index.md +0 -74
- docs/introduction/introduction.md +0 -18
- docs/make.bat +0 -35
- docs/requirements.txt +0 -12
- docs/user/api_reference/api_reference.md +0 -11
- docs/user/applications/applications.md +0 -10
- docs/user/customisation.md +0 -123
- docs/user/getting_started/BECDockArea.png +0 -0
- docs/user/getting_started/auto_updates.md +0 -82
- docs/user/getting_started/getting_started.md +0 -15
- docs/user/getting_started/gui_complex_gui.gif +0 -0
- docs/user/getting_started/installation.md +0 -33
- docs/user/getting_started/quick_start.md +0 -110
- docs/user/getting_started/video_tutorials.md +0 -17
- docs/user/user.md +0 -71
- docs/user/widgets/bec_figure/BECFigure.png +0 -0
- docs/user/widgets/bec_figure/bec_figure.md +0 -105
- docs/user/widgets/bec_status_box/bec_status_box.gif +0 -0
- docs/user/widgets/bec_status_box/bec_status_box.md +0 -38
- docs/user/widgets/buttons/buttons.md +0 -63
- docs/user/widgets/buttons/dark_mode_disabled.png +0 -0
- docs/user/widgets/buttons/dark_mode_enabled.png +0 -0
- docs/user/widgets/device_browser/device_browser.md +0 -36
- docs/user/widgets/device_browser/device_browser.png +0 -0
- docs/user/widgets/device_input/device_input.md +0 -100
- docs/user/widgets/dock_area/BECDockArea.png +0 -0
- docs/user/widgets/dock_area/bec_dock_area.md +0 -107
- docs/user/widgets/image/image_plot.gif +0 -0
- docs/user/widgets/image/image_widget.md +0 -84
- docs/user/widgets/motor_map/motor.gif +0 -0
- docs/user/widgets/motor_map/motor_map.md +0 -80
- docs/user/widgets/position_indicator/position_indicator.md +0 -76
- docs/user/widgets/positioner_box/positioner_box.md +0 -63
- docs/user/widgets/progress_bar/progress_bar.gif +0 -0
- docs/user/widgets/progress_bar/ring_progress_bar.md +0 -103
- docs/user/widgets/queue/queue.md +0 -41
- docs/user/widgets/scan_control/hide_scan_control.png +0 -0
- docs/user/widgets/scan_control/scan_control.gif +0 -0
- docs/user/widgets/scan_control/scan_control.md +0 -54
- docs/user/widgets/spinner/spinner.md +0 -75
- docs/user/widgets/text_box/text_box.md +0 -74
- docs/user/widgets/toggle/toggle.md +0 -66
- docs/user/widgets/waveform/bec_figure_dap.gif +0 -0
- docs/user/widgets/waveform/scatter_2D.gif +0 -0
- docs/user/widgets/waveform/w1D.gif +0 -0
- docs/user/widgets/waveform/waveform_widget.md +0 -132
- docs/user/widgets/website/website.md +0 -69
- docs/user/widgets/widgets.md +0 -220
- tests/__init__.py +0 -0
- tests/end-2-end/__init__.py +0 -0
- tests/end-2-end/conftest.py +0 -53
- tests/end-2-end/test_bec_dock_rpc_e2e.py +0 -298
- tests/end-2-end/test_bec_figure_rpc_e2e.py +0 -212
- tests/end-2-end/test_rpc_register_e2e.py +0 -40
- tests/end-2-end/test_scan_control_e2e.py +0 -71
- tests/references/SpinnerWidget/SpinnerWidget_darwin.png +0 -0
- tests/references/SpinnerWidget/SpinnerWidget_linux.png +0 -0
- tests/references/SpinnerWidget/SpinnerWidget_started_darwin.png +0 -0
- tests/references/SpinnerWidget/SpinnerWidget_started_linux.png +0 -0
- tests/unit_tests/__init__.py +0 -0
- tests/unit_tests/client_mocks.py +0 -189
- tests/unit_tests/conftest.py +0 -64
- tests/unit_tests/test_bec_connector.py +0 -80
- tests/unit_tests/test_bec_dispatcher.py +0 -119
- tests/unit_tests/test_bec_dock.py +0 -155
- tests/unit_tests/test_bec_figure.py +0 -270
- tests/unit_tests/test_bec_image.py +0 -63
- tests/unit_tests/test_bec_image_widget.py +0 -217
- tests/unit_tests/test_bec_motor_map.py +0 -282
- tests/unit_tests/test_bec_queue.py +0 -111
- tests/unit_tests/test_bec_status_box.py +0 -123
- tests/unit_tests/test_client_utils.py +0 -76
- tests/unit_tests/test_color_map_selector.py +0 -42
- tests/unit_tests/test_color_validation.py +0 -75
- tests/unit_tests/test_configs/config_device.yaml +0 -33
- tests/unit_tests/test_configs/config_device_no_entry.yaml +0 -27
- tests/unit_tests/test_configs/config_scan.yaml +0 -82
- tests/unit_tests/test_crosshair.py +0 -143
- tests/unit_tests/test_dark_mode_button.py +0 -70
- tests/unit_tests/test_device_browser.py +0 -83
- tests/unit_tests/test_device_input_base.py +0 -76
- tests/unit_tests/test_device_input_widgets.py +0 -178
- tests/unit_tests/test_error_utils.py +0 -63
- tests/unit_tests/test_generate_cli_client.py +0 -123
- tests/unit_tests/test_generate_plugin.py +0 -155
- tests/unit_tests/test_motor_map_widget.py +0 -194
- tests/unit_tests/test_msgs/__init__.py +0 -0
- tests/unit_tests/test_msgs/available_scans_message.py +0 -989
- tests/unit_tests/test_plot_base.py +0 -95
- tests/unit_tests/test_plugin_utils.py +0 -13
- tests/unit_tests/test_positioner_box.py +0 -130
- tests/unit_tests/test_ring_progress_bar.py +0 -337
- tests/unit_tests/test_rpc_register.py +0 -52
- tests/unit_tests/test_rpc_server.py +0 -42
- tests/unit_tests/test_rpc_widget_handler.py +0 -7
- tests/unit_tests/test_scan_control.py +0 -324
- tests/unit_tests/test_scan_control_group_box.py +0 -160
- tests/unit_tests/test_setting_dialog.py +0 -96
- tests/unit_tests/test_spinner.py +0 -31
- tests/unit_tests/test_stop_button.py +0 -27
- tests/unit_tests/test_text_box_widget.py +0 -54
- tests/unit_tests/test_toggle.py +0 -38
- tests/unit_tests/test_vscode_widget.py +0 -75
- tests/unit_tests/test_waveform1d.py +0 -712
- tests/unit_tests/test_waveform_widget.py +0 -462
- tests/unit_tests/test_website_widget.py +0 -25
- tests/unit_tests/test_widget_io.py +0 -90
- tests/unit_tests/test_yaml_dialog.py +0 -163
- {bec_widgets-0.99.1.dist-info → bec_widgets-0.99.9.dist-info}/WHEEL +0 -0
- {bec_widgets-0.99.1.dist-info → bec_widgets-0.99.9.dist-info}/entry_points.txt +0 -0
- {bec_widgets-0.99.1.dist-info → bec_widgets-0.99.9.dist-info}/licenses/LICENSE +0 -0
@@ -1,119 +0,0 @@
|
|
1
|
-
# pylint: disable = no-name-in-module,missing-class-docstring, missing-module-docstring
|
2
|
-
import threading
|
3
|
-
import time
|
4
|
-
from unittest import mock
|
5
|
-
|
6
|
-
import pytest
|
7
|
-
import redis
|
8
|
-
from bec_lib.connector import MessageObject
|
9
|
-
from bec_lib.messages import ScanMessage
|
10
|
-
from bec_lib.redis_connector import RedisConnector
|
11
|
-
from bec_lib.serialization import MsgpackSerialization
|
12
|
-
|
13
|
-
from bec_widgets.utils.bec_dispatcher import QtRedisConnector
|
14
|
-
|
15
|
-
|
16
|
-
@pytest.fixture
|
17
|
-
def bec_dispatcher_w_connector(bec_dispatcher, topics_msg_list, send_msg_event):
|
18
|
-
def pubsub_msg_generator():
|
19
|
-
send_msg_event.wait()
|
20
|
-
for topic, msg in topics_msg_list:
|
21
|
-
yield {"channel": topic.encode(), "pattern": None, "data": msg}
|
22
|
-
while True:
|
23
|
-
time.sleep(0.2)
|
24
|
-
yield StopIteration
|
25
|
-
|
26
|
-
with mock.patch("redis.Redis"):
|
27
|
-
pubsub = redis.Redis().pubsub()
|
28
|
-
messages = pubsub_msg_generator()
|
29
|
-
pubsub.get_message.side_effect = lambda timeout: next(messages)
|
30
|
-
connector = QtRedisConnector("localhost:1")
|
31
|
-
bec_dispatcher.client.connector = connector
|
32
|
-
yield bec_dispatcher
|
33
|
-
|
34
|
-
|
35
|
-
dummy_msg = MsgpackSerialization.dumps(ScanMessage(point_id=0, scan_id="0", data={}))
|
36
|
-
|
37
|
-
|
38
|
-
@pytest.fixture
|
39
|
-
def send_msg_event():
|
40
|
-
return threading.Event()
|
41
|
-
|
42
|
-
|
43
|
-
@pytest.mark.parametrize(
|
44
|
-
"topics_msg_list", [(("topic1", dummy_msg), ("topic2", dummy_msg), ("topic3", dummy_msg))]
|
45
|
-
)
|
46
|
-
def test_dispatcher_disconnect_all(bec_dispatcher_w_connector, qtbot, send_msg_event):
|
47
|
-
bec_dispatcher = bec_dispatcher_w_connector
|
48
|
-
cb1 = mock.Mock(spec=[])
|
49
|
-
cb2 = mock.Mock(spec=[])
|
50
|
-
|
51
|
-
bec_dispatcher.connect_slot(cb1, "topic1")
|
52
|
-
bec_dispatcher.connect_slot(cb1, "topic2")
|
53
|
-
bec_dispatcher.connect_slot(cb2, "topic2")
|
54
|
-
bec_dispatcher.connect_slot(cb2, "topic3")
|
55
|
-
assert len(bec_dispatcher.client.connector._topics_cb) == 3
|
56
|
-
send_msg_event.set()
|
57
|
-
qtbot.wait(10)
|
58
|
-
assert cb1.call_count == 2
|
59
|
-
assert cb2.call_count == 2
|
60
|
-
|
61
|
-
bec_dispatcher.disconnect_all()
|
62
|
-
|
63
|
-
assert len(bec_dispatcher.client.connector._topics_cb) == 0
|
64
|
-
|
65
|
-
|
66
|
-
@pytest.mark.parametrize("topics_msg_list", [(("topic1", dummy_msg), ("topic2", dummy_msg))])
|
67
|
-
def test_dispatcher_disconnect_one(bec_dispatcher_w_connector, qtbot, send_msg_event):
|
68
|
-
# test for BEC issue #276
|
69
|
-
bec_dispatcher = bec_dispatcher_w_connector
|
70
|
-
cb1 = mock.Mock(spec=[])
|
71
|
-
cb2 = mock.Mock(spec=[])
|
72
|
-
|
73
|
-
bec_dispatcher.connect_slot(cb1, "topic1")
|
74
|
-
bec_dispatcher.connect_slot(cb2, "topic2")
|
75
|
-
assert len(bec_dispatcher.client.connector._topics_cb) == 2
|
76
|
-
bec_dispatcher.disconnect_slot(cb1, "topic1")
|
77
|
-
assert len(bec_dispatcher.client.connector._topics_cb) == 1
|
78
|
-
|
79
|
-
send_msg_event.set()
|
80
|
-
qtbot.wait(10)
|
81
|
-
assert cb1.call_count == 0
|
82
|
-
cb2.assert_called_once()
|
83
|
-
|
84
|
-
|
85
|
-
@pytest.mark.parametrize("topics_msg_list", [(("topic1", dummy_msg),)])
|
86
|
-
def test_dispatcher_2_cb_same_topic(bec_dispatcher_w_connector, qtbot, send_msg_event):
|
87
|
-
# test for BEC issue #276
|
88
|
-
bec_dispatcher = bec_dispatcher_w_connector
|
89
|
-
cb1 = mock.Mock(spec=[])
|
90
|
-
cb2 = mock.Mock(spec=[])
|
91
|
-
|
92
|
-
bec_dispatcher.connect_slot(cb1, "topic1")
|
93
|
-
bec_dispatcher.connect_slot(cb2, "topic1")
|
94
|
-
assert len(bec_dispatcher.client.connector._topics_cb) == 1
|
95
|
-
assert len(bec_dispatcher._slots) == 2
|
96
|
-
bec_dispatcher.disconnect_slot(cb1, "topic1")
|
97
|
-
assert len(bec_dispatcher._slots) == 1
|
98
|
-
|
99
|
-
send_msg_event.set()
|
100
|
-
qtbot.wait(10)
|
101
|
-
assert cb1.call_count == 0
|
102
|
-
cb2.assert_called_once()
|
103
|
-
|
104
|
-
|
105
|
-
@pytest.mark.parametrize("topics_msg_list", [(("topic1", dummy_msg), ("topic2", dummy_msg))])
|
106
|
-
def test_dispatcher_2_topic_same_cb(bec_dispatcher_w_connector, qtbot, send_msg_event):
|
107
|
-
# test for BEC issue #276
|
108
|
-
bec_dispatcher = bec_dispatcher_w_connector
|
109
|
-
cb1 = mock.Mock(spec=[])
|
110
|
-
|
111
|
-
bec_dispatcher.connect_slot(cb1, "topic1")
|
112
|
-
bec_dispatcher.connect_slot(cb1, "topic2")
|
113
|
-
assert len(bec_dispatcher.client.connector._topics_cb) == 2
|
114
|
-
bec_dispatcher.disconnect_slot(cb1, "topic1")
|
115
|
-
assert len(bec_dispatcher.client.connector._topics_cb) == 1
|
116
|
-
|
117
|
-
send_msg_event.set()
|
118
|
-
qtbot.wait(10)
|
119
|
-
cb1.assert_called_once()
|
@@ -1,155 +0,0 @@
|
|
1
|
-
# pylint: disable=missing-function-docstring, missing-module-docstring, unused-import
|
2
|
-
from unittest.mock import MagicMock, patch
|
3
|
-
|
4
|
-
import pytest
|
5
|
-
|
6
|
-
from bec_widgets.widgets.dock import BECDock, BECDockArea
|
7
|
-
|
8
|
-
from .client_mocks import mocked_client
|
9
|
-
|
10
|
-
|
11
|
-
@pytest.fixture
|
12
|
-
def bec_dock_area(qtbot, mocked_client):
|
13
|
-
widget = BECDockArea(client=mocked_client)
|
14
|
-
qtbot.addWidget(widget)
|
15
|
-
qtbot.waitExposed(widget)
|
16
|
-
yield widget
|
17
|
-
|
18
|
-
|
19
|
-
def test_bec_dock_area_init(bec_dock_area):
|
20
|
-
assert bec_dock_area is not None
|
21
|
-
assert bec_dock_area.client is not None
|
22
|
-
assert isinstance(bec_dock_area, BECDockArea)
|
23
|
-
assert bec_dock_area.config.widget_class == "BECDockArea"
|
24
|
-
|
25
|
-
|
26
|
-
def test_bec_dock_area_add_remove_dock(bec_dock_area, qtbot):
|
27
|
-
initial_count = len(bec_dock_area.dock_area.docks)
|
28
|
-
|
29
|
-
# Adding 3 docks
|
30
|
-
d0 = bec_dock_area.add_dock()
|
31
|
-
d1 = bec_dock_area.add_dock()
|
32
|
-
d2 = bec_dock_area.add_dock()
|
33
|
-
|
34
|
-
# Check if the docks were added
|
35
|
-
assert len(bec_dock_area.dock_area.docks) == initial_count + 3
|
36
|
-
assert d0.name() in dict(bec_dock_area.dock_area.docks)
|
37
|
-
assert d1.name() in dict(bec_dock_area.dock_area.docks)
|
38
|
-
assert d2.name() in dict(bec_dock_area.dock_area.docks)
|
39
|
-
assert bec_dock_area.dock_area.docks[d0.name()].config.widget_class == "BECDock"
|
40
|
-
assert bec_dock_area.dock_area.docks[d1.name()].config.widget_class == "BECDock"
|
41
|
-
assert bec_dock_area.dock_area.docks[d2.name()].config.widget_class == "BECDock"
|
42
|
-
|
43
|
-
# Check panels API for getting docks to CLI
|
44
|
-
assert bec_dock_area.panels == dict(bec_dock_area.dock_area.docks)
|
45
|
-
|
46
|
-
# Remove docks
|
47
|
-
d0_name = d0.name()
|
48
|
-
bec_dock_area.remove_dock(d0_name)
|
49
|
-
qtbot.wait(200)
|
50
|
-
d1.remove()
|
51
|
-
qtbot.wait(200)
|
52
|
-
|
53
|
-
assert len(bec_dock_area.dock_area.docks) == initial_count + 1
|
54
|
-
assert d0.name() not in dict(bec_dock_area.dock_area.docks)
|
55
|
-
assert d1.name() not in dict(bec_dock_area.dock_area.docks)
|
56
|
-
assert d2.name() in dict(bec_dock_area.dock_area.docks)
|
57
|
-
|
58
|
-
|
59
|
-
def test_add_remove_bec_figure_to_dock(bec_dock_area):
|
60
|
-
d0 = bec_dock_area.add_dock()
|
61
|
-
fig = d0.add_widget("BECFigure")
|
62
|
-
plt = fig.plot(x_name="samx", y_name="bpm4i")
|
63
|
-
im = fig.image("eiger")
|
64
|
-
mm = fig.motor_map("samx", "samy")
|
65
|
-
|
66
|
-
assert len(bec_dock_area.dock_area.docks) == 1
|
67
|
-
assert len(d0.widgets) == 1
|
68
|
-
assert len(d0.widget_list) == 1
|
69
|
-
assert len(fig.widgets) == 3
|
70
|
-
|
71
|
-
assert fig.config.widget_class == "BECFigure"
|
72
|
-
assert plt.config.widget_class == "BECWaveform"
|
73
|
-
assert im.config.widget_class == "BECImageShow"
|
74
|
-
assert mm.config.widget_class == "BECMotorMap"
|
75
|
-
|
76
|
-
|
77
|
-
def test_close_docks(bec_dock_area, qtbot):
|
78
|
-
d0 = bec_dock_area.add_dock(name="dock_0")
|
79
|
-
d1 = bec_dock_area.add_dock(name="dock_1")
|
80
|
-
d2 = bec_dock_area.add_dock(name="dock_2")
|
81
|
-
|
82
|
-
bec_dock_area.clear_all()
|
83
|
-
qtbot.wait(200)
|
84
|
-
assert len(bec_dock_area.dock_area.docks) == 0
|
85
|
-
|
86
|
-
|
87
|
-
def test_undock_and_dock_docks(bec_dock_area, qtbot):
|
88
|
-
d0 = bec_dock_area.add_dock(name="dock_0")
|
89
|
-
d1 = bec_dock_area.add_dock(name="dock_1")
|
90
|
-
d2 = bec_dock_area.add_dock(name="dock_4")
|
91
|
-
d3 = bec_dock_area.add_dock(name="dock_3")
|
92
|
-
|
93
|
-
d0.detach()
|
94
|
-
bec_dock_area.detach_dock("dock_1")
|
95
|
-
d2.detach()
|
96
|
-
|
97
|
-
assert len(bec_dock_area.dock_area.docks) == 4
|
98
|
-
assert len(bec_dock_area.dock_area.tempAreas) == 3
|
99
|
-
|
100
|
-
d0.attach()
|
101
|
-
assert len(bec_dock_area.dock_area.docks) == 4
|
102
|
-
assert len(bec_dock_area.dock_area.tempAreas) == 2
|
103
|
-
|
104
|
-
bec_dock_area.attach_all()
|
105
|
-
assert len(bec_dock_area.dock_area.docks) == 4
|
106
|
-
assert len(bec_dock_area.dock_area.tempAreas) == 0
|
107
|
-
|
108
|
-
|
109
|
-
###################################
|
110
|
-
# Toolbar Actions
|
111
|
-
###################################
|
112
|
-
def test_toolbar_add_plot_waveform(bec_dock_area):
|
113
|
-
bec_dock_area.toolbar.widgets["menu_plots"].widgets["waveform"].trigger()
|
114
|
-
assert "waveform_1" in bec_dock_area.panels
|
115
|
-
assert bec_dock_area.panels["waveform_1"].widgets[0].config.widget_class == "BECWaveformWidget"
|
116
|
-
|
117
|
-
|
118
|
-
def test_toolbar_add_plot_image(bec_dock_area):
|
119
|
-
bec_dock_area.toolbar.widgets["menu_plots"].widgets["image"].trigger()
|
120
|
-
assert "image_1" in bec_dock_area.panels
|
121
|
-
assert bec_dock_area.panels["image_1"].widgets[0].config.widget_class == "BECImageWidget"
|
122
|
-
|
123
|
-
|
124
|
-
def test_toolbar_add_plot_motor_map(bec_dock_area):
|
125
|
-
bec_dock_area.toolbar.widgets["menu_plots"].widgets["motor_map"].trigger()
|
126
|
-
assert "motor_map_1" in bec_dock_area.panels
|
127
|
-
assert bec_dock_area.panels["motor_map_1"].widgets[0].config.widget_class == "BECMotorMapWidget"
|
128
|
-
|
129
|
-
|
130
|
-
def test_toolbar_add_device_positioner_box(bec_dock_area):
|
131
|
-
bec_dock_area.toolbar.widgets["menu_devices"].widgets["positioner_box"].trigger()
|
132
|
-
assert "positioner_box_1" in bec_dock_area.panels
|
133
|
-
assert (
|
134
|
-
bec_dock_area.panels["positioner_box_1"].widgets[0].config.widget_class == "PositionerBox"
|
135
|
-
)
|
136
|
-
|
137
|
-
|
138
|
-
def test_toolbar_add_utils_queue(bec_dock_area):
|
139
|
-
bec_dock_area.toolbar.widgets["menu_utils"].widgets["queue"].trigger()
|
140
|
-
assert "queue_1" in bec_dock_area.panels
|
141
|
-
assert bec_dock_area.panels["queue_1"].widgets[0].config.widget_class == "BECQueue"
|
142
|
-
|
143
|
-
|
144
|
-
def test_toolbar_add_utils_status(bec_dock_area):
|
145
|
-
bec_dock_area.toolbar.widgets["menu_utils"].widgets["status"].trigger()
|
146
|
-
assert "status_1" in bec_dock_area.panels
|
147
|
-
assert bec_dock_area.panels["status_1"].widgets[0].config.widget_class == "BECStatusBox"
|
148
|
-
|
149
|
-
|
150
|
-
def test_toolbar_add_utils_progress_bar(bec_dock_area):
|
151
|
-
bec_dock_area.toolbar.widgets["menu_utils"].widgets["progress_bar"].trigger()
|
152
|
-
assert "progress_bar_1" in bec_dock_area.panels
|
153
|
-
assert (
|
154
|
-
bec_dock_area.panels["progress_bar_1"].widgets[0].config.widget_class == "RingProgressBar"
|
155
|
-
)
|
@@ -1,270 +0,0 @@
|
|
1
|
-
# pylint: disable=missing-function-docstring, missing-module-docstring, unused-import
|
2
|
-
|
3
|
-
import numpy as np
|
4
|
-
import pytest
|
5
|
-
|
6
|
-
from bec_widgets.widgets.figure import BECFigure
|
7
|
-
from bec_widgets.widgets.figure.plots.image.image import BECImageShow
|
8
|
-
from bec_widgets.widgets.figure.plots.motor_map.motor_map import BECMotorMap
|
9
|
-
from bec_widgets.widgets.figure.plots.waveform.waveform import BECWaveform
|
10
|
-
|
11
|
-
from .client_mocks import mocked_client
|
12
|
-
from .conftest import create_widget
|
13
|
-
|
14
|
-
|
15
|
-
def test_bec_figure_init(qtbot, mocked_client):
|
16
|
-
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
17
|
-
assert bec_figure is not None
|
18
|
-
assert bec_figure.client is not None
|
19
|
-
assert isinstance(bec_figure, BECFigure)
|
20
|
-
assert bec_figure.config.widget_class == "BECFigure"
|
21
|
-
|
22
|
-
|
23
|
-
def test_bec_figure_init_with_config(mocked_client):
|
24
|
-
config = {"widget_class": "BECFigure", "gui_id": "test_gui_id", "theme": "dark"}
|
25
|
-
widget = BECFigure(client=mocked_client, config=config)
|
26
|
-
assert widget.config.gui_id == "test_gui_id"
|
27
|
-
assert widget.config.theme == "dark"
|
28
|
-
|
29
|
-
|
30
|
-
def test_bec_figure_add_remove_plot(qtbot, mocked_client):
|
31
|
-
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
32
|
-
initial_count = len(bec_figure._widgets)
|
33
|
-
|
34
|
-
# Adding 3 widgets - 2 WaveformBase and 1 PlotBase
|
35
|
-
w0 = bec_figure.plot(new=True)
|
36
|
-
w1 = bec_figure.plot(new=True)
|
37
|
-
w2 = bec_figure.add_widget(widget_type="BECPlotBase")
|
38
|
-
|
39
|
-
# Check if the widgets were added
|
40
|
-
assert len(bec_figure._widgets) == initial_count + 3
|
41
|
-
assert w0.gui_id in bec_figure._widgets
|
42
|
-
assert w1.gui_id in bec_figure._widgets
|
43
|
-
assert w2.gui_id in bec_figure._widgets
|
44
|
-
assert bec_figure._widgets[w0.gui_id].config.widget_class == "BECWaveform"
|
45
|
-
assert bec_figure._widgets[w1.gui_id].config.widget_class == "BECWaveform"
|
46
|
-
assert bec_figure._widgets[w2.gui_id].config.widget_class == "BECPlotBase"
|
47
|
-
|
48
|
-
# Check accessing positions by the grid in figure
|
49
|
-
assert bec_figure[0, 0] == w0
|
50
|
-
assert bec_figure[1, 0] == w1
|
51
|
-
assert bec_figure[2, 0] == w2
|
52
|
-
|
53
|
-
# Removing 1 widget
|
54
|
-
bec_figure.remove(widget_id=w0.gui_id)
|
55
|
-
assert len(bec_figure._widgets) == initial_count + 2
|
56
|
-
assert w0.gui_id not in bec_figure._widgets
|
57
|
-
assert w2.gui_id in bec_figure._widgets
|
58
|
-
assert bec_figure._widgets[w1.gui_id].config.widget_class == "BECWaveform"
|
59
|
-
|
60
|
-
|
61
|
-
def test_add_different_types_of_widgets(qtbot, mocked_client):
|
62
|
-
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
63
|
-
plt = bec_figure.plot(x_name="samx", y_name="bpm4i")
|
64
|
-
im = bec_figure.image("eiger")
|
65
|
-
motor_map = bec_figure.motor_map("samx", "samy")
|
66
|
-
|
67
|
-
assert plt.__class__ == BECWaveform
|
68
|
-
assert im.__class__ == BECImageShow
|
69
|
-
assert motor_map.__class__ == BECMotorMap
|
70
|
-
|
71
|
-
|
72
|
-
def test_access_widgets_access_errors(qtbot, mocked_client):
|
73
|
-
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
74
|
-
bec_figure.plot(row=0, col=0)
|
75
|
-
|
76
|
-
# access widget by non-existent coordinates
|
77
|
-
with pytest.raises(ValueError) as excinfo:
|
78
|
-
bec_figure[0, 2]
|
79
|
-
assert "No widget at coordinates (0, 2)" in str(excinfo.value)
|
80
|
-
|
81
|
-
# access widget by non-existent widget_id
|
82
|
-
with pytest.raises(KeyError) as excinfo:
|
83
|
-
bec_figure["non_existent_widget"]
|
84
|
-
assert "Widget with id 'non_existent_widget' not found" in str(excinfo.value)
|
85
|
-
|
86
|
-
# access widget by wrong type
|
87
|
-
with pytest.raises(TypeError) as excinfo:
|
88
|
-
bec_figure[1.2]
|
89
|
-
assert (
|
90
|
-
"Key must be a string (widget id) or a tuple of two integers (grid coordinates)"
|
91
|
-
in str(excinfo.value)
|
92
|
-
)
|
93
|
-
|
94
|
-
|
95
|
-
def test_add_plot_to_occupied_position(qtbot, mocked_client):
|
96
|
-
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
97
|
-
bec_figure.plot(row=0, col=0)
|
98
|
-
|
99
|
-
with pytest.raises(ValueError) as excinfo:
|
100
|
-
bec_figure.plot(row=0, col=0, new=True)
|
101
|
-
assert "Position at row 0 and column 0 is already occupied." in str(excinfo.value)
|
102
|
-
|
103
|
-
|
104
|
-
def test_remove_plots(qtbot, mocked_client):
|
105
|
-
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
106
|
-
w1 = bec_figure.plot(row=0, col=0)
|
107
|
-
w2 = bec_figure.plot(row=0, col=1)
|
108
|
-
w3 = bec_figure.plot(row=1, col=0)
|
109
|
-
w4 = bec_figure.plot(row=1, col=1)
|
110
|
-
|
111
|
-
assert bec_figure[0, 0] == w1
|
112
|
-
assert bec_figure[0, 1] == w2
|
113
|
-
assert bec_figure[1, 0] == w3
|
114
|
-
assert bec_figure[1, 1] == w4
|
115
|
-
|
116
|
-
# remove by coordinates
|
117
|
-
bec_figure[0, 0].remove()
|
118
|
-
assert w1.gui_id not in bec_figure._widgets
|
119
|
-
|
120
|
-
# remove by widget_id
|
121
|
-
bec_figure.remove(widget_id=w2.gui_id)
|
122
|
-
assert w2.gui_id not in bec_figure._widgets
|
123
|
-
|
124
|
-
# remove by widget object
|
125
|
-
w3.remove()
|
126
|
-
assert w3.gui_id not in bec_figure._widgets
|
127
|
-
|
128
|
-
# check the remaining widget 4
|
129
|
-
assert bec_figure[0, 0] == w4
|
130
|
-
assert bec_figure[w4.gui_id] == w4
|
131
|
-
assert w4.gui_id in bec_figure._widgets
|
132
|
-
assert len(bec_figure._widgets) == 1
|
133
|
-
|
134
|
-
|
135
|
-
def test_remove_plots_by_coordinates_ints(qtbot, mocked_client):
|
136
|
-
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
137
|
-
w1 = bec_figure.plot(row=0, col=0)
|
138
|
-
w2 = bec_figure.plot(row=0, col=1)
|
139
|
-
|
140
|
-
bec_figure.remove(row=0, col=0)
|
141
|
-
assert w1.gui_id not in bec_figure._widgets
|
142
|
-
assert w2.gui_id in bec_figure._widgets
|
143
|
-
assert bec_figure[0, 0] == w2
|
144
|
-
assert len(bec_figure._widgets) == 1
|
145
|
-
|
146
|
-
|
147
|
-
def test_remove_plots_by_coordinates_tuple(qtbot, mocked_client):
|
148
|
-
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
149
|
-
w1 = bec_figure.plot(row=0, col=0)
|
150
|
-
w2 = bec_figure.plot(row=0, col=1)
|
151
|
-
|
152
|
-
bec_figure.remove(coordinates=(0, 0))
|
153
|
-
assert w1.gui_id not in bec_figure._widgets
|
154
|
-
assert w2.gui_id in bec_figure._widgets
|
155
|
-
assert bec_figure[0, 0] == w2
|
156
|
-
assert len(bec_figure._widgets) == 1
|
157
|
-
|
158
|
-
|
159
|
-
def test_remove_plot_by_id_error(qtbot, mocked_client):
|
160
|
-
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
161
|
-
bec_figure.plot()
|
162
|
-
|
163
|
-
with pytest.raises(ValueError) as excinfo:
|
164
|
-
bec_figure.remove(widget_id="non_existent_widget")
|
165
|
-
assert "Widget with ID 'non_existent_widget' does not exist." in str(excinfo.value)
|
166
|
-
|
167
|
-
|
168
|
-
def test_remove_plot_by_coordinates_error(qtbot, mocked_client):
|
169
|
-
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
170
|
-
bec_figure.plot(row=0, col=0)
|
171
|
-
|
172
|
-
with pytest.raises(ValueError) as excinfo:
|
173
|
-
bec_figure.remove(0, 1)
|
174
|
-
assert "No widget at coordinates (0, 1)" in str(excinfo.value)
|
175
|
-
|
176
|
-
|
177
|
-
def test_remove_plot_by_providing_nothing(qtbot, mocked_client):
|
178
|
-
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
179
|
-
bec_figure.plot(row=0, col=0)
|
180
|
-
|
181
|
-
with pytest.raises(ValueError) as excinfo:
|
182
|
-
bec_figure.remove()
|
183
|
-
assert "Must provide either widget_id or coordinates for removal." in str(excinfo.value)
|
184
|
-
|
185
|
-
|
186
|
-
# def test_change_theme(bec_figure): #TODO do no work at python 3.12
|
187
|
-
# bec_figure.change_theme("dark")
|
188
|
-
# assert bec_figure.config.theme == "dark"
|
189
|
-
# assert bec_figure.backgroundBrush().color().name() == "#000000"
|
190
|
-
# bec_figure.change_theme("light")
|
191
|
-
# assert bec_figure.config.theme == "light"
|
192
|
-
# assert bec_figure.backgroundBrush().color().name() == "#ffffff"
|
193
|
-
# bec_figure.change_theme("dark")
|
194
|
-
# assert bec_figure.config.theme == "dark"
|
195
|
-
# assert bec_figure.backgroundBrush().color().name() == "#000000"
|
196
|
-
|
197
|
-
|
198
|
-
def test_change_layout(qtbot, mocked_client):
|
199
|
-
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
200
|
-
w1 = bec_figure.plot(row=0, col=0)
|
201
|
-
w2 = bec_figure.plot(row=0, col=1)
|
202
|
-
w3 = bec_figure.plot(row=1, col=0)
|
203
|
-
w4 = bec_figure.plot(row=1, col=1)
|
204
|
-
|
205
|
-
bec_figure.change_layout(max_columns=1)
|
206
|
-
|
207
|
-
assert np.shape(bec_figure.grid) == (4, 1)
|
208
|
-
assert bec_figure[0, 0] == w1
|
209
|
-
assert bec_figure[1, 0] == w2
|
210
|
-
assert bec_figure[2, 0] == w3
|
211
|
-
assert bec_figure[3, 0] == w4
|
212
|
-
|
213
|
-
bec_figure.change_layout(max_rows=1)
|
214
|
-
|
215
|
-
assert np.shape(bec_figure.grid) == (1, 4)
|
216
|
-
assert bec_figure[0, 0] == w1
|
217
|
-
assert bec_figure[0, 1] == w2
|
218
|
-
assert bec_figure[0, 2] == w3
|
219
|
-
assert bec_figure[0, 3] == w4
|
220
|
-
|
221
|
-
|
222
|
-
def test_clear_all(qtbot, mocked_client):
|
223
|
-
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
224
|
-
bec_figure.plot(row=0, col=0)
|
225
|
-
bec_figure.plot(row=0, col=1)
|
226
|
-
bec_figure.plot(row=1, col=0)
|
227
|
-
bec_figure.plot(row=1, col=1)
|
228
|
-
|
229
|
-
bec_figure.clear_all()
|
230
|
-
|
231
|
-
assert len(bec_figure._widgets) == 0
|
232
|
-
assert np.shape(bec_figure.grid) == (0,)
|
233
|
-
|
234
|
-
|
235
|
-
def test_shortcuts(qtbot, mocked_client):
|
236
|
-
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
237
|
-
plt = bec_figure.plot(x_name="samx", y_name="bpm4i")
|
238
|
-
im = bec_figure.image("eiger")
|
239
|
-
motor_map = bec_figure.motor_map("samx", "samy")
|
240
|
-
|
241
|
-
assert plt.config.widget_class == "BECWaveform"
|
242
|
-
assert plt.__class__ == BECWaveform
|
243
|
-
assert im.config.widget_class == "BECImageShow"
|
244
|
-
assert im.__class__ == BECImageShow
|
245
|
-
assert motor_map.config.widget_class == "BECMotorMap"
|
246
|
-
assert motor_map.__class__ == BECMotorMap
|
247
|
-
|
248
|
-
|
249
|
-
def test_plot_access_factory(qtbot, mocked_client):
|
250
|
-
bec_figure = create_widget(qtbot, BECFigure, client=mocked_client)
|
251
|
-
plt_00 = bec_figure.plot(x_name="samx", y_name="bpm4i")
|
252
|
-
plt_01 = bec_figure.plot(x_name="samx", y_name="bpm4i", row=0, col=1)
|
253
|
-
plt_10 = bec_figure.plot(new=True)
|
254
|
-
|
255
|
-
assert bec_figure.widget_list[0] == plt_00
|
256
|
-
assert bec_figure.widget_list[1] == plt_01
|
257
|
-
assert bec_figure.widget_list[2] == plt_10
|
258
|
-
assert bec_figure.axes(row=0, col=0) == plt_00
|
259
|
-
assert bec_figure.axes(row=0, col=1) == plt_01
|
260
|
-
assert bec_figure.axes(row=1, col=0) == plt_10
|
261
|
-
|
262
|
-
assert len(plt_00.curves) == 1
|
263
|
-
assert len(plt_01.curves) == 1
|
264
|
-
assert len(plt_10.curves) == 0
|
265
|
-
|
266
|
-
# update plt_00
|
267
|
-
bec_figure.plot(x_name="samx", y_name="bpm3a")
|
268
|
-
bec_figure.plot(x=[1, 2, 3], y=[1, 2, 3], row=0, col=0)
|
269
|
-
|
270
|
-
assert len(plt_00.curves) == 3
|
@@ -1,63 +0,0 @@
|
|
1
|
-
# pylint: disable=missing-function-docstring, missing-module-docstring, unused-import
|
2
|
-
from unittest import mock
|
3
|
-
|
4
|
-
import numpy as np
|
5
|
-
import pytest
|
6
|
-
from bec_lib import messages
|
7
|
-
from qtpy.QtGui import QFontInfo
|
8
|
-
|
9
|
-
from bec_widgets.widgets.figure import BECFigure
|
10
|
-
|
11
|
-
from .client_mocks import mocked_client
|
12
|
-
from .conftest import create_widget
|
13
|
-
|
14
|
-
|
15
|
-
@pytest.fixture
|
16
|
-
def bec_image_show(bec_figure):
|
17
|
-
yield bec_figure.image("eiger")
|
18
|
-
|
19
|
-
|
20
|
-
def test_on_image_update(qtbot, mocked_client):
|
21
|
-
bec_image_show = create_widget(qtbot, BECFigure, client=mocked_client).image("eiger")
|
22
|
-
data = np.random.rand(100, 100)
|
23
|
-
msg = messages.DeviceMonitor2DMessage(device="eiger", data=data, metadata={"scan_id": "12345"})
|
24
|
-
bec_image_show.on_image_update(msg.content, msg.metadata)
|
25
|
-
img = bec_image_show.images[0]
|
26
|
-
assert np.array_equal(img.get_data(), data)
|
27
|
-
|
28
|
-
|
29
|
-
def test_autorange_on_image_update(qtbot, mocked_client):
|
30
|
-
bec_image_show = create_widget(qtbot, BECFigure, client=mocked_client).image("eiger")
|
31
|
-
# Check if autorange mode "mean" works, should be default
|
32
|
-
data = np.random.rand(100, 100)
|
33
|
-
msg = messages.DeviceMonitor2DMessage(device="eiger", data=data, metadata={"scan_id": "12345"})
|
34
|
-
bec_image_show.on_image_update(msg.content, msg.metadata)
|
35
|
-
img = bec_image_show.images[0]
|
36
|
-
assert np.array_equal(img.get_data(), data)
|
37
|
-
vmin = max(np.mean(data) - 2 * np.std(data), 0)
|
38
|
-
vmax = np.mean(data) + 2 * np.std(data)
|
39
|
-
assert np.isclose(img.color_bar.getLevels(), (vmin, vmax), rtol=(1e-5, 1e-5)).all()
|
40
|
-
# Test general update with autorange True, mode "max"
|
41
|
-
bec_image_show.set_autorange_mode("max")
|
42
|
-
bec_image_show.on_image_update(msg.content, msg.metadata)
|
43
|
-
img = bec_image_show.images[0]
|
44
|
-
vmin = np.min(data)
|
45
|
-
vmax = np.max(data)
|
46
|
-
assert np.array_equal(img.get_data(), data)
|
47
|
-
assert np.isclose(img.color_bar.getLevels(), (vmin, vmax), rtol=(1e-5, 1e-5)).all()
|
48
|
-
# Change the input data, and switch to autorange False, colormap levels should stay untouched
|
49
|
-
data *= 100
|
50
|
-
msg = messages.DeviceMonitor2DMessage(device="eiger", data=data, metadata={"scan_id": "12345"})
|
51
|
-
bec_image_show.set_autorange(False)
|
52
|
-
bec_image_show.on_image_update(msg.content, msg.metadata)
|
53
|
-
img = bec_image_show.images[0]
|
54
|
-
assert np.array_equal(img.get_data(), data)
|
55
|
-
assert np.isclose(img.color_bar.getLevels(), (vmin, vmax), rtol=(1e-3, 1e-3)).all()
|
56
|
-
# Reactivate autorange, should now scale the new data
|
57
|
-
bec_image_show.set_autorange(True)
|
58
|
-
bec_image_show.set_autorange_mode("mean")
|
59
|
-
bec_image_show.on_image_update(msg.content, msg.metadata)
|
60
|
-
img = bec_image_show.images[0]
|
61
|
-
vmin = max(np.mean(data) - 2 * np.std(data), 0)
|
62
|
-
vmax = np.mean(data) + 2 * np.std(data)
|
63
|
-
assert np.isclose(img.color_bar.getLevels(), (vmin, vmax), rtol=(1e-5, 1e-5)).all()
|