microeye 2.3.2__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.
- microEye/__init__.py +47 -0
- microEye/_version.py +2 -0
- microEye/analysis/__init__.py +1 -0
- microEye/analysis/checklist_dialog.py +143 -0
- microEye/analysis/cmosMaps.py +228 -0
- microEye/analysis/filters/__init__.py +9 -0
- microEye/analysis/filters/base.py +21 -0
- microEye/analysis/filters/spatial.py +338 -0
- microEye/analysis/filters/temporal.py +76 -0
- microEye/analysis/fitting/__init__.py +0 -0
- microEye/analysis/fitting/fit.py +680 -0
- microEye/analysis/fitting/nena.py +375 -0
- microEye/analysis/fitting/phasor_fit.py +90 -0
- microEye/analysis/fitting/processing.py +317 -0
- microEye/analysis/fitting/psf/__init__.py +6 -0
- microEye/analysis/fitting/psf/extract.py +1129 -0
- microEye/analysis/fitting/psf/rubost_mean.py +150 -0
- microEye/analysis/fitting/psf/spline.py +167 -0
- microEye/analysis/fitting/psf/stats/__init__.py +12 -0
- microEye/analysis/fitting/psf/stats/core.py +295 -0
- microEye/analysis/fitting/psf/stats/curve_fit.py +708 -0
- microEye/analysis/fitting/psf/stats/io.py +104 -0
- microEye/analysis/fitting/psf/stats/slope_fit.py +171 -0
- microEye/analysis/fitting/psf/temp.py +147 -0
- microEye/analysis/fitting/psf/test.py +47 -0
- microEye/analysis/fitting/pyfit3Dcspline/CPU/CPUfunctions.py +657 -0
- microEye/analysis/fitting/pyfit3Dcspline/CPU/CPUmleFit_LM.py +1336 -0
- microEye/analysis/fitting/pyfit3Dcspline/CPU/CPUsplineLib.py +270 -0
- microEye/analysis/fitting/pyfit3Dcspline/CPU/__init__.py +1 -0
- microEye/analysis/fitting/pyfit3Dcspline/GPU/GPUfunctions.py +609 -0
- microEye/analysis/fitting/pyfit3Dcspline/GPU/GPUmleFit_LM_EMCCD.py +1396 -0
- microEye/analysis/fitting/pyfit3Dcspline/GPU/GPUmleFit_LM_sCMOS.py +1426 -0
- microEye/analysis/fitting/pyfit3Dcspline/GPU/GPUsplineLib.py +231 -0
- microEye/analysis/fitting/pyfit3Dcspline/GPU/__init__.py +2 -0
- microEye/analysis/fitting/pyfit3Dcspline/__init__.py +10 -0
- microEye/analysis/fitting/pyfit3Dcspline/constants.py +27 -0
- microEye/analysis/fitting/pyfit3Dcspline/mainfunctions.py +903 -0
- microEye/analysis/fitting/results.py +917 -0
- microEye/analysis/fitting/results_stats.py +251 -0
- microEye/analysis/fitting/tardis.py +209 -0
- microEye/analysis/multi_viewer.py +568 -0
- microEye/analysis/processing/__init__.py +1 -0
- microEye/analysis/processing/frc.py +120 -0
- microEye/analysis/rendering/__init__.py +3 -0
- microEye/analysis/rendering/base.py +452 -0
- microEye/analysis/rendering/cloud.py +215 -0
- microEye/analysis/rendering/core.py +47 -0
- microEye/analysis/rendering/volumetric.py +198 -0
- microEye/analysis/tools/__init__.py +0 -0
- microEye/analysis/tools/kymograms.py +1079 -0
- microEye/analysis/tools/roi_selectors.py +556 -0
- microEye/analysis/utils/__init__.py +3 -0
- microEye/analysis/utils/coordinates.py +18 -0
- microEye/analysis/utils/images.py +68 -0
- microEye/analysis/utils/windows.py +19 -0
- microEye/analysis/viewer/__init__.py +3 -0
- microEye/analysis/viewer/image_options_widget.py +615 -0
- microEye/analysis/viewer/images.py +1225 -0
- microEye/analysis/viewer/layers_widget.py +415 -0
- microEye/analysis/viewer/localizations.py +1304 -0
- microEye/analysis/viewer/psf.py +1003 -0
- microEye/analysis/viewer/volume.py +456 -0
- microEye/hardware/__init__.py +3 -0
- microEye/hardware/cams/__init__.py +29 -0
- microEye/hardware/cams/camera_calibration.py +99 -0
- microEye/hardware/cams/camera_list.py +528 -0
- microEye/hardware/cams/camera_options.py +694 -0
- microEye/hardware/cams/camera_panel.py +941 -0
- microEye/hardware/cams/dummy/__init__.py +1 -0
- microEye/hardware/cams/dummy/dummy_panel.py +759 -0
- microEye/hardware/cams/jobs.py +497 -0
- microEye/hardware/cams/line_profiler.py +99 -0
- microEye/hardware/cams/linescan/IR_Cam.py +474 -0
- microEye/hardware/cams/linescan/__init__.py +1 -0
- microEye/hardware/cams/micam.py +524 -0
- microEye/hardware/cams/pco/__init__.py +58 -0
- microEye/hardware/cams/pco/enums.py +382 -0
- microEye/hardware/cams/pco/pco_cam.py +761 -0
- microEye/hardware/cams/pco/pco_panel.py +477 -0
- microEye/hardware/cams/shortcuts.py +312 -0
- microEye/hardware/cams/thorlabs/__init__.py +1 -0
- microEye/hardware/cams/thorlabs/thorlabs.py +1508 -0
- microEye/hardware/cams/thorlabs/thorlabs_panel.py +850 -0
- microEye/hardware/cams/ueye/__init__.py +1 -0
- microEye/hardware/cams/ueye/ueye_camera.py +1023 -0
- microEye/hardware/cams/ueye/ueye_panel.py +861 -0
- microEye/hardware/cams/vimba/__init__.py +1 -0
- microEye/hardware/cams/vimba/vimba_cam.py +1000 -0
- microEye/hardware/cams/vimba/vimba_panel.py +813 -0
- microEye/hardware/device.py +60 -0
- microEye/hardware/lasers/__init__.py +13 -0
- microEye/hardware/lasers/io_matchbox.py +791 -0
- microEye/hardware/lasers/io_params.py +85 -0
- microEye/hardware/lasers/io_single_laser.py +742 -0
- microEye/hardware/lasers/laser_relay.py +594 -0
- microEye/hardware/mieye/__init__.py +1 -0
- microEye/hardware/mieye/acquisition_manager.py +467 -0
- microEye/hardware/mieye/devices_manager.py +533 -0
- microEye/hardware/mieye/miEye.py +659 -0
- microEye/hardware/misc/__init__.py +0 -0
- microEye/hardware/misc/acquisition_view.py +71 -0
- microEye/hardware/misc/reglo.py +761 -0
- microEye/hardware/misc/temp.py +188 -0
- microEye/hardware/port_config.py +59 -0
- microEye/hardware/protocols/__init__.py +2 -0
- microEye/hardware/protocols/actions.py +402 -0
- microEye/hardware/protocols/actions_items.py +703 -0
- microEye/hardware/protocols/designer.py +244 -0
- microEye/hardware/protocols/scene_manager.py +191 -0
- microEye/hardware/protocols/serialization.py +97 -0
- microEye/hardware/pycromanager/__init__.py +16 -0
- microEye/hardware/pycromanager/core.py +1433 -0
- microEye/hardware/pycromanager/devices.py +461 -0
- microEye/hardware/pycromanager/enums.py +107 -0
- microEye/hardware/pycromanager/headless.py +153 -0
- microEye/hardware/pycromanager/utils.py +34 -0
- microEye/hardware/pycromanager/widgets/__init__.py +5 -0
- microEye/hardware/pycromanager/widgets/bridges.py +407 -0
- microEye/hardware/pycromanager/widgets/headless_manager.py +258 -0
- microEye/hardware/pycromanager/widgets/headless_options.py +224 -0
- microEye/hardware/pycromanager/widgets/pycro_panel.py +455 -0
- microEye/hardware/stages/__init__.py +18 -0
- microEye/hardware/stages/elliptec/__init__.py +5 -0
- microEye/hardware/stages/elliptec/baseDevice.py +314 -0
- microEye/hardware/stages/elliptec/device.py +384 -0
- microEye/hardware/stages/elliptec/deviceID.py +212 -0
- microEye/hardware/stages/elliptec/devicePort.py +379 -0
- microEye/hardware/stages/elliptec/deviceStatus.py +65 -0
- microEye/hardware/stages/elliptec/devicesView.py +706 -0
- microEye/hardware/stages/elliptec/ellDevices.py +134 -0
- microEye/hardware/stages/elliptec/messageUpdater.py +34 -0
- microEye/hardware/stages/elliptec/motorInfo.py +153 -0
- microEye/hardware/stages/elliptec/stage.py +62 -0
- microEye/hardware/stages/elliptec/test.py +139 -0
- microEye/hardware/stages/kinesis/__init__.py +1 -0
- microEye/hardware/stages/kinesis/kdc101/__init__.py +1 -0
- microEye/hardware/stages/kinesis/kdc101/enums.py +1002 -0
- microEye/hardware/stages/kinesis/kdc101/factory.py +171 -0
- microEye/hardware/stages/kinesis/kdc101/kdc101.py +718 -0
- microEye/hardware/stages/kinesis/kinesis.py +776 -0
- microEye/hardware/stages/piezo_concept.py +607 -0
- microEye/hardware/stages/stabilizer.py +785 -0
- microEye/hardware/stages/stage.py +89 -0
- microEye/hardware/widgets/__init__.py +10 -0
- microEye/hardware/widgets/controller.py +246 -0
- microEye/hardware/widgets/devices.py +133 -0
- microEye/hardware/widgets/focusWidget.py +264 -0
- microEye/hardware/widgets/qlist_slider.py +113 -0
- microEye/hardware/widgets/scan_acquisition.py +424 -0
- microEye/icons/1024.png +0 -0
- microEye/icons/128.png +0 -0
- microEye/icons/16.png +0 -0
- microEye/icons/24.png +0 -0
- microEye/icons/256.png +0 -0
- microEye/icons/32.png +0 -0
- microEye/icons/48.png +0 -0
- microEye/icons/512.png +0 -0
- microEye/icons/64.png +0 -0
- microEye/icons/__init__.py +0 -0
- microEye/icons/close.svg +88 -0
- microEye/icons/mieye.png +0 -0
- microEye/icons/min.svg +83 -0
- microEye/icons/viewer.png +0 -0
- microEye/launcher.py +42 -0
- microEye/qt.py +181 -0
- microEye/utils/__init__.py +2 -0
- microEye/utils/enum_encoder.py +10 -0
- microEye/utils/expandable_groupbox.py +93 -0
- microEye/utils/gui_helper.py +457 -0
- microEye/utils/hid/__init__.py +8 -0
- microEye/utils/hid/controller.py +153 -0
- microEye/utils/hid/device.py +63 -0
- microEye/utils/hid/enums.py +140 -0
- microEye/utils/hid/utils.py +58 -0
- microEye/utils/labelled_slider.py +134 -0
- microEye/utils/metadata.py +599 -0
- microEye/utils/metadata_tree.py +718 -0
- microEye/utils/micro_launcher.py +245 -0
- microEye/utils/parameter_tree.py +325 -0
- microEye/utils/pyscripting.py +444 -0
- microEye/utils/retry_exec.py +35 -0
- microEye/utils/start_gui.py +112 -0
- microEye/utils/thread_worker.py +115 -0
- microEye/utils/uImage.py +1512 -0
- microeye-2.3.2.dist-info/METADATA +401 -0
- microeye-2.3.2.dist-info/RECORD +190 -0
- microeye-2.3.2.dist-info/WHEEL +5 -0
- microeye-2.3.2.dist-info/entry_points.txt +2 -0
- microeye-2.3.2.dist-info/licenses/LICENSE +674 -0
- microeye-2.3.2.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,594 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import sys
|
|
3
|
+
from enum import Enum
|
|
4
|
+
from typing import Optional
|
|
5
|
+
|
|
6
|
+
from pyqtgraph.parametertree import Parameter
|
|
7
|
+
|
|
8
|
+
from microEye.qt import QtCore, QtSerialPort, QtWidgets, Signal
|
|
9
|
+
from microEye.utils import StartGUI, Tree
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class LaserRelay:
|
|
13
|
+
def __init__(self) -> None:
|
|
14
|
+
"""
|
|
15
|
+
Initialize a new LaserRelay instance.
|
|
16
|
+
|
|
17
|
+
Sets up the serial port with a baud rate of 115200 and a port of 'COM6'.
|
|
18
|
+
Also initializes the last sent configuration, the current laser relay state,
|
|
19
|
+
and the ALEX flag.
|
|
20
|
+
"""
|
|
21
|
+
self.__port = QtSerialPort.QSerialPort()
|
|
22
|
+
self.__port.setBaudRate(115200)
|
|
23
|
+
self.__port.setPortName('COM6')
|
|
24
|
+
|
|
25
|
+
self.__last = ''
|
|
26
|
+
self.laserRelay_curr = ''
|
|
27
|
+
self.__alex = False
|
|
28
|
+
|
|
29
|
+
@property
|
|
30
|
+
def lastCommand(self):
|
|
31
|
+
return self.__last
|
|
32
|
+
|
|
33
|
+
def isOpen(self) -> bool:
|
|
34
|
+
'''
|
|
35
|
+
Check if the serial port is open.
|
|
36
|
+
|
|
37
|
+
Returns
|
|
38
|
+
-------
|
|
39
|
+
bool
|
|
40
|
+
True if the serial port is open, False otherwise.
|
|
41
|
+
'''
|
|
42
|
+
return self.__port.isOpen()
|
|
43
|
+
|
|
44
|
+
def isALEX(self) -> bool:
|
|
45
|
+
'''
|
|
46
|
+
Check if the ALEX flag is set.
|
|
47
|
+
|
|
48
|
+
Returns
|
|
49
|
+
-------
|
|
50
|
+
bool
|
|
51
|
+
True if the ALEX flag is set, False otherwise.
|
|
52
|
+
'''
|
|
53
|
+
return self.__alex
|
|
54
|
+
|
|
55
|
+
def setALEX(self, value: bool):
|
|
56
|
+
'''
|
|
57
|
+
Set the ALEX flag.
|
|
58
|
+
|
|
59
|
+
Parameters
|
|
60
|
+
----------
|
|
61
|
+
value : bool
|
|
62
|
+
The new value for the ALEX flag.
|
|
63
|
+
|
|
64
|
+
Raises
|
|
65
|
+
------
|
|
66
|
+
TypeError
|
|
67
|
+
If the value is not a boolean.
|
|
68
|
+
'''
|
|
69
|
+
if not isinstance(value, bool):
|
|
70
|
+
raise TypeError('ALEX value should be boolean.')
|
|
71
|
+
|
|
72
|
+
self.__alex = value
|
|
73
|
+
|
|
74
|
+
def open(self):
|
|
75
|
+
'''
|
|
76
|
+
Open the serial port.
|
|
77
|
+
|
|
78
|
+
If the serial port is not already open,
|
|
79
|
+
this method will open it in read-write mode.
|
|
80
|
+
'''
|
|
81
|
+
if not self.isOpen():
|
|
82
|
+
self.__port.open(QtCore.QIODevice.OpenModeFlag.ReadWrite)
|
|
83
|
+
|
|
84
|
+
def close(self):
|
|
85
|
+
'''
|
|
86
|
+
Close the serial port.
|
|
87
|
+
|
|
88
|
+
If the serial port is already open, this method will close it.
|
|
89
|
+
'''
|
|
90
|
+
if self.isOpen():
|
|
91
|
+
self.__port.close()
|
|
92
|
+
|
|
93
|
+
def portName(self):
|
|
94
|
+
'''
|
|
95
|
+
Get the name of the serial port.
|
|
96
|
+
|
|
97
|
+
Returns
|
|
98
|
+
-------
|
|
99
|
+
str
|
|
100
|
+
The name of the serial port.
|
|
101
|
+
'''
|
|
102
|
+
return self.__port.portName()
|
|
103
|
+
|
|
104
|
+
def baudRate(self):
|
|
105
|
+
'''
|
|
106
|
+
Get the baud rate of the serial port.
|
|
107
|
+
|
|
108
|
+
Returns
|
|
109
|
+
-------
|
|
110
|
+
int
|
|
111
|
+
The baud rate of the serial port.
|
|
112
|
+
'''
|
|
113
|
+
return self.__port.baudRate()
|
|
114
|
+
|
|
115
|
+
def setBaudRate(self, value: int):
|
|
116
|
+
'''
|
|
117
|
+
Set the baud rate of the serial port.
|
|
118
|
+
|
|
119
|
+
Parameters
|
|
120
|
+
----------
|
|
121
|
+
value : int
|
|
122
|
+
The new baud rate for the serial port.
|
|
123
|
+
|
|
124
|
+
Raises
|
|
125
|
+
------
|
|
126
|
+
ValueError
|
|
127
|
+
If the value is not a valid baud rate.
|
|
128
|
+
'''
|
|
129
|
+
if not self.isOpen():
|
|
130
|
+
self.__port.setBaudRate(value)
|
|
131
|
+
|
|
132
|
+
def setPortName(self, value: str):
|
|
133
|
+
'''
|
|
134
|
+
Set the port of the serial port.
|
|
135
|
+
|
|
136
|
+
Parameters
|
|
137
|
+
----------
|
|
138
|
+
value : str
|
|
139
|
+
The new port for the serial port.
|
|
140
|
+
|
|
141
|
+
Raises
|
|
142
|
+
------
|
|
143
|
+
ValueError
|
|
144
|
+
If the value is not a valid port.
|
|
145
|
+
'''
|
|
146
|
+
if not self.isOpen():
|
|
147
|
+
self.__port.setPortName(value)
|
|
148
|
+
|
|
149
|
+
def sendConfig(self, config: str = None):
|
|
150
|
+
'''
|
|
151
|
+
Send the RelayBox configuration command.
|
|
152
|
+
|
|
153
|
+
Parameters
|
|
154
|
+
----------
|
|
155
|
+
config : str, optional
|
|
156
|
+
The configuration to send. If None, the current configuration will be sent.
|
|
157
|
+
|
|
158
|
+
Raises
|
|
159
|
+
------
|
|
160
|
+
Exception
|
|
161
|
+
If there is an error sending the configuration.
|
|
162
|
+
'''
|
|
163
|
+
try:
|
|
164
|
+
if not self.isOpen():
|
|
165
|
+
raise ConnectionError('Device is not open.')
|
|
166
|
+
|
|
167
|
+
if config is None:
|
|
168
|
+
config = ('ALEXON' if self.isALEX() else 'ALEXOFF') + '\r'
|
|
169
|
+
|
|
170
|
+
self.__port.write(config.encode('utf-8'))
|
|
171
|
+
self.__last = config
|
|
172
|
+
print(str(self.__port.readAll(), encoding='utf-8'))
|
|
173
|
+
except Exception as e:
|
|
174
|
+
print('Failed Laser Relay Send Config: ' + str(e))
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
class RelayParams(Enum):
|
|
178
|
+
'''
|
|
179
|
+
Enum class defining Laser Relay parameters.
|
|
180
|
+
'''
|
|
181
|
+
|
|
182
|
+
MODEL = 'Model'
|
|
183
|
+
ALEX = 'ALEX'
|
|
184
|
+
SEND_COMMAND = 'Send Command'
|
|
185
|
+
|
|
186
|
+
SERIAL_PORT = 'Serial Port'
|
|
187
|
+
PORT = 'Serial Port.Port'
|
|
188
|
+
BAUDRATE = 'Serial Port.Baudrate'
|
|
189
|
+
SET_PORT = 'Serial Port.Set Config'
|
|
190
|
+
OPEN = 'Serial Port.Connect'
|
|
191
|
+
CLOSE = 'Serial Port.Disconnect'
|
|
192
|
+
PORT_STATE = 'Serial Port.State'
|
|
193
|
+
|
|
194
|
+
REMOVE = 'Remove Device'
|
|
195
|
+
|
|
196
|
+
def __str__(self):
|
|
197
|
+
'''
|
|
198
|
+
Return the last part of the enum value (Param name).
|
|
199
|
+
'''
|
|
200
|
+
return self.value.split('.')[-1]
|
|
201
|
+
|
|
202
|
+
def get_path(self):
|
|
203
|
+
'''
|
|
204
|
+
Return the full parameter path.
|
|
205
|
+
'''
|
|
206
|
+
return self.value.split('.')
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
class LaserRelayView(Tree):
|
|
210
|
+
PARAMS = RelayParams
|
|
211
|
+
sendCommandActivated = Signal()
|
|
212
|
+
removed = Signal(object)
|
|
213
|
+
|
|
214
|
+
def __init__(
|
|
215
|
+
self, parent: Optional['QtWidgets.QWidget'] = None, relay: LaserRelay = None
|
|
216
|
+
):
|
|
217
|
+
self.__laserRelay = relay if relay else LaserRelay()
|
|
218
|
+
|
|
219
|
+
super().__init__(parent=parent)
|
|
220
|
+
|
|
221
|
+
def create_parameters(self):
|
|
222
|
+
'''
|
|
223
|
+
Create the parameter tree structure.
|
|
224
|
+
'''
|
|
225
|
+
params = [
|
|
226
|
+
{
|
|
227
|
+
'name': str(RelayParams.MODEL),
|
|
228
|
+
'type': 'str',
|
|
229
|
+
'value': 'Laser Relay Box',
|
|
230
|
+
'readonly': True,
|
|
231
|
+
},
|
|
232
|
+
{'name': str(RelayParams.ALEX), 'type': 'bool', 'value': False},
|
|
233
|
+
{'name': str(RelayParams.SEND_COMMAND), 'type': 'action'},
|
|
234
|
+
{
|
|
235
|
+
'name': str(RelayParams.SERIAL_PORT),
|
|
236
|
+
'type': 'group',
|
|
237
|
+
'expanded': False,
|
|
238
|
+
'children': [
|
|
239
|
+
{
|
|
240
|
+
'name': str(RelayParams.PORT),
|
|
241
|
+
'type': 'list',
|
|
242
|
+
'limits': [
|
|
243
|
+
info.portName()
|
|
244
|
+
for info in QtSerialPort.QSerialPortInfo.availablePorts()
|
|
245
|
+
],
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
'name': str(RelayParams.BAUDRATE),
|
|
249
|
+
'type': 'list',
|
|
250
|
+
'value': 115200,
|
|
251
|
+
'limits': [
|
|
252
|
+
baudrate
|
|
253
|
+
for baudrate in \
|
|
254
|
+
QtSerialPort.QSerialPortInfo.standardBaudRates()
|
|
255
|
+
],
|
|
256
|
+
},
|
|
257
|
+
{'name': str(RelayParams.SET_PORT), 'type': 'action'},
|
|
258
|
+
{'name': str(RelayParams.OPEN), 'type': 'action'},
|
|
259
|
+
{'name': str(RelayParams.CLOSE), 'type': 'action'},
|
|
260
|
+
{
|
|
261
|
+
'name': str(RelayParams.PORT_STATE),
|
|
262
|
+
'type': 'str',
|
|
263
|
+
'value': 'closed',
|
|
264
|
+
'readonly': True,
|
|
265
|
+
},
|
|
266
|
+
],
|
|
267
|
+
},
|
|
268
|
+
]
|
|
269
|
+
|
|
270
|
+
self.param_tree = Parameter.create(name='', type='group', children=params)
|
|
271
|
+
self.param_tree.sigTreeStateChanged.connect(self.change)
|
|
272
|
+
self.header().setSectionResizeMode(
|
|
273
|
+
QtWidgets.QHeaderView.ResizeMode.ResizeToContents
|
|
274
|
+
)
|
|
275
|
+
|
|
276
|
+
self.get_param(RelayParams.CLOSE).sigActivated.connect(self.__laserRelay.close)
|
|
277
|
+
self.get_param(RelayParams.SEND_COMMAND).sigActivated.connect(
|
|
278
|
+
lambda: self.sendCommandActivated.emit()
|
|
279
|
+
)
|
|
280
|
+
|
|
281
|
+
def remove_widget(self):
|
|
282
|
+
'''
|
|
283
|
+
Remove the widget from its parent.
|
|
284
|
+
|
|
285
|
+
This method removes the view from its parent widget if
|
|
286
|
+
the laser relay is not open.
|
|
287
|
+
'''
|
|
288
|
+
if self.parent() and not self.__laserRelay.isOpen():
|
|
289
|
+
self.parent().layout().removeWidget(self)
|
|
290
|
+
self.removed.emit(self)
|
|
291
|
+
self.deleteLater()
|
|
292
|
+
else:
|
|
293
|
+
print(f'Disconnect Laser Relay before removing!')
|
|
294
|
+
|
|
295
|
+
def StartGUI():
|
|
296
|
+
'''Initializes a new :class:`QApplication` and :class:`LaserRelay`.
|
|
297
|
+
|
|
298
|
+
Use
|
|
299
|
+
-------
|
|
300
|
+
app, window = LaserRelay.StartGUI()
|
|
301
|
+
|
|
302
|
+
app.exec()
|
|
303
|
+
|
|
304
|
+
Returns
|
|
305
|
+
-------
|
|
306
|
+
tuple (:class:`QApplication`, :class:`LaserRelay`)
|
|
307
|
+
Returns a tuple with QApp and LaserRelay main window.
|
|
308
|
+
'''
|
|
309
|
+
return StartGUI(LaserRelay)
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
class LaserRelayController:
|
|
313
|
+
def __init__(self, relay: LaserRelay = None, view: LaserRelayView = None):
|
|
314
|
+
'''
|
|
315
|
+
Initialize the LaserRelayController class.
|
|
316
|
+
|
|
317
|
+
This class controls the interaction between the LaserRelay
|
|
318
|
+
and the LaserRelayView widget.
|
|
319
|
+
|
|
320
|
+
Parameters
|
|
321
|
+
----------
|
|
322
|
+
relay: LaserRelay
|
|
323
|
+
The laser relay to be controlled.
|
|
324
|
+
Default is a new LaserRelay instance.
|
|
325
|
+
view: LaserRelayView
|
|
326
|
+
The GUI/view for the laser relay.
|
|
327
|
+
Default is a new LaserRelayView instance with the relay as an argument.
|
|
328
|
+
'''
|
|
329
|
+
self.__relay = relay if relay else LaserRelay()
|
|
330
|
+
self.__view = view if view else LaserRelayView(relay=self.__relay)
|
|
331
|
+
|
|
332
|
+
self.__view.get_param(RelayParams.SET_PORT).sigActivated.connect(
|
|
333
|
+
self.set_config
|
|
334
|
+
)
|
|
335
|
+
self.__view.get_param(RelayParams.OPEN).sigActivated.connect(self.connect)
|
|
336
|
+
|
|
337
|
+
@property
|
|
338
|
+
def sendCommandActivated(self):
|
|
339
|
+
'''
|
|
340
|
+
PyQt signal emitted when the "Send Command" action is
|
|
341
|
+
activated in the parameter tree.
|
|
342
|
+
'''
|
|
343
|
+
return self.__view.sendCommandActivated
|
|
344
|
+
|
|
345
|
+
@property
|
|
346
|
+
def lastCommand(self):
|
|
347
|
+
'''
|
|
348
|
+
The last command sent by the LaserRelay instance.
|
|
349
|
+
|
|
350
|
+
Returns
|
|
351
|
+
-------
|
|
352
|
+
str
|
|
353
|
+
The last command sent by the LaserRelay instance.
|
|
354
|
+
'''
|
|
355
|
+
return self.__relay.lastCommand
|
|
356
|
+
|
|
357
|
+
@property
|
|
358
|
+
def view(self):
|
|
359
|
+
'''
|
|
360
|
+
The GUI/view for the laser relay.
|
|
361
|
+
|
|
362
|
+
Returns
|
|
363
|
+
-------
|
|
364
|
+
:class:`LaserRelayView`
|
|
365
|
+
The GUI/view for the laser relay.
|
|
366
|
+
'''
|
|
367
|
+
return self.__view
|
|
368
|
+
|
|
369
|
+
def portName(self):
|
|
370
|
+
'''
|
|
371
|
+
Get the name of the serial port.
|
|
372
|
+
|
|
373
|
+
Returns
|
|
374
|
+
-------
|
|
375
|
+
str
|
|
376
|
+
The name of the serial port.
|
|
377
|
+
'''
|
|
378
|
+
return self.__relay.portName()
|
|
379
|
+
|
|
380
|
+
def setPortName(self, value: str):
|
|
381
|
+
'''
|
|
382
|
+
Set the name of the serial port.
|
|
383
|
+
|
|
384
|
+
Parameters
|
|
385
|
+
----------
|
|
386
|
+
value : str
|
|
387
|
+
The name of the serial port.
|
|
388
|
+
'''
|
|
389
|
+
self.__relay.setPortName(value)
|
|
390
|
+
self.__view.set_param_value(RelayParams.PORT, value)
|
|
391
|
+
|
|
392
|
+
def baudRate(self):
|
|
393
|
+
'''
|
|
394
|
+
Get the baud rate of the serial port.
|
|
395
|
+
|
|
396
|
+
Returns
|
|
397
|
+
-------
|
|
398
|
+
int
|
|
399
|
+
The baud rate of the serial port.
|
|
400
|
+
'''
|
|
401
|
+
return self.__relay.baudRate()
|
|
402
|
+
|
|
403
|
+
def setBaudRate(self, value: int):
|
|
404
|
+
'''
|
|
405
|
+
Set the baud rate of the serial port.
|
|
406
|
+
|
|
407
|
+
Parameters
|
|
408
|
+
----------
|
|
409
|
+
value : int
|
|
410
|
+
The baud rate of the serial port.
|
|
411
|
+
'''
|
|
412
|
+
self.__relay.setBaudRate(value)
|
|
413
|
+
self.__view.set_param_value(RelayParams.BAUDRATE, value)
|
|
414
|
+
|
|
415
|
+
def isOpen(self):
|
|
416
|
+
'''
|
|
417
|
+
Check if the laser relay is open.
|
|
418
|
+
|
|
419
|
+
Returns
|
|
420
|
+
-------
|
|
421
|
+
bool
|
|
422
|
+
True if the laser relay is open, False otherwise.
|
|
423
|
+
'''
|
|
424
|
+
return self.__relay.isOpen()
|
|
425
|
+
|
|
426
|
+
def set_config(self):
|
|
427
|
+
'''Sets the serial port configuration.
|
|
428
|
+
|
|
429
|
+
This method sets the serial port configuration based on the current
|
|
430
|
+
settings in the parameter tree.
|
|
431
|
+
'''
|
|
432
|
+
if not self.__relay.isOpen():
|
|
433
|
+
self.__relay.setPortName(self.__view.get_param_value(RelayParams.PORT))
|
|
434
|
+
self.__relay.setBaudRate(self.__view.get_param_value(RelayParams.BAUDRATE))
|
|
435
|
+
|
|
436
|
+
def connect(self):
|
|
437
|
+
'''
|
|
438
|
+
Connect to the laser relay.
|
|
439
|
+
|
|
440
|
+
This method opens the serial port and sets the port state to "open" in the
|
|
441
|
+
parameter tree.
|
|
442
|
+
'''
|
|
443
|
+
self.__relay.open()
|
|
444
|
+
|
|
445
|
+
self.__view.set_param_value(RelayParams.PORT_STATE, 'open')
|
|
446
|
+
|
|
447
|
+
def disconnect(self):
|
|
448
|
+
'''
|
|
449
|
+
Disconnect from the laser relay.
|
|
450
|
+
'''
|
|
451
|
+
self.__relay.close()
|
|
452
|
+
|
|
453
|
+
self.__view.set_param_value(RelayParams.PORT_STATE, 'closed')
|
|
454
|
+
|
|
455
|
+
def isALEX(self) -> bool:
|
|
456
|
+
'''
|
|
457
|
+
Check if the ALEX flag is set.
|
|
458
|
+
|
|
459
|
+
Returns
|
|
460
|
+
-------
|
|
461
|
+
bool
|
|
462
|
+
True if the ALEX flag is set, False otherwise.
|
|
463
|
+
'''
|
|
464
|
+
return self.__relay.isALEX()
|
|
465
|
+
|
|
466
|
+
def sendCommand(self, config: str):
|
|
467
|
+
'''
|
|
468
|
+
Send a configuration command to the laser relay.
|
|
469
|
+
|
|
470
|
+
Parameters
|
|
471
|
+
----------
|
|
472
|
+
config : str
|
|
473
|
+
The configuration command to send to the laser relay.
|
|
474
|
+
'''
|
|
475
|
+
self.__relay.sendConfig(config)
|
|
476
|
+
|
|
477
|
+
def updatePortState(self):
|
|
478
|
+
'''
|
|
479
|
+
Update the port state in the parameter tree.
|
|
480
|
+
|
|
481
|
+
This method updates the port state in the parameter
|
|
482
|
+
tree to reflect the current state of the laser relay.
|
|
483
|
+
'''
|
|
484
|
+
color = '#004CB6' if self.isOpen() else 'black'
|
|
485
|
+
|
|
486
|
+
self.__view.set_param_value(
|
|
487
|
+
RelayParams.PORT_STATE, 'open' if self.isOpen() else 'closed'
|
|
488
|
+
)
|
|
489
|
+
|
|
490
|
+
next(self.__view.get_param(RelayParams.OPEN).items.keys()).button.setStyleSheet(
|
|
491
|
+
f'background-color: {color}'
|
|
492
|
+
)
|
|
493
|
+
|
|
494
|
+
def updateHighlight(self, config: str):
|
|
495
|
+
'''
|
|
496
|
+
Update the highlight style of the "Send Command" action.
|
|
497
|
+
|
|
498
|
+
This method updates the highlight style of the "Send Command" action
|
|
499
|
+
in the parameter tree based on whether the given configuration matches
|
|
500
|
+
the last command sent.
|
|
501
|
+
|
|
502
|
+
Parameters
|
|
503
|
+
----------
|
|
504
|
+
config : str
|
|
505
|
+
The configuration to compare with the last command sent.
|
|
506
|
+
'''
|
|
507
|
+
style = ''
|
|
508
|
+
if config is not None:
|
|
509
|
+
if config == self.lastCommand:
|
|
510
|
+
style = 'background-color: #004CB6'
|
|
511
|
+
else:
|
|
512
|
+
style = 'background-color: black'
|
|
513
|
+
|
|
514
|
+
next(
|
|
515
|
+
self.__view.get_param(RelayParams.SEND_COMMAND).items.keys()
|
|
516
|
+
).button.setStyleSheet(style)
|
|
517
|
+
|
|
518
|
+
def refreshPorts(self):
|
|
519
|
+
"""
|
|
520
|
+
Refreshes the available serial ports list in the GUI.
|
|
521
|
+
|
|
522
|
+
This method updates the list of available serial ports in the GUI by fetching
|
|
523
|
+
the current list of available ports and setting it as the options for the
|
|
524
|
+
'Serial Port' parameter in the parameter tree.
|
|
525
|
+
"""
|
|
526
|
+
if not self.isOpen():
|
|
527
|
+
self.__view.get_param(RelayParams.PORT).setLimits(
|
|
528
|
+
[
|
|
529
|
+
info.portName()
|
|
530
|
+
for info in QtSerialPort.QSerialPortInfo.availablePorts()
|
|
531
|
+
]
|
|
532
|
+
)
|
|
533
|
+
|
|
534
|
+
def getCommand(self, config: str):
|
|
535
|
+
'''
|
|
536
|
+
Get the full configuration command to send to the laser relay.
|
|
537
|
+
|
|
538
|
+
This method returns the full configuration command to send to the laser relay,
|
|
539
|
+
including the ALEXON/ALEXOFF command based on the current ALEX flag.
|
|
540
|
+
|
|
541
|
+
Parameters
|
|
542
|
+
----------
|
|
543
|
+
config : str
|
|
544
|
+
The configuration command to send to the laser relay,
|
|
545
|
+
excluding the ALEXON/ALEXOFF command.
|
|
546
|
+
|
|
547
|
+
Returns
|
|
548
|
+
-------
|
|
549
|
+
str
|
|
550
|
+
The full configuration command to send to the laser relay,
|
|
551
|
+
including the ALEXON/ALEXOFF command.
|
|
552
|
+
'''
|
|
553
|
+
return config + ('ALEXON' if self.isALEX() else 'ALEXOFF') + '\r'
|
|
554
|
+
|
|
555
|
+
def get_config(self) -> dict:
|
|
556
|
+
'''
|
|
557
|
+
Get the current configuration of the laser relay.
|
|
558
|
+
|
|
559
|
+
Returns
|
|
560
|
+
-------
|
|
561
|
+
dict
|
|
562
|
+
The current configuration of the laser relay.
|
|
563
|
+
'''
|
|
564
|
+
return {
|
|
565
|
+
'port': self.__relay.portName(),
|
|
566
|
+
'baudrate': self.__relay.baudRate(),
|
|
567
|
+
'alex': self.isALEX(),
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
def load_config(self, config: dict):
|
|
571
|
+
'''
|
|
572
|
+
Load the configuration from a dictionary.
|
|
573
|
+
|
|
574
|
+
Parameters
|
|
575
|
+
----------
|
|
576
|
+
config : dict
|
|
577
|
+
The configuration dictionary to load.
|
|
578
|
+
'''
|
|
579
|
+
if not isinstance(config, dict):
|
|
580
|
+
raise TypeError("Config must be a dictionary.")
|
|
581
|
+
|
|
582
|
+
port = config.get('port')
|
|
583
|
+
baudrate = config.get('baudrate')
|
|
584
|
+
alex = config.get('alex')
|
|
585
|
+
|
|
586
|
+
if port:
|
|
587
|
+
self.setPortName(port)
|
|
588
|
+
if baudrate:
|
|
589
|
+
self.setBaudRate(baudrate)
|
|
590
|
+
if alex:
|
|
591
|
+
self.__relay.setALEX(alex)
|
|
592
|
+
|
|
593
|
+
def __str__(self):
|
|
594
|
+
return 'Laser Relay Controller'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from microEye.hardware.mieye.miEye import miEye_module
|