mirror of
https://github.com/bec-project/bec_widgets.git
synced 2026-04-14 20:50:55 +02:00
Compare commits
13 Commits
v1.3.1
...
fix/temp-d
| Author | SHA1 | Date | |
|---|---|---|---|
| 9c49c33fb7 | |||
|
|
bf0b49b863 | ||
| 11e5937ae0 | |||
| 4f31ea655c | |||
| 64df805a9e | |||
| 035136d517 | |||
| b2eb71aae0 | |||
|
|
1e6659c379 | ||
| 5fabd4bea9 | |||
| 4f0693cae3 | |||
|
|
ba76d6bb86 | ||
| 2304c9f849 | |||
| c6e48ec1fe |
193
CHANGELOG.md
193
CHANGELOG.md
@@ -1,172 +1,209 @@
|
||||
# CHANGELOG
|
||||
|
||||
|
||||
## v1.4.0 (2024-11-11)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- **crosshair**: Label of coordinates of TextItem displays numbers in general format
|
||||
([`11e5937`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/11e5937ae0f3c1413acd4e66878a692ebe4ef7d0))
|
||||
|
||||
- **crosshair**: Label of coordinates of TextItem is updated according to the current theme of qapp
|
||||
([`4f31ea6`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/4f31ea655cf6190e141e6a2720a2d6da517a2b5b))
|
||||
|
||||
- **crosshair**: Log is separately scaled for backend logic and for signal emit
|
||||
([`b2eb71a`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/b2eb71aae0b6a7c82158f2d150ae1e31411cfdeb))
|
||||
|
||||
### Features
|
||||
|
||||
- **crosshair**: Textitem to display crosshair coordinates
|
||||
([`035136d`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/035136d5171ec5f4311d15a9aa5bad2bdbc1f6cb))
|
||||
|
||||
### Testing
|
||||
|
||||
- **crosshair**: Tests extended
|
||||
([`64df805`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/64df805a9ed92bb97e580ac3bc0a1bbd2b1cb81e))
|
||||
|
||||
|
||||
## v1.3.3 (2024-11-07)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- **scan_control**: Devicelineedit kwargs readings changed to get name of the positioner
|
||||
([`5fabd4b`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/5fabd4bea95bafd2352102686357cc1db80813fd))
|
||||
|
||||
### Documentation
|
||||
|
||||
- Update outdated text in docs
|
||||
([`4f0693c`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/4f0693cae34b391d75884837e1ae6353a0501868))
|
||||
|
||||
|
||||
## v1.3.2 (2024-11-05)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- **plot_base**: Legend text color is changed when changing dark-light theme
|
||||
([`2304c9f`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/2304c9f8497c1ab1492f3e6690bb79b0464c0df8))
|
||||
|
||||
### Build System
|
||||
|
||||
- Pyside6 version fixed 6.7.2
|
||||
([`c6e48ec`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/c6e48ec1fe5aaee6a7c7a6f930f1520cd439cdb2))
|
||||
|
||||
|
||||
## v1.3.1 (2024-10-31)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* fix(ophyd_kind_util): Kind enums are imported from the bec widget util class ([`940ee65`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/940ee6552c1ee8d9b4e4a74c62351f2e133ab678))
|
||||
- **ophyd_kind_util**: Kind enums are imported from the bec widget util class
|
||||
([`940ee65`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/940ee6552c1ee8d9b4e4a74c62351f2e133ab678))
|
||||
|
||||
|
||||
## v1.3.0 (2024-10-30)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* fix(colors): extend color map validation for matplotlib and colorcet maps (if available) ([`14dd8c5`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/14dd8c5b2947c92f6643b888d71975e4e8d4ee88))
|
||||
- **colors**: Extend color map validation for matplotlib and colorcet maps (if available)
|
||||
([`14dd8c5`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/14dd8c5b2947c92f6643b888d71975e4e8d4ee88))
|
||||
|
||||
### Features
|
||||
|
||||
* feat(colormap_button): colormap button with menu to select colormap filtered by the colormap type ([`b039933`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/b039933405e2fbe92bd81bd0748e79e8d443a741))
|
||||
- **colormap_button**: Colormap button with menu to select colormap filtered by the colormap type
|
||||
([`b039933`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/b039933405e2fbe92bd81bd0748e79e8d443a741))
|
||||
|
||||
|
||||
## v1.2.0 (2024-10-25)
|
||||
|
||||
### Features
|
||||
|
||||
* feat(colors): evenly spaced color generation + new golden ratio calculation ([`40c9fea`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/40c9fea35f869ef52e05948dd1989bcd99f602e0))
|
||||
- **colors**: Evenly spaced color generation + new golden ratio calculation
|
||||
([`40c9fea`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/40c9fea35f869ef52e05948dd1989bcd99f602e0))
|
||||
|
||||
### Refactoring
|
||||
|
||||
* refactor: add bec_lib version to statusbox ([`5d4b86e`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/5d4b86e1c6e1800051afce4f991153e370767fa6))
|
||||
- Add bec_lib version to statusbox
|
||||
([`5d4b86e`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/5d4b86e1c6e1800051afce4f991153e370767fa6))
|
||||
|
||||
|
||||
## v1.1.0 (2024-10-25)
|
||||
|
||||
### Features
|
||||
|
||||
* feat: add filter i/o utility class ([`0350833`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/0350833f36e0a7cadce4173f9b1d1fbfdf985375))
|
||||
- Add filter i/o utility class
|
||||
([`0350833`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/0350833f36e0a7cadce4173f9b1d1fbfdf985375))
|
||||
|
||||
### Refactoring
|
||||
|
||||
* refactor: do not flush selection upon receiving config update; allow widgetIO to receive kwargs to be able to use get_value to receive string instead of int for QComboBox ([`91959e8`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/91959e82de8586934af3ebb5aaa0923930effc51))
|
||||
- Do not flush selection upon receiving config update; allow widgetIO to receive kwargs to be able
|
||||
to use get_value to receive string instead of int for QComboBox
|
||||
([`91959e8`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/91959e82de8586934af3ebb5aaa0923930effc51))
|
||||
|
||||
* refactor: allow to set selection in DeviceInput; automatic update of selection on device config update; cleanup ([`5eb15b7`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/5eb15b785f12e30eb8ccbc56d4ad9e759a4cf5eb))
|
||||
- Allow to set selection in DeviceInput; automatic update of selection on device config update;
|
||||
cleanup
|
||||
([`5eb15b7`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/5eb15b785f12e30eb8ccbc56d4ad9e759a4cf5eb))
|
||||
|
||||
* refactor: cleanup, added device_signal for signal inputs ([`6fb2055`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/6fb20552ff57978f4aeb79fd7f062f8d6b5581e7))
|
||||
- Cleanup, added device_signal for signal inputs
|
||||
([`6fb2055`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/6fb20552ff57978f4aeb79fd7f062f8d6b5581e7))
|
||||
|
||||
### Testing
|
||||
|
||||
* test(scan_control): tests added for grid_scan to ensure scan_args signal validity ([`acb7902`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/acb79020d4be546efc001ff47b6f5cdba2ee9375))
|
||||
- **scan_control**: Tests added for grid_scan to ensure scan_args signal validity
|
||||
([`acb7902`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/acb79020d4be546efc001ff47b6f5cdba2ee9375))
|
||||
|
||||
|
||||
## v1.0.2 (2024-10-22)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* fix(scan_control): scan args signal fixed to emit list instead of hardcoded structure ([`4f5448c`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/4f5448cf51a204e077af162c7f0aed1f1a60e57a))
|
||||
- **scan_control**: Scan args signal fixed to emit list instead of hardcoded structure
|
||||
([`4f5448c`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/4f5448cf51a204e077af162c7f0aed1f1a60e57a))
|
||||
|
||||
|
||||
## v1.0.1 (2024-10-22)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* fix(waveform): added support for live_data and data access ([`7469c89`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/7469c892c8076fc09e61f173df6920c551241cec))
|
||||
- **waveform**: Added support for live_data and data access
|
||||
([`7469c89`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/7469c892c8076fc09e61f173df6920c551241cec))
|
||||
|
||||
|
||||
## v1.0.0 (2024-10-18)
|
||||
|
||||
### Breaking
|
||||
|
||||
* feat!: ability to disable scatter from waveform & compatible crosshair with down sampling ([`2ab12ed`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/2ab12ed60abb995abc381d9330fdcf399796d9e5))
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* fix(crosshair): downsample clear markers ([`f9a889f`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/f9a889fc6d380b9e587edcb465203122ea0bffc1))
|
||||
- **crosshair**: Downsample clear markers
|
||||
([`f9a889f`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/f9a889fc6d380b9e587edcb465203122ea0bffc1))
|
||||
|
||||
### Features
|
||||
|
||||
- Ability to disable scatter from waveform & compatible crosshair with down sampling
|
||||
([`2ab12ed`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/2ab12ed60abb995abc381d9330fdcf399796d9e5))
|
||||
|
||||
|
||||
## v0.119.0 (2024-10-17)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* fix: fix syntax due to change of api for simulated devices ([`19f4e40`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/19f4e407e00ee242973ca4c3f90e4e41a4d3e315))
|
||||
- Fix syntax due to change of api for simulated devices
|
||||
([`19f4e40`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/19f4e407e00ee242973ca4c3f90e4e41a4d3e315))
|
||||
|
||||
* fix: remove wrongly scoped test ([`a23841b`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/a23841b2553dc7162da943715d58275c7dc39ed9))
|
||||
- Remove wrongly scoped test
|
||||
([`a23841b`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/a23841b2553dc7162da943715d58275c7dc39ed9))
|
||||
|
||||
* fix: rename 'compact' property -> 'compact_view' ([`6982711`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/6982711fea5fb8a73845ed7c0692e3ec53ef7871))
|
||||
- Rename 'compact' property -> 'compact_view'
|
||||
([`6982711`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/6982711fea5fb8a73845ed7c0692e3ec53ef7871))
|
||||
|
||||
* fix: Alignment 1D update, make app window a main window (in .ui file) ([`0015f0e`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/0015f0e2d62adc02d3ef334e1f6dbb2d0288fec6))
|
||||
- Alignment 1D update, make app window a main window (in .ui file)
|
||||
([`0015f0e`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/0015f0e2d62adc02d3ef334e1f6dbb2d0288fec6))
|
||||
|
||||
* fix: set (Minimum, Fixed) size policy on Stop button ([`523cc43`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/523cc435725b10b7d59a4477a1aaa24a1f3e37a2))
|
||||
- Set (Minimum, Fixed) size policy on Stop button
|
||||
([`523cc43`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/523cc435725b10b7d59a4477a1aaa24a1f3e37a2))
|
||||
|
||||
### Features
|
||||
|
||||
* feat: new PositionerGroup widget ([`af9655d`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/af9655de0c541092437accfbaa779628a2f48ccb))
|
||||
- New PositionerGroup widget
|
||||
([`af9655d`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/af9655de0c541092437accfbaa779628a2f48ccb))
|
||||
|
||||
* feat: add 'expand_popup' property to CompactPopupWidget
|
||||
- Add 'expand_popup' property to CompactPopupWidget
|
||||
([`e4121a0`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/e4121a01cb6b8d496e630cd43bc642b994b8f310))
|
||||
|
||||
This property tells if expand should show a popup (by default), or
|
||||
if the widget should expand in-place ([`e4121a0`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/e4121a01cb6b8d496e630cd43bc642b994b8f310))
|
||||
This property tells if expand should show a popup (by default), or if the widget should expand
|
||||
in-place
|
||||
|
||||
* feat: PositionerBox with a popup view ([`2615787`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/261578796f1de8ca9cab9b91659bc1484f7aa89d))
|
||||
- Positionerbox with a popup view
|
||||
([`2615787`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/261578796f1de8ca9cab9b91659bc1484f7aa89d))
|
||||
|
||||
* feat: emit 'device_selected' and 'scan_axis' from scan control widget ([`0b9b1a3`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/0b9b1a3c89a98505079f7d4078915b7bbfaa1e23))
|
||||
- Emit 'device_selected' and 'scan_axis' from scan control widget
|
||||
([`0b9b1a3`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/0b9b1a3c89a98505079f7d4078915b7bbfaa1e23))
|
||||
|
||||
* feat: new 'device_selected' signals to ScanControl, ScanGroupBox, DeviceLineEdit ([`9801d27`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/9801d2769eb0ee95c94ec0c011e1dac1407142ae))
|
||||
- New 'device_selected' signals to ScanControl, ScanGroupBox, DeviceLineEdit
|
||||
([`9801d27`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/9801d2769eb0ee95c94ec0c011e1dac1407142ae))
|
||||
|
||||
### Refactoring
|
||||
|
||||
* refactor: redesign of scan selection and scan control boxes ([`a69d287`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/a69d2870e2b3539739781d741b27b8599c0f4abd))
|
||||
- Redesign of scan selection and scan control boxes
|
||||
([`a69d287`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/a69d2870e2b3539739781d741b27b8599c0f4abd))
|
||||
|
||||
* refactor: move add/remove bundle to scan group box ([`e3d0a7b`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/e3d0a7bbf9918dc16eb7227a178c310256ce570d))
|
||||
- Move add/remove bundle to scan group box
|
||||
([`e3d0a7b`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/e3d0a7bbf9918dc16eb7227a178c310256ce570d))
|
||||
|
||||
|
||||
## v0.118.0 (2024-10-13)
|
||||
|
||||
### Documentation
|
||||
|
||||
* docs(sphinx-build): adjusted pyside verion ([`b236951`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/b23695167ab969f754a058ffdccca2b40f00a008))
|
||||
- **sphinx-build**: Adjusted pyside verion
|
||||
([`b236951`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/b23695167ab969f754a058ffdccca2b40f00a008))
|
||||
|
||||
### Features
|
||||
|
||||
* feat(image): image widget can take data from monitor_1d endpoint ([`9ef1d1c`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/9ef1d1c9ac2178d9fa2e655942208f8abbdf5c1b))
|
||||
- **image**: Image widget can take data from monitor_1d endpoint
|
||||
([`9ef1d1c`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/9ef1d1c9ac2178d9fa2e655942208f8abbdf5c1b))
|
||||
|
||||
|
||||
## v0.117.1 (2024-10-11)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* fix(FPS): qtimer cleanup leaking ([`3a22392`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/3a2239278075de7489ad10a58c31d7d89715e221))
|
||||
|
||||
### Unknown
|
||||
|
||||
* feature(vscode): added support for vscode instructions ([`f5f1f6c`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/f5f1f6c304b890dc162e8653005233bce4ea82e4))
|
||||
|
||||
* feature(vscode): support for controlling vscode from widgets ([`9238679`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/923867947f62db026ac0378c30ef62c883596058))
|
||||
|
||||
|
||||
## v0.117.0 (2024-10-11)
|
||||
|
||||
### Features
|
||||
|
||||
* feat(utils): FPS counter utility based on the viewBox updates, integrated to waveform and image widget ([`8c5ef26`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/8c5ef268430d5243ac05fcbbdb6b76ad24ac5735))
|
||||
|
||||
### Unknown
|
||||
|
||||
* tests(plot_base): tests extended ([`8dc892d`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/8dc892df0a47ccbdd812555b7c5775a455a23ede))
|
||||
|
||||
|
||||
## v0.116.0 (2024-10-11)
|
||||
|
||||
### Build System
|
||||
|
||||
* build: fix PySide6 to 6.7.2 ([`908dbc1`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/908dbc1760da5b323722207163f00850b84fb90b))
|
||||
|
||||
### Features
|
||||
|
||||
* feat: UI changes to have top toolbar with compact popup widgets (fix issue #360) ([`499b6b9`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/499b6b9a12efd931b5728b519404c41a7e29e4d6))
|
||||
|
||||
* feat: adapt BECQueue and BECStatusBox widgets to use CompactPopupWidget ([`94ce92f`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/94ce92f5b054d25ea3bb7976c1f75e14b78b9edc))
|
||||
|
||||
* feat: add 'CompactPopupWidget' container widget
|
||||
|
||||
Makes it easy to write widgets which can have a compact
|
||||
representation with LED-like global state indicator,
|
||||
with the possibility to display a popup dialog with more
|
||||
complete UI ([`49268e3`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/49268e3829406d70b09e4d88989812f5578e46f4))
|
||||
|
||||
|
||||
## v0.115.0 (2024-10-08)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* fix: make Alignment1D a MainWindow as it is an application ([`c5e9ed6`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/c5e9ed6e422acb908e1ada32822f5d7cc256ade7))
|
||||
- **FPS**: Qtimer cleanup leaking
|
||||
([`3a22392`](https://gitlab.psi.ch/bec/bec_widgets/-/commit/3a2239278075de7489ad10a58c31d7d89715e221))
|
||||
|
||||
@@ -396,6 +396,7 @@ class BECDockArea(RPCBase, BECGuiClientMixin):
|
||||
relative_to: "BECDock | None" = None,
|
||||
closable: "bool" = True,
|
||||
floating: "bool" = False,
|
||||
temporary: "bool" = False,
|
||||
prefix: "str" = "dock",
|
||||
widget: "str | QWidget | None" = None,
|
||||
row: "int" = None,
|
||||
@@ -412,6 +413,7 @@ class BECDockArea(RPCBase, BECGuiClientMixin):
|
||||
relative_to(BECDock): The dock to which the new dock should be added relative to.
|
||||
closable(bool): Whether the dock is closable.
|
||||
floating(bool): Whether the dock is detached after creating.
|
||||
temporary(bool): Whether the dock is temporary. After closing the dock do not return to the parent DockArea.
|
||||
prefix(str): The prefix for the dock name if no name is provided.
|
||||
widget(str|QWidget|None): The widget to be added to the dock. While using RPC, only BEC RPC widgets from RPCWidgetHandler are allowed.
|
||||
row(int): The row of the added widget.
|
||||
|
||||
@@ -2,10 +2,8 @@ from collections import defaultdict
|
||||
|
||||
import numpy as np
|
||||
import pyqtgraph as pg
|
||||
|
||||
# from qtpy.QtCore import QObject, pyqtSignal
|
||||
from qtpy.QtCore import QObject, Qt
|
||||
from qtpy.QtCore import Signal as pyqtSignal
|
||||
from qtpy.QtCore import QObject, Qt, Signal, Slot
|
||||
from qtpy.QtWidgets import QApplication
|
||||
|
||||
|
||||
class NonDownsamplingScatterPlotItem(pg.ScatterPlotItem):
|
||||
@@ -17,14 +15,18 @@ class NonDownsamplingScatterPlotItem(pg.ScatterPlotItem):
|
||||
|
||||
|
||||
class Crosshair(QObject):
|
||||
positionChanged = pyqtSignal(tuple)
|
||||
positionClicked = pyqtSignal(tuple)
|
||||
# QT Position of mouse cursor
|
||||
positionChanged = Signal(tuple)
|
||||
positionClicked = Signal(tuple)
|
||||
# Plain crosshair position signals mapped to real coordinates
|
||||
crosshairChanged = Signal(tuple)
|
||||
crosshairClicked = Signal(tuple)
|
||||
# Signal for 1D plot
|
||||
coordinatesChanged1D = pyqtSignal(tuple)
|
||||
coordinatesClicked1D = pyqtSignal(tuple)
|
||||
coordinatesChanged1D = Signal(tuple)
|
||||
coordinatesClicked1D = Signal(tuple)
|
||||
# Signal for 2D plot
|
||||
coordinatesChanged2D = pyqtSignal(tuple)
|
||||
coordinatesClicked2D = pyqtSignal(tuple)
|
||||
coordinatesChanged2D = Signal(tuple)
|
||||
coordinatesClicked2D = Signal(tuple)
|
||||
|
||||
def __init__(self, plot_item: pg.PlotItem, precision: int = 3, parent=None):
|
||||
"""
|
||||
@@ -47,11 +49,21 @@ class Crosshair(QObject):
|
||||
self.h_line.skip_auto_range = True
|
||||
self.plot_item.addItem(self.v_line, ignoreBounds=True)
|
||||
self.plot_item.addItem(self.h_line, ignoreBounds=True)
|
||||
|
||||
# Add TextItem to display coordinates
|
||||
self.coord_label = pg.TextItem("", anchor=(1, 1), fill=(0, 0, 0, 100))
|
||||
self.coord_label.setVisible(False) # Hide initially
|
||||
self.coord_label.skip_auto_range = True
|
||||
self.plot_item.addItem(self.coord_label)
|
||||
|
||||
# Signals to connect
|
||||
self.proxy = pg.SignalProxy(
|
||||
self.plot_item.scene().sigMouseMoved, rateLimit=60, slot=self.mouse_moved
|
||||
)
|
||||
self.positionChanged.connect(self.update_coord_label)
|
||||
self.plot_item.scene().sigMouseClicked.connect(self.mouse_clicked)
|
||||
|
||||
# Connect signals from pyqtgraph right click menu
|
||||
self.plot_item.ctrl.derivativeCheck.checkStateChanged.connect(self.check_derivatives)
|
||||
self.plot_item.ctrl.logXCheck.checkStateChanged.connect(self.check_log)
|
||||
self.plot_item.ctrl.logYCheck.checkStateChanged.connect(self.check_log)
|
||||
@@ -62,6 +74,44 @@ class Crosshair(QObject):
|
||||
self.marker_clicked_1d = {}
|
||||
self.marker_2d = None
|
||||
self.update_markers()
|
||||
self.check_log()
|
||||
self.check_derivatives()
|
||||
|
||||
self._connect_to_theme_change()
|
||||
|
||||
def _connect_to_theme_change(self):
|
||||
"""Connect to the theme change signal."""
|
||||
qapp = QApplication.instance()
|
||||
if hasattr(qapp, "theme_signal"):
|
||||
qapp.theme_signal.theme_updated.connect(self._update_theme)
|
||||
self._update_theme()
|
||||
|
||||
@Slot(str)
|
||||
def _update_theme(self, theme: str | None = None):
|
||||
"""Update the theme."""
|
||||
if theme is None:
|
||||
qapp = QApplication.instance()
|
||||
if hasattr(qapp, "theme"):
|
||||
theme = qapp.theme.theme
|
||||
else:
|
||||
theme = "dark"
|
||||
self.apply_theme(theme)
|
||||
|
||||
def apply_theme(self, theme: str):
|
||||
"""Apply the theme to the plot."""
|
||||
if theme == "dark":
|
||||
text_color = "w"
|
||||
label_bg_color = (50, 50, 50, 150)
|
||||
elif theme == "light":
|
||||
text_color = "k"
|
||||
label_bg_color = (240, 240, 240, 150)
|
||||
else:
|
||||
text_color = "w"
|
||||
label_bg_color = (50, 50, 50, 150)
|
||||
|
||||
self.coord_label.setColor(text_color)
|
||||
self.coord_label.fill = pg.mkBrush(label_bg_color)
|
||||
self.coord_label.border = pg.mkPen(None)
|
||||
|
||||
def update_markers(self):
|
||||
"""Update the markers for the crosshair, creating new ones if necessary."""
|
||||
@@ -151,21 +201,34 @@ class Crosshair(QObject):
|
||||
|
||||
return None, None
|
||||
|
||||
def closest_x_y_value(self, input_value: float, list_x: list, list_y: list) -> tuple:
|
||||
def closest_x_y_value(self, input_x: float, list_x: list, list_y: list) -> tuple:
|
||||
"""
|
||||
Find the closest x and y value to the input value.
|
||||
|
||||
Args:
|
||||
input_value (float): Input value
|
||||
input_x (float): Input value
|
||||
list_x (list): List of x values
|
||||
list_y (list): List of y values
|
||||
|
||||
Returns:
|
||||
tuple: Closest x and y value
|
||||
"""
|
||||
arr = np.asarray(list_x)
|
||||
i = (np.abs(arr - input_value)).argmin()
|
||||
return list_x[i], list_y[i]
|
||||
# Convert lists to NumPy arrays
|
||||
arr_x = np.asarray(list_x)
|
||||
|
||||
# Get the indices where x is not NaN
|
||||
valid_indices = ~np.isnan(arr_x)
|
||||
|
||||
# Filter x array to exclude NaN values
|
||||
filtered_x = arr_x[valid_indices]
|
||||
|
||||
# Find the index of the closest value in the filtered x array
|
||||
closest_index = np.abs(filtered_x - input_x).argmin()
|
||||
|
||||
# Map back to the original index in the list_x and list_y arrays
|
||||
original_index = np.where(valid_indices)[0][closest_index]
|
||||
|
||||
return list_x[original_index], list_y[original_index]
|
||||
|
||||
def mouse_moved(self, event):
|
||||
"""Handles the mouse moved event, updating the crosshair position and emitting signals.
|
||||
@@ -175,17 +238,15 @@ class Crosshair(QObject):
|
||||
"""
|
||||
pos = event[0]
|
||||
self.update_markers()
|
||||
self.positionChanged.emit((pos.x(), pos.y()))
|
||||
if self.plot_item.vb.sceneBoundingRect().contains(pos):
|
||||
mouse_point = self.plot_item.vb.mapSceneToView(pos)
|
||||
self.v_line.setPos(mouse_point.x())
|
||||
self.h_line.setPos(mouse_point.y())
|
||||
|
||||
x, y = mouse_point.x(), mouse_point.y()
|
||||
if self.is_log_x:
|
||||
x = 10**x
|
||||
if self.is_log_y:
|
||||
y = 10**y
|
||||
self.v_line.setPos(x)
|
||||
self.h_line.setPos(y)
|
||||
scaled_x, scaled_y = self.scale_emitted_coordinates(mouse_point.x(), mouse_point.y())
|
||||
self.crosshairChanged.emit((scaled_x, scaled_y))
|
||||
self.positionChanged.emit((x, y))
|
||||
|
||||
x_snap_values, y_snap_values = self.snap_to_data(x, y)
|
||||
if x_snap_values is None or y_snap_values is None:
|
||||
return
|
||||
@@ -202,7 +263,12 @@ class Crosshair(QObject):
|
||||
if x is None or y is None:
|
||||
continue
|
||||
self.marker_moved_1d[name].setData([x], [y])
|
||||
coordinate_to_emit = (name, round(x, self.precision), round(y, self.precision))
|
||||
x_snapped_scaled, y_snapped_scaled = self.scale_emitted_coordinates(x, y)
|
||||
coordinate_to_emit = (
|
||||
name,
|
||||
round(x_snapped_scaled, self.precision),
|
||||
round(y_snapped_scaled, self.precision),
|
||||
)
|
||||
self.coordinatesChanged1D.emit(coordinate_to_emit)
|
||||
elif isinstance(item, pg.ImageItem):
|
||||
name = item.config.monitor
|
||||
@@ -229,12 +295,10 @@ class Crosshair(QObject):
|
||||
if self.plot_item.vb.sceneBoundingRect().contains(event._scenePos):
|
||||
mouse_point = self.plot_item.vb.mapSceneToView(event._scenePos)
|
||||
x, y = mouse_point.x(), mouse_point.y()
|
||||
scaled_x, scaled_y = self.scale_emitted_coordinates(mouse_point.x(), mouse_point.y())
|
||||
self.crosshairClicked.emit((scaled_x, scaled_y))
|
||||
self.positionClicked.emit((x, y))
|
||||
|
||||
if self.is_log_x:
|
||||
x = 10**x
|
||||
if self.is_log_y:
|
||||
y = 10**y
|
||||
x_snap_values, y_snap_values = self.snap_to_data(x, y)
|
||||
|
||||
if x_snap_values is None or y_snap_values is None:
|
||||
@@ -252,7 +316,12 @@ class Crosshair(QObject):
|
||||
if x is None or y is None:
|
||||
continue
|
||||
self.marker_clicked_1d[name].setData([x], [y])
|
||||
coordinate_to_emit = (name, round(x, self.precision), round(y, self.precision))
|
||||
x_snapped_scaled, y_snapped_scaled = self.scale_emitted_coordinates(x, y)
|
||||
coordinate_to_emit = (
|
||||
name,
|
||||
round(x_snapped_scaled, self.precision),
|
||||
round(y_snapped_scaled, self.precision),
|
||||
)
|
||||
self.coordinatesClicked1D.emit(coordinate_to_emit)
|
||||
elif isinstance(item, pg.ImageItem):
|
||||
name = item.config.monitor
|
||||
@@ -272,10 +341,40 @@ class Crosshair(QObject):
|
||||
for marker in self.marker_clicked_1d.values():
|
||||
marker.clear()
|
||||
|
||||
def scale_emitted_coordinates(self, x, y):
|
||||
"""Scales the emitted coordinates if the axes are in log scale.
|
||||
|
||||
Args:
|
||||
x (float): The x-coordinate
|
||||
y (float): The y-coordinate
|
||||
|
||||
Returns:
|
||||
tuple: The scaled x and y coordinates
|
||||
"""
|
||||
if self.is_log_x:
|
||||
x = 10**x
|
||||
if self.is_log_y:
|
||||
y = 10**y
|
||||
return x, y
|
||||
|
||||
def update_coord_label(self, pos: tuple):
|
||||
"""Updates the coordinate label based on the crosshair position and axis scales.
|
||||
|
||||
Args:
|
||||
pos (tuple): The (x, y) position of the crosshair.
|
||||
"""
|
||||
x, y = pos
|
||||
x_scaled, y_scaled = self.scale_emitted_coordinates(x, y)
|
||||
|
||||
# # Update coordinate label
|
||||
self.coord_label.setText(f"({x_scaled:.{self.precision}g}, {y_scaled:.{self.precision}g})")
|
||||
self.coord_label.setPos(x, y)
|
||||
self.coord_label.setVisible(True)
|
||||
|
||||
def check_log(self):
|
||||
"""Checks if the x or y axis is in log scale and updates the internal state accordingly."""
|
||||
self.is_log_x = self.plot_item.ctrl.logXCheck.isChecked()
|
||||
self.is_log_y = self.plot_item.ctrl.logYCheck.isChecked()
|
||||
self.is_log_x = self.plot_item.axes["bottom"]["item"].logMode
|
||||
self.is_log_y = self.plot_item.axes["left"]["item"].logMode
|
||||
self.clear_markers()
|
||||
|
||||
def check_derivatives(self):
|
||||
@@ -284,6 +383,8 @@ class Crosshair(QObject):
|
||||
self.clear_markers()
|
||||
|
||||
def cleanup(self):
|
||||
self.v_line.deleteLater()
|
||||
self.h_line.deleteLater()
|
||||
self.plot_item.removeItem(self.v_line)
|
||||
self.plot_item.removeItem(self.h_line)
|
||||
self.plot_item.removeItem(self.coord_label)
|
||||
|
||||
self.clear_markers()
|
||||
|
||||
@@ -280,6 +280,7 @@ class BECDockArea(BECWidget, QWidget):
|
||||
relative_to: BECDock | None = None,
|
||||
closable: bool = True,
|
||||
floating: bool = False,
|
||||
temporary: bool = False,
|
||||
prefix: str = "dock",
|
||||
widget: str | QWidget | None = None,
|
||||
row: int = None,
|
||||
@@ -296,6 +297,7 @@ class BECDockArea(BECWidget, QWidget):
|
||||
relative_to(BECDock): The dock to which the new dock should be added relative to.
|
||||
closable(bool): Whether the dock is closable.
|
||||
floating(bool): Whether the dock is detached after creating.
|
||||
temporary(bool): Whether the dock is temporary. After closing the dock do not return to the parent DockArea.
|
||||
prefix(str): The prefix for the dock name if no name is provided.
|
||||
widget(str|QWidget|None): The widget to be added to the dock. While using RPC, only BEC RPC widgets from RPCWidgetHandler are allowed.
|
||||
row(int): The row of the added widget.
|
||||
@@ -317,16 +319,21 @@ class BECDockArea(BECWidget, QWidget):
|
||||
if position is None:
|
||||
position = "bottom"
|
||||
|
||||
if temporary:
|
||||
target_area = self.dock_area.addTempArea()
|
||||
else:
|
||||
target_area = self.dock_area
|
||||
|
||||
dock = BECDock(name=name, parent_dock_area=self, closable=closable)
|
||||
dock.config.position = position
|
||||
self.config.docks[name] = dock.config
|
||||
|
||||
self.dock_area.addDock(dock=dock, position=position, relativeTo=relative_to)
|
||||
target_area.addDock(dock=dock, position=position, relativeTo=relative_to)
|
||||
|
||||
if len(self.dock_area.docks) <= 1:
|
||||
if len(target_area.docks) <= 1:
|
||||
dock.hide_title_bar()
|
||||
elif len(self.dock_area.docks) > 1:
|
||||
for dock in self.dock_area.docks.values():
|
||||
elif len(target_area.docks) > 1:
|
||||
for dock in target_area.docks.values():
|
||||
dock.show_title_bar()
|
||||
|
||||
if widget is not None and isinstance(widget, str):
|
||||
|
||||
@@ -147,6 +147,9 @@ class BECPlotBase(BECConnector, pg.GraphicsLayout):
|
||||
for axis in ["left", "bottom", "right", "top"]:
|
||||
self.plot_item.getAxis(axis).setPen(text_pen)
|
||||
self.plot_item.getAxis(axis).setTextPen(text_pen)
|
||||
if self.plot_item.legend is not None:
|
||||
for sample, label in self.plot_item.legend.items:
|
||||
label.setText(label.text, color=palette.text().color())
|
||||
|
||||
def set(self, **kwargs) -> None:
|
||||
"""
|
||||
@@ -394,8 +397,8 @@ class BECPlotBase(BECConnector, pg.GraphicsLayout):
|
||||
"""Hook the crosshair to all plots."""
|
||||
if self.crosshair is None:
|
||||
self.crosshair = Crosshair(self.plot_item, precision=3)
|
||||
self.crosshair.positionChanged.connect(self.crosshair_position_changed)
|
||||
self.crosshair.positionClicked.connect(self.crosshair_position_clicked)
|
||||
self.crosshair.crosshairChanged.connect(self.crosshair_position_changed)
|
||||
self.crosshair.crosshairClicked.connect(self.crosshair_position_clicked)
|
||||
self.crosshair.coordinatesChanged1D.connect(self.crosshair_coordinates_changed)
|
||||
self.crosshair.coordinatesClicked1D.connect(self.crosshair_coordinates_clicked)
|
||||
self.crosshair.coordinatesChanged2D.connect(self.crosshair_coordinates_changed)
|
||||
@@ -404,8 +407,8 @@ class BECPlotBase(BECConnector, pg.GraphicsLayout):
|
||||
def unhook_crosshair(self) -> None:
|
||||
"""Unhook the crosshair from all plots."""
|
||||
if self.crosshair is not None:
|
||||
self.crosshair.positionChanged.disconnect(self.crosshair_position_changed)
|
||||
self.crosshair.positionClicked.disconnect(self.crosshair_position_clicked)
|
||||
self.crosshair.crosshairChanged.disconnect(self.crosshair_position_changed)
|
||||
self.crosshair.crosshairClicked.disconnect(self.crosshair_position_clicked)
|
||||
self.crosshair.coordinatesChanged1D.disconnect(self.crosshair_coordinates_changed)
|
||||
self.crosshair.coordinatesClicked1D.disconnect(self.crosshair_coordinates_clicked)
|
||||
self.crosshair.coordinatesChanged2D.disconnect(self.crosshair_coordinates_changed)
|
||||
|
||||
@@ -321,7 +321,7 @@ class ScanGroupBox(QGroupBox):
|
||||
for i in range(self.layout.columnCount()):
|
||||
widget = self.layout.itemAtPosition(1, i).widget()
|
||||
if isinstance(widget, DeviceLineEdit) and device_object:
|
||||
value = widget.get_device()
|
||||
value = widget.get_current_device().name
|
||||
else:
|
||||
value = WidgetIO.get_value(widget)
|
||||
kwargs[widget.arg_name] = value
|
||||
|
||||
@@ -29,16 +29,16 @@ In this example, we demonstrate how to add a `TextBox` widget to a `BECDockArea`
|
||||
text_box = gui.add_dock().add_widget("TextBox")
|
||||
|
||||
# Set the text to display
|
||||
text_box.set_text("Hello, World!")
|
||||
text_box.set_plain_text("Hello, World!")
|
||||
```
|
||||
|
||||
## Example 2 - Displaying HTML Content
|
||||
|
||||
The `TextBox` widget can automatically detect and render HTML content. This example shows how to display formatted HTML text.
|
||||
The `TextBox` widget can also render HTML content. This example shows how to display formatted HTML text.
|
||||
|
||||
```python
|
||||
# Set the text to display as HTML
|
||||
text_box.set_text("<h1>Welcome to BEC Widgets</h1><p>This is an example of displaying <strong>HTML</strong> text.</p>")
|
||||
text_box.set_html_text("<h1>Welcome to BEC Widgets</h1><p>This is an example of displaying <strong>HTML</strong> text.</p>")
|
||||
```
|
||||
|
||||
````
|
||||
|
||||
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
||||
|
||||
[project]
|
||||
name = "bec_widgets"
|
||||
version = "1.3.1"
|
||||
version = "1.4.0"
|
||||
description = "BEC Widgets"
|
||||
requires-python = ">=3.10"
|
||||
classifiers = [
|
||||
@@ -38,7 +38,7 @@ dev = [
|
||||
"pytest~=8.0",
|
||||
]
|
||||
pyqt6 = ["PyQt6>=6.7", "PyQt6-WebEngine>=6.7"]
|
||||
pyside6 = ["PySide6~=6.7.2"]
|
||||
pyside6 = ["PySide6==6.7.2"]
|
||||
|
||||
[project.urls]
|
||||
"Bug Tracker" = "https://gitlab.psi.ch/bec/bec_widgets/issues"
|
||||
|
||||
@@ -159,3 +159,94 @@ def test_toolbar_add_utils_progress_bar(bec_dock_area):
|
||||
assert (
|
||||
bec_dock_area.panels["progress_bar_1"].widgets[0].config.widget_class == "RingProgressBar"
|
||||
)
|
||||
|
||||
|
||||
###################################
|
||||
# Tests for Temporary Docks
|
||||
###################################
|
||||
def test_add_temporary_dock(bec_dock_area, qtbot):
|
||||
# Add a temporary dock
|
||||
temp_dock = bec_dock_area.add_dock(name="temp_dock_1", temporary=True)
|
||||
|
||||
# Check that tempAreas has one area
|
||||
assert len(bec_dock_area.dock_area.tempAreas) == 1
|
||||
|
||||
# Check that the dock is in the tempArea's docks
|
||||
temp_area = bec_dock_area.dock_area.tempAreas[0]
|
||||
assert temp_dock.name() in temp_area.docks
|
||||
|
||||
# Close the temporary dock
|
||||
temp_dock.close()
|
||||
qtbot.wait(100)
|
||||
|
||||
# Check that tempAreas is now empty
|
||||
assert len(bec_dock_area.dock_area.tempAreas) == 0
|
||||
|
||||
# Check that the dock is removed from docks
|
||||
assert temp_dock.name() not in bec_dock_area.dock_area.docks
|
||||
|
||||
bec_dock_area.close()
|
||||
|
||||
|
||||
def test_clear_all_with_temporary_docks(bec_dock_area, qtbot):
|
||||
# Add normal docks
|
||||
d0 = bec_dock_area.add_dock(name="dock_0")
|
||||
d1 = bec_dock_area.add_dock(name="dock_1")
|
||||
# Add temporary docks
|
||||
temp_dock_1 = bec_dock_area.add_dock(name="temp_dock_1", temporary=True)
|
||||
temp_dock_2 = bec_dock_area.add_dock(name="temp_dock_2", temporary=True)
|
||||
|
||||
# Check that tempAreas have 2 areas
|
||||
assert len(bec_dock_area.dock_area.tempAreas) == 2
|
||||
|
||||
# Clear all docks
|
||||
bec_dock_area.clear_all()
|
||||
qtbot.wait(100)
|
||||
|
||||
# Check that all docks are removed
|
||||
assert len(bec_dock_area.dock_area.docks) == 0
|
||||
assert len(bec_dock_area.dock_area.tempAreas) == 0
|
||||
|
||||
|
||||
def test_attach_all_removes_temporary_docks(bec_dock_area, qtbot):
|
||||
# Add normal dock
|
||||
d0 = bec_dock_area.add_dock(name="dock_0")
|
||||
# Add temporary dock
|
||||
temp_dock = bec_dock_area.add_dock(name="temp_dock", temporary=True)
|
||||
|
||||
# Detach normal dock
|
||||
d0.detach()
|
||||
|
||||
# Check tempAreas
|
||||
assert len(bec_dock_area.dock_area.tempAreas) == 2 # One for temp_dock, one for detached d0
|
||||
|
||||
# Call attach_all
|
||||
bec_dock_area.attach_all()
|
||||
qtbot.wait(100)
|
||||
|
||||
# Check that tempAreas is now empty
|
||||
assert len(bec_dock_area.dock_area.tempAreas) == 0
|
||||
|
||||
# Check that temp_dock is not in docks
|
||||
assert temp_dock.name() not in bec_dock_area.dock_area.docks
|
||||
|
||||
|
||||
def test_close_temporary_dock(bec_dock_area, qtbot):
|
||||
# Add temporary dock
|
||||
temp_dock = bec_dock_area.add_dock(name="temp_dock", temporary=True)
|
||||
|
||||
# Check tempAreas
|
||||
assert len(bec_dock_area.dock_area.tempAreas) == 1
|
||||
|
||||
# Close the temporary dock
|
||||
temp_dock.close()
|
||||
qtbot.wait(100)
|
||||
|
||||
# Check that tempAreas is now empty
|
||||
assert len(bec_dock_area.dock_area.tempAreas) == 0
|
||||
|
||||
# Check that the dock is removed from docks
|
||||
assert temp_dock.name() not in bec_dock_area.dock_area.docks
|
||||
|
||||
# Close parent area
|
||||
bec_dock_area.close()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# pylint: disable = no-name-in-module,missing-class-docstring, missing-module-docstring
|
||||
import numpy as np
|
||||
import pyqtgraph as pg
|
||||
import pytest
|
||||
from qtpy.QtCore import QPointF
|
||||
from qtpy.QtCore import QPointF, Qt
|
||||
|
||||
from bec_widgets.widgets.image.image_widget import BECImageWidget
|
||||
from bec_widgets.widgets.waveform.waveform_widget import BECWaveformWidget
|
||||
@@ -36,10 +36,6 @@ def image_widget_with_crosshair(qtbot, mocked_client):
|
||||
def test_mouse_moved_lines(plot_widget_with_crosshair):
|
||||
crosshair, plot_item = plot_widget_with_crosshair
|
||||
|
||||
# Connect the signals to slots that will store the emitted values
|
||||
emitted_values_1D = []
|
||||
crosshair.coordinatesChanged1D.connect(emitted_values_1D.append)
|
||||
|
||||
# Simulate a mouse moved event at a specific position
|
||||
pos_in_view = QPointF(2, 5)
|
||||
pos_in_scene = plot_item.vb.mapViewToScene(pos_in_view)
|
||||
@@ -56,21 +52,17 @@ def test_mouse_moved_lines(plot_widget_with_crosshair):
|
||||
def test_mouse_moved_signals(plot_widget_with_crosshair):
|
||||
crosshair, plot_item = plot_widget_with_crosshair
|
||||
|
||||
# Create a slot that will store the emitted values as tuples
|
||||
emitted_values_1D = []
|
||||
|
||||
def slot(coordinates):
|
||||
emitted_values_1D.append(coordinates)
|
||||
|
||||
# Connect the signal to the custom slot
|
||||
crosshair.coordinatesChanged1D.connect(slot)
|
||||
|
||||
# Simulate a mouse moved event at a specific position
|
||||
pos_in_view = QPointF(2, 5)
|
||||
pos_in_scene = plot_item.vb.mapViewToScene(pos_in_view)
|
||||
event_mock = [pos_in_scene]
|
||||
|
||||
# Call the mouse_moved method
|
||||
crosshair.mouse_moved(event_mock)
|
||||
|
||||
# Assert the expected behavior
|
||||
@@ -83,8 +75,8 @@ def test_mouse_moved_signals_outside(plot_widget_with_crosshair):
|
||||
# Create a slot that will store the emitted values as tuples
|
||||
emitted_values_1D = []
|
||||
|
||||
def slot(x, y_values):
|
||||
emitted_values_1D.append((x, y_values))
|
||||
def slot(coordinates):
|
||||
emitted_values_1D.append(coordinates)
|
||||
|
||||
# Connect the signal to the custom slot
|
||||
crosshair.coordinatesChanged1D.connect(slot)
|
||||
@@ -104,40 +96,132 @@ def test_mouse_moved_signals_outside(plot_widget_with_crosshair):
|
||||
def test_mouse_moved_signals_2D(image_widget_with_crosshair):
|
||||
crosshair, plot_item = image_widget_with_crosshair
|
||||
|
||||
# Create a slot that will store the emitted values as tuples
|
||||
emitted_values_2D = []
|
||||
|
||||
def slot(coordinates):
|
||||
emitted_values_2D.append(coordinates)
|
||||
|
||||
# Connect the signal to the custom slot
|
||||
crosshair.coordinatesChanged2D.connect(slot)
|
||||
# Simulate a mouse moved event at a specific position
|
||||
|
||||
pos_in_view = QPointF(22.0, 55.0)
|
||||
pos_in_scene = plot_item.vb.mapViewToScene(pos_in_view)
|
||||
event_mock = [pos_in_scene]
|
||||
# Call the mouse_moved method
|
||||
|
||||
crosshair.mouse_moved(event_mock)
|
||||
# Assert the expected behavior
|
||||
|
||||
assert emitted_values_2D == [("test", 22.0, 55.0)]
|
||||
|
||||
|
||||
def test_mouse_moved_signals_2D_outside(image_widget_with_crosshair):
|
||||
crosshair, plot_item = image_widget_with_crosshair
|
||||
|
||||
# Create a slot that will store the emitted values as tuples
|
||||
emitted_values_2D = []
|
||||
|
||||
def slot(x, y):
|
||||
emitted_values_2D.append((x, y))
|
||||
def slot(coordinates):
|
||||
emitted_values_2D.append(coordinates)
|
||||
|
||||
# Connect the signal to the custom slot
|
||||
crosshair.coordinatesChanged2D.connect(slot)
|
||||
# Simulate a mouse moved event at a specific position
|
||||
|
||||
pos_in_view = QPointF(220.0, 555.0)
|
||||
pos_in_scene = plot_item.vb.mapViewToScene(pos_in_view)
|
||||
event_mock = [pos_in_scene]
|
||||
# Call the mouse_moved method
|
||||
|
||||
crosshair.mouse_moved(event_mock)
|
||||
# Assert the expected behavior
|
||||
|
||||
assert emitted_values_2D == []
|
||||
|
||||
|
||||
def test_marker_positions_after_mouse_move(plot_widget_with_crosshair):
|
||||
crosshair, plot_item = plot_widget_with_crosshair
|
||||
|
||||
pos_in_view = QPointF(2, 5)
|
||||
pos_in_scene = plot_item.vb.mapViewToScene(pos_in_view)
|
||||
event_mock = [pos_in_scene]
|
||||
|
||||
crosshair.mouse_moved(event_mock)
|
||||
|
||||
marker = crosshair.marker_moved_1d["Curve 1"]
|
||||
marker_x, marker_y = marker.getData()
|
||||
assert marker_x == [2]
|
||||
assert marker_y == [5]
|
||||
|
||||
|
||||
def test_scale_emitted_coordinates(plot_widget_with_crosshair):
|
||||
crosshair, _ = plot_widget_with_crosshair
|
||||
|
||||
x, y = crosshair.scale_emitted_coordinates(2, 5)
|
||||
assert x == 2
|
||||
assert y == 5
|
||||
|
||||
crosshair.is_log_x = True
|
||||
crosshair.is_log_y = True
|
||||
|
||||
x, y = crosshair.scale_emitted_coordinates(np.log10(2), np.log10(5))
|
||||
assert np.isclose(x, 2)
|
||||
assert np.isclose(y, 5)
|
||||
|
||||
|
||||
def test_crosshair_changed_signal(plot_widget_with_crosshair):
|
||||
crosshair, plot_item = plot_widget_with_crosshair
|
||||
|
||||
emitted_positions = []
|
||||
|
||||
def slot(position):
|
||||
emitted_positions.append(position)
|
||||
|
||||
crosshair.crosshairChanged.connect(slot)
|
||||
|
||||
pos_in_view = QPointF(2, 5)
|
||||
pos_in_scene = plot_item.vb.mapViewToScene(pos_in_view)
|
||||
event_mock = [pos_in_scene]
|
||||
|
||||
crosshair.mouse_moved(event_mock)
|
||||
|
||||
x, y = emitted_positions[0]
|
||||
|
||||
assert np.isclose(x, 2)
|
||||
assert np.isclose(y, 5)
|
||||
|
||||
|
||||
def test_marker_positions_after_mouse_move(plot_widget_with_crosshair):
|
||||
crosshair, plot_item = plot_widget_with_crosshair
|
||||
|
||||
pos_in_view = QPointF(2, 5)
|
||||
pos_in_scene = plot_item.vb.mapViewToScene(pos_in_view)
|
||||
event_mock = [pos_in_scene]
|
||||
|
||||
crosshair.mouse_moved(event_mock)
|
||||
|
||||
marker = crosshair.marker_moved_1d["Curve 1"]
|
||||
marker_x, marker_y = marker.getData()
|
||||
assert marker_x == [2]
|
||||
assert marker_y == [5]
|
||||
|
||||
|
||||
def test_crosshair_clicked_signal(qtbot, plot_widget_with_crosshair):
|
||||
crosshair, plot_item = plot_widget_with_crosshair
|
||||
|
||||
emitted_positions = []
|
||||
|
||||
def slot(position):
|
||||
emitted_positions.append(position)
|
||||
|
||||
crosshair.crosshairClicked.connect(slot)
|
||||
|
||||
x_data = 2
|
||||
y_data = 5
|
||||
|
||||
# Map data coordinates to scene coordinates
|
||||
pos_in_scene = plot_item.vb.mapViewToScene(QPointF(x_data, y_data))
|
||||
# Map scene coordinates to widget coordinates
|
||||
graphics_view = plot_item.vb.scene().views()[0]
|
||||
qtbot.waitExposed(graphics_view)
|
||||
pos_in_widget = graphics_view.mapFromScene(pos_in_scene)
|
||||
|
||||
# Simulate mouse click
|
||||
qtbot.mouseClick(graphics_view.viewport(), Qt.LeftButton, pos=pos_in_widget)
|
||||
|
||||
x, y = emitted_positions[0]
|
||||
|
||||
assert np.isclose(round(x, 1), 2)
|
||||
assert np.isclose(round(y, 1), 5)
|
||||
|
||||
Reference in New Issue
Block a user