bec-widgets 0.82.1__py3-none-any.whl → 0.83.0__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.
Files changed (44) hide show
  1. .gitlab-ci.yml +3 -0
  2. CHANGELOG.md +32 -34
  3. PKG-INFO +1 -1
  4. bec_widgets/cli/client_utils.py +5 -2
  5. bec_widgets/cli/server.py +24 -10
  6. bec_widgets/utils/bec_connector.py +2 -0
  7. bec_widgets/utils/bec_widget.py +6 -0
  8. bec_widgets/utils/generate_designer_plugin.py +6 -5
  9. bec_widgets/utils/reference_utils.py +92 -0
  10. bec_widgets/widgets/console/console.py +1 -1
  11. bec_widgets/widgets/device_box/__init__.py +0 -0
  12. bec_widgets/widgets/device_box/device_box.py +197 -0
  13. bec_widgets/widgets/device_box/device_box.pyproject +1 -0
  14. bec_widgets/widgets/device_box/device_box.ui +179 -0
  15. bec_widgets/widgets/device_box/device_box_plugin.py +54 -0
  16. bec_widgets/widgets/device_box/register_device_box.py +15 -0
  17. bec_widgets/widgets/figure/figure.py +3 -3
  18. bec_widgets/widgets/position_indicator/position_indicator.py +71 -0
  19. bec_widgets/widgets/position_indicator/position_indicator.pyproject +1 -0
  20. bec_widgets/widgets/position_indicator/position_indicator_plugin.py +54 -0
  21. bec_widgets/widgets/position_indicator/register_position_indicator.py +17 -0
  22. bec_widgets/widgets/spinner/__init__.py +0 -0
  23. bec_widgets/widgets/spinner/register_spinner_widget.py +15 -0
  24. bec_widgets/widgets/spinner/spinner.py +85 -0
  25. bec_widgets/widgets/spinner/spinner_widget.pyproject +1 -0
  26. bec_widgets/widgets/spinner/spinner_widget_plugin.py +54 -0
  27. bec_widgets/widgets/vscode/vscode.py +0 -14
  28. bec_widgets/widgets/website/website.py +1 -1
  29. {bec_widgets-0.82.1.dist-info → bec_widgets-0.83.0.dist-info}/METADATA +1 -1
  30. {bec_widgets-0.82.1.dist-info → bec_widgets-0.83.0.dist-info}/RECORD +44 -21
  31. pyproject.toml +1 -1
  32. tests/references/SpinnerWidget/SpinnerWidget_darwin.png +0 -0
  33. tests/references/SpinnerWidget/SpinnerWidget_linux.png +0 -0
  34. tests/references/SpinnerWidget/SpinnerWidget_started_darwin.png +0 -0
  35. tests/references/SpinnerWidget/SpinnerWidget_started_linux.png +0 -0
  36. tests/unit_tests/client_mocks.py +9 -1
  37. tests/unit_tests/test_client_utils.py +47 -0
  38. tests/unit_tests/test_device_box.py +98 -0
  39. tests/unit_tests/test_rpc_server.py +42 -0
  40. tests/unit_tests/test_spinner.py +30 -0
  41. tests/unit_tests/test_vscode_widget.py +27 -32
  42. {bec_widgets-0.82.1.dist-info → bec_widgets-0.83.0.dist-info}/WHEEL +0 -0
  43. {bec_widgets-0.82.1.dist-info → bec_widgets-0.83.0.dist-info}/entry_points.txt +0 -0
  44. {bec_widgets-0.82.1.dist-info → bec_widgets-0.83.0.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,179 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <ui version="4.0">
3
+ <class>Form</class>
4
+ <widget class="QWidget" name="Form">
5
+ <property name="geometry">
6
+ <rect>
7
+ <x>0</x>
8
+ <y>0</y>
9
+ <width>251</width>
10
+ <height>289</height>
11
+ </rect>
12
+ </property>
13
+ <property name="minimumSize">
14
+ <size>
15
+ <width>0</width>
16
+ <height>192</height>
17
+ </size>
18
+ </property>
19
+ <property name="maximumSize">
20
+ <size>
21
+ <width>16777215</width>
22
+ <height>16777215</height>
23
+ </size>
24
+ </property>
25
+ <property name="windowTitle">
26
+ <string>Form</string>
27
+ </property>
28
+ <layout class="QVBoxLayout" name="verticalLayout">
29
+ <item>
30
+ <widget class="QGroupBox" name="device_box">
31
+ <property name="title">
32
+ <string>Device Name</string>
33
+ </property>
34
+ <layout class="QGridLayout" name="gridLayout" rowstretch="0,0,0,0,0">
35
+ <property name="topMargin">
36
+ <number>0</number>
37
+ </property>
38
+ <item row="3" column="1">
39
+ <widget class="QDoubleSpinBox" name="step_size"/>
40
+ </item>
41
+ <item row="3" column="2">
42
+ <widget class="QToolButton" name="tweak_right">
43
+ <property name="minimumSize">
44
+ <size>
45
+ <width>50</width>
46
+ <height>50</height>
47
+ </size>
48
+ </property>
49
+ <property name="maximumSize">
50
+ <size>
51
+ <width>50</width>
52
+ <height>50</height>
53
+ </size>
54
+ </property>
55
+ <property name="text">
56
+ <string>...</string>
57
+ </property>
58
+ <property name="iconSize">
59
+ <size>
60
+ <width>30</width>
61
+ <height>30</height>
62
+ </size>
63
+ </property>
64
+ <property name="arrowType">
65
+ <enum>Qt::ArrowType::RightArrow</enum>
66
+ </property>
67
+ </widget>
68
+ </item>
69
+ <item row="2" column="0" colspan="3">
70
+ <widget class="QLineEdit" name="setpoint"/>
71
+ </item>
72
+ <item row="3" column="0">
73
+ <widget class="QToolButton" name="tweak_left">
74
+ <property name="minimumSize">
75
+ <size>
76
+ <width>50</width>
77
+ <height>50</height>
78
+ </size>
79
+ </property>
80
+ <property name="maximumSize">
81
+ <size>
82
+ <width>50</width>
83
+ <height>50</height>
84
+ </size>
85
+ </property>
86
+ <property name="text">
87
+ <string>...</string>
88
+ </property>
89
+ <property name="iconSize">
90
+ <size>
91
+ <width>30</width>
92
+ <height>30</height>
93
+ </size>
94
+ </property>
95
+ <property name="arrowType">
96
+ <enum>Qt::ArrowType::LeftArrow</enum>
97
+ </property>
98
+ </widget>
99
+ </item>
100
+ <item row="4" column="0" colspan="3">
101
+ <widget class="QPushButton" name="stop">
102
+ <property name="text">
103
+ <string>Stop</string>
104
+ </property>
105
+ </widget>
106
+ </item>
107
+ <item row="0" column="0" colspan="3">
108
+ <layout class="QVBoxLayout" name="verticalLayout_2">
109
+ <item>
110
+ <layout class="QHBoxLayout" name="horizontalLayout">
111
+ <item>
112
+ <spacer name="horizontalSpacer">
113
+ <property name="orientation">
114
+ <enum>Qt::Orientation::Horizontal</enum>
115
+ </property>
116
+ <property name="sizeType">
117
+ <enum>QSizePolicy::Policy::Expanding</enum>
118
+ </property>
119
+ <property name="sizeHint" stdset="0">
120
+ <size>
121
+ <width>40</width>
122
+ <height>20</height>
123
+ </size>
124
+ </property>
125
+ </spacer>
126
+ </item>
127
+ <item>
128
+ <widget class="SpinnerWidget" name="spinner_widget">
129
+ <property name="minimumSize">
130
+ <size>
131
+ <width>25</width>
132
+ <height>25</height>
133
+ </size>
134
+ </property>
135
+ <property name="maximumSize">
136
+ <size>
137
+ <width>25</width>
138
+ <height>25</height>
139
+ </size>
140
+ </property>
141
+ </widget>
142
+ </item>
143
+ </layout>
144
+ </item>
145
+ <item>
146
+ <widget class="PositionIndicator" name="position_indicator"/>
147
+ </item>
148
+ <item>
149
+ <widget class="QLabel" name="readback">
150
+ <property name="text">
151
+ <string>Position</string>
152
+ </property>
153
+ <property name="alignment">
154
+ <set>Qt::AlignmentFlag::AlignCenter</set>
155
+ </property>
156
+ </widget>
157
+ </item>
158
+ </layout>
159
+ </item>
160
+ </layout>
161
+ </widget>
162
+ </item>
163
+ </layout>
164
+ </widget>
165
+ <customwidgets>
166
+ <customwidget>
167
+ <class>SpinnerWidget</class>
168
+ <extends>QWidget</extends>
169
+ <header>spinner_widget</header>
170
+ </customwidget>
171
+ <customwidget>
172
+ <class>PositionIndicator</class>
173
+ <extends>QWidget</extends>
174
+ <header>position_indicator</header>
175
+ </customwidget>
176
+ </customwidgets>
177
+ <resources/>
178
+ <connections/>
179
+ </ui>
@@ -0,0 +1,54 @@
1
+ # Copyright (C) 2022 The Qt Company Ltd.
2
+ # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
+
4
+ from qtpy.QtDesigner import QDesignerCustomWidgetInterface
5
+ from qtpy.QtGui import QIcon
6
+
7
+ from bec_widgets.widgets.device_box.device_box import DeviceBox
8
+
9
+ DOM_XML = """
10
+ <ui language='c++'>
11
+ <widget class='DeviceBox' name='device_box'>
12
+ </widget>
13
+ </ui>
14
+ """
15
+
16
+
17
+ class DeviceBoxPlugin(QDesignerCustomWidgetInterface): # pragma: no cover
18
+ def __init__(self):
19
+ super().__init__()
20
+ self._form_editor = None
21
+
22
+ def createWidget(self, parent):
23
+ t = DeviceBox(parent)
24
+ return t
25
+
26
+ def domXml(self):
27
+ return DOM_XML
28
+
29
+ def group(self):
30
+ return "Device Control"
31
+
32
+ def icon(self):
33
+ return QIcon()
34
+
35
+ def includeFile(self):
36
+ return "device_box"
37
+
38
+ def initialize(self, form_editor):
39
+ self._form_editor = form_editor
40
+
41
+ def isContainer(self):
42
+ return False
43
+
44
+ def isInitialized(self):
45
+ return self._form_editor is not None
46
+
47
+ def name(self):
48
+ return "DeviceBox"
49
+
50
+ def toolTip(self):
51
+ return "A widget for controlling a single positioner. "
52
+
53
+ def whatsThis(self):
54
+ return self.toolTip()
@@ -0,0 +1,15 @@
1
+ def main(): # pragma: no cover
2
+ from qtpy import PYSIDE6
3
+
4
+ if not PYSIDE6:
5
+ print("PYSIDE6 is not available in the environment. Cannot patch designer.")
6
+ return
7
+ from PySide6.QtDesigner import QPyDesignerCustomWidgetCollection
8
+
9
+ from bec_widgets.widgets.device_box.device_box_plugin import DeviceBoxPlugin
10
+
11
+ QPyDesignerCustomWidgetCollection.addCustomWidget(DeviceBoxPlugin())
12
+
13
+
14
+ if __name__ == "__main__": # pragma: no cover
15
+ main()
@@ -830,6 +830,6 @@ class BECFigure(BECConnector, pg.GraphicsLayoutWidget):
830
830
  widget_class=self.__class__.__name__, gui_id=self.gui_id, theme=theme
831
831
  )
832
832
 
833
- def cleanup(self):
834
- self.clear_all()
835
- super().cleanup()
833
+ # def cleanup(self):
834
+ # self.clear_all()
835
+ # super().cleanup()
@@ -0,0 +1,71 @@
1
+ from qtpy.QtCore import Qt, Slot
2
+ from qtpy.QtGui import QPainter, QPen
3
+ from qtpy.QtWidgets import QWidget
4
+
5
+
6
+ class PositionIndicator(QWidget):
7
+
8
+ def __init__(self, parent=None):
9
+ super().__init__(parent)
10
+ self.position = 0.5
11
+ self.min_value = 0
12
+ self.max_value = 100
13
+ self.scaling_factor = 0.5
14
+ self.setMinimumHeight(10)
15
+
16
+ def set_range(self, min_value, max_value):
17
+ self.min_value = min_value
18
+ self.max_value = max_value
19
+
20
+ @Slot(float)
21
+ def on_position_update(self, position: float):
22
+ self.position = position
23
+ self.update()
24
+
25
+ def paintEvent(self, event):
26
+ painter = QPainter(self)
27
+ painter.setRenderHint(QPainter.Antialiasing)
28
+
29
+ width = self.width()
30
+ height = self.height()
31
+
32
+ # Draw horizontal line
33
+ painter.setPen(Qt.black)
34
+ painter.drawLine(0, height // 2, width, height // 2)
35
+
36
+ # Draw shorter vertical line at the current position
37
+ x_pos = int(self.position * width)
38
+ painter.setPen(QPen(Qt.red, 2))
39
+ short_line_height = int(height * self.scaling_factor)
40
+ painter.drawLine(
41
+ x_pos,
42
+ (height // 2) - (short_line_height // 2),
43
+ x_pos,
44
+ (height // 2) + (short_line_height // 2),
45
+ )
46
+
47
+ # Draw thicker vertical lines at the ends
48
+ end_line_pen = QPen(Qt.blue, 5)
49
+ painter.setPen(end_line_pen)
50
+ painter.drawLine(0, 0, 0, height)
51
+ painter.drawLine(width - 1, 0, width - 1, height)
52
+
53
+
54
+ if __name__ == "__main__":
55
+ from qtpy.QtWidgets import QApplication, QSlider, QVBoxLayout
56
+
57
+ app = QApplication([])
58
+
59
+ position_indicator = PositionIndicator()
60
+ slider = QSlider(Qt.Horizontal)
61
+ slider.valueChanged.connect(lambda value: position_indicator.on_position_update(value / 100))
62
+
63
+ layout = QVBoxLayout()
64
+ layout.addWidget(position_indicator)
65
+ layout.addWidget(slider)
66
+
67
+ widget = QWidget()
68
+ widget.setLayout(layout)
69
+ widget.show()
70
+
71
+ app.exec_()
@@ -0,0 +1 @@
1
+ {'files': ['position_indicator.py']}
@@ -0,0 +1,54 @@
1
+ # Copyright (C) 2022 The Qt Company Ltd.
2
+ # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
+
4
+ from qtpy.QtDesigner import QDesignerCustomWidgetInterface
5
+ from qtpy.QtGui import QIcon
6
+
7
+ from bec_widgets.widgets.position_indicator.position_indicator import PositionIndicator
8
+
9
+ DOM_XML = """
10
+ <ui language='c++'>
11
+ <widget class='PositionIndicator' name='position_indicator'>
12
+ </widget>
13
+ </ui>
14
+ """
15
+
16
+
17
+ class PositionIndicatorPlugin(QDesignerCustomWidgetInterface): # pragma: no cover
18
+ def __init__(self):
19
+ super().__init__()
20
+ self._form_editor = None
21
+
22
+ def createWidget(self, parent):
23
+ t = PositionIndicator(parent)
24
+ return t
25
+
26
+ def domXml(self):
27
+ return DOM_XML
28
+
29
+ def group(self):
30
+ return ""
31
+
32
+ def icon(self):
33
+ return QIcon()
34
+
35
+ def includeFile(self):
36
+ return "position_indicator"
37
+
38
+ def initialize(self, form_editor):
39
+ self._form_editor = form_editor
40
+
41
+ def isContainer(self):
42
+ return False
43
+
44
+ def isInitialized(self):
45
+ return self._form_editor is not None
46
+
47
+ def name(self):
48
+ return "PositionIndicator"
49
+
50
+ def toolTip(self):
51
+ return "PositionIndicator"
52
+
53
+ def whatsThis(self):
54
+ return self.toolTip()
@@ -0,0 +1,17 @@
1
+ def main(): # pragma: no cover
2
+ from qtpy import PYSIDE6
3
+
4
+ if not PYSIDE6:
5
+ print("PYSIDE6 is not available in the environment. Cannot patch designer.")
6
+ return
7
+ from PySide6.QtDesigner import QPyDesignerCustomWidgetCollection
8
+
9
+ from bec_widgets.widgets.position_indicator.position_indicator_plugin import (
10
+ PositionIndicatorPlugin,
11
+ )
12
+
13
+ QPyDesignerCustomWidgetCollection.addCustomWidget(PositionIndicatorPlugin())
14
+
15
+
16
+ if __name__ == "__main__": # pragma: no cover
17
+ main()
File without changes
@@ -0,0 +1,15 @@
1
+ def main(): # pragma: no cover
2
+ from qtpy import PYSIDE6
3
+
4
+ if not PYSIDE6:
5
+ print("PYSIDE6 is not available in the environment. Cannot patch designer.")
6
+ return
7
+ from PySide6.QtDesigner import QPyDesignerCustomWidgetCollection
8
+
9
+ from bec_widgets.widgets.spinner.spinner_widget_plugin import SpinnerWidgetPlugin
10
+
11
+ QPyDesignerCustomWidgetCollection.addCustomWidget(SpinnerWidgetPlugin())
12
+
13
+
14
+ if __name__ == "__main__": # pragma: no cover
15
+ main()
@@ -0,0 +1,85 @@
1
+ import sys
2
+
3
+ import numpy as np
4
+ import qdarktheme
5
+ from qtpy.QtCore import QRect, Qt, QTimer
6
+ from qtpy.QtGui import QColor, QPainter, QPen
7
+ from qtpy.QtWidgets import QApplication, QMainWindow, QWidget
8
+
9
+
10
+ def ease_in_out_sine(t):
11
+ return 1 - np.sin(np.pi * t)
12
+
13
+
14
+ class SpinnerWidget(QWidget):
15
+ def __init__(self, parent=None):
16
+ super().__init__(parent)
17
+
18
+ self.angle = 0
19
+ self.timer = QTimer(self)
20
+ self.timer.timeout.connect(self.rotate)
21
+ self.time = 0
22
+ self.duration = 50
23
+ self.speed = 50
24
+ self._started = False
25
+
26
+ def start(self):
27
+ if self._started:
28
+ return
29
+ self.timer.start(self.speed)
30
+ self._started = True
31
+
32
+ def stop(self):
33
+ if not self._started:
34
+ return
35
+ self.timer.stop()
36
+ self._started = False
37
+ self.update()
38
+
39
+ def rotate(self):
40
+ self.time = (self.time + 1) % self.duration
41
+ t = self.time / self.duration
42
+ easing_value = ease_in_out_sine(t)
43
+ self.angle -= (20 * easing_value) % 360 + 10
44
+ self.update()
45
+
46
+ def paintEvent(self, event):
47
+ painter = QPainter(self)
48
+ painter.setRenderHint(QPainter.Antialiasing)
49
+ size = min(self.width(), self.height())
50
+ rect = QRect(0, 0, size, size)
51
+
52
+ background_color = QColor(200, 200, 200, 50)
53
+ line_width = 5
54
+
55
+ color_palette = qdarktheme.load_palette()
56
+
57
+ color = QColor(color_palette.accent().color())
58
+
59
+ rect.adjust(line_width, line_width, -line_width, -line_width)
60
+
61
+ # Background arc
62
+ painter.setPen(QPen(background_color, line_width, Qt.SolidLine))
63
+ adjusted_rect = QRect(rect.left(), rect.top(), rect.width(), rect.height())
64
+ painter.drawArc(adjusted_rect, 0, 360 * 16)
65
+
66
+ if self._started:
67
+ # Foreground arc
68
+ pen = QPen(color, line_width, Qt.SolidLine)
69
+ pen.setCapStyle(Qt.RoundCap)
70
+ painter.setPen(pen)
71
+ proportion = 1 / 4
72
+ angle_span = int(proportion * 360 * 16)
73
+ angle_span += angle_span * ease_in_out_sine(self.time / self.duration)
74
+ painter.drawArc(adjusted_rect, self.angle * 16, int(angle_span))
75
+ painter.end()
76
+
77
+
78
+ if __name__ == "__main__": # pragma: no cover
79
+ app = QApplication(sys.argv)
80
+ window = QMainWindow()
81
+ widget = SpinnerWidget()
82
+ widget.start()
83
+ window.setCentralWidget(widget)
84
+ window.show()
85
+ sys.exit(app.exec())
@@ -0,0 +1 @@
1
+ {'files': ['spinner.py']}
@@ -0,0 +1,54 @@
1
+ # Copyright (C) 2022 The Qt Company Ltd.
2
+ # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
+
4
+ from qtpy.QtDesigner import QDesignerCustomWidgetInterface
5
+ from qtpy.QtGui import QIcon
6
+
7
+ from bec_widgets.widgets.spinner.spinner import SpinnerWidget
8
+
9
+ DOM_XML = """
10
+ <ui language='c++'>
11
+ <widget class='SpinnerWidget' name='spinner_widget'>
12
+ </widget>
13
+ </ui>
14
+ """
15
+
16
+
17
+ class SpinnerWidgetPlugin(QDesignerCustomWidgetInterface): # pragma: no cover
18
+ def __init__(self):
19
+ super().__init__()
20
+ self._form_editor = None
21
+
22
+ def createWidget(self, parent):
23
+ t = SpinnerWidget(parent)
24
+ return t
25
+
26
+ def domXml(self):
27
+ return DOM_XML
28
+
29
+ def group(self):
30
+ return ""
31
+
32
+ def icon(self):
33
+ return QIcon()
34
+
35
+ def includeFile(self):
36
+ return "spinner_widget"
37
+
38
+ def initialize(self, form_editor):
39
+ self._form_editor = form_editor
40
+
41
+ def isContainer(self):
42
+ return False
43
+
44
+ def isInitialized(self):
45
+ return self._form_editor is not None
46
+
47
+ def name(self):
48
+ return "SpinnerWidget"
49
+
50
+ def toolTip(self):
51
+ return "SpinnerWidget"
52
+
53
+ def whatsThis(self):
54
+ return self.toolTip()
@@ -49,13 +49,6 @@ class VSCodeEditor(WebsiteWidget):
49
49
  break
50
50
  self.set_url(self._url)
51
51
 
52
- def closeEvent(self, event):
53
- """
54
- Hook for the close event to terminate the server.
55
- """
56
- self.cleanup_vscode()
57
- super().closeEvent(event)
58
-
59
52
  def cleanup_vscode(self):
60
53
  """
61
54
  Cleanup the VSCode editor.
@@ -72,13 +65,6 @@ class VSCodeEditor(WebsiteWidget):
72
65
  self.cleanup_vscode()
73
66
  return super().cleanup()
74
67
 
75
- def close(self):
76
- """
77
- Close the widget.
78
- """
79
- self.cleanup_vscode()
80
- return super().close()
81
-
82
68
 
83
69
  if __name__ == "__main__": # pragma: no cover
84
70
  import sys
@@ -69,6 +69,6 @@ if __name__ == "__main__":
69
69
  import sys
70
70
 
71
71
  app = QApplication(sys.argv)
72
- mainWin = WebsiteWidget("https://scilog.psi.ch")
72
+ mainWin = WebsiteWidget(url="https://scilog.psi.ch")
73
73
  mainWin.show()
74
74
  sys.exit(app.exec())
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: bec_widgets
3
- Version: 0.82.1
3
+ Version: 0.83.0
4
4
  Summary: BEC Widgets
5
5
  Project-URL: Bug Tracker, https://gitlab.psi.ch/bec/bec_widgets/issues
6
6
  Project-URL: Homepage, https://gitlab.psi.ch/bec/bec_widgets