pymodaq 5.1.6__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 (154) hide show
  1. pymodaq/__init__.py +98 -0
  2. pymodaq/control_modules/__init__.py +1 -0
  3. pymodaq/control_modules/daq_move.py +1238 -0
  4. pymodaq/control_modules/daq_move_ui/__init__.py +0 -0
  5. pymodaq/control_modules/daq_move_ui/factory.py +48 -0
  6. pymodaq/control_modules/daq_move_ui/ui_base.py +359 -0
  7. pymodaq/control_modules/daq_move_ui/uis/__init__.py +0 -0
  8. pymodaq/control_modules/daq_move_ui/uis/binary.py +139 -0
  9. pymodaq/control_modules/daq_move_ui/uis/original.py +120 -0
  10. pymodaq/control_modules/daq_move_ui/uis/relative.py +124 -0
  11. pymodaq/control_modules/daq_move_ui/uis/simple.py +126 -0
  12. pymodaq/control_modules/daq_viewer.py +1517 -0
  13. pymodaq/control_modules/daq_viewer_ui.py +407 -0
  14. pymodaq/control_modules/mocks.py +57 -0
  15. pymodaq/control_modules/move_utility_classes.py +1141 -0
  16. pymodaq/control_modules/thread_commands.py +137 -0
  17. pymodaq/control_modules/ui_utils.py +72 -0
  18. pymodaq/control_modules/utils.py +591 -0
  19. pymodaq/control_modules/viewer_utility_classes.py +670 -0
  20. pymodaq/daq_utils/__init__.py +0 -0
  21. pymodaq/daq_utils/daq_utils.py +6 -0
  22. pymodaq/dashboard.py +2396 -0
  23. pymodaq/examples/Labview_TCP_Client/DAQ_TCP_Client.aliases +3 -0
  24. pymodaq/examples/Labview_TCP_Client/DAQ_TCP_Client.lvlps +3 -0
  25. pymodaq/examples/Labview_TCP_Client/DAQ_TCP_Client.lvproj +32 -0
  26. pymodaq/examples/Labview_TCP_Client/DAQ_TCP_Client.vi +0 -0
  27. pymodaq/examples/Labview_TCP_Client/DAQ_TCP_Server_1Dgaussian.vi +0 -0
  28. pymodaq/examples/Labview_TCP_Client/DAQ_TCP_Server_2Dgaussian.vi +0 -0
  29. pymodaq/examples/Labview_TCP_Client/DAQ_TCP_read_cmd.vi +0 -0
  30. pymodaq/examples/Labview_TCP_Client/DAQ_TCP_read_float.vi +0 -0
  31. pymodaq/examples/Labview_TCP_Client/DAQ_TCP_read_int.vi +0 -0
  32. pymodaq/examples/Labview_TCP_Client/DAQ_TCP_send_data.vi +0 -0
  33. pymodaq/examples/Labview_TCP_Client/DAQ_TCP_send_int.vi +0 -0
  34. pymodaq/examples/Labview_TCP_Client/DAQ_TCP_send_scalar.vi +0 -0
  35. pymodaq/examples/Labview_TCP_Client/DAQ_TCP_send_string.vi +0 -0
  36. pymodaq/examples/Labview_TCP_Client/client_state.ctl +0 -0
  37. pymodaq/examples/Labview_TCP_Client/cmd_types.ctl +0 -0
  38. pymodaq/examples/__init__.py +0 -0
  39. pymodaq/examples/function_plotter.py +160 -0
  40. pymodaq/examples/nonlinearscanner.py +126 -0
  41. pymodaq/examples/qt_less_standalone_module.py +165 -0
  42. pymodaq/examples/tcp_client.py +97 -0
  43. pymodaq/extensions/__init__.py +25 -0
  44. pymodaq/extensions/adaptive/__init__.py +2 -0
  45. pymodaq/extensions/adaptive/adaptive_optimization.py +179 -0
  46. pymodaq/extensions/adaptive/loss_function/_1d_loss_functions.py +73 -0
  47. pymodaq/extensions/adaptive/loss_function/_2d_loss_functions.py +73 -0
  48. pymodaq/extensions/adaptive/loss_function/__init__.py +3 -0
  49. pymodaq/extensions/adaptive/loss_function/loss_factory.py +110 -0
  50. pymodaq/extensions/adaptive/utils.py +123 -0
  51. pymodaq/extensions/bayesian/__init__.py +2 -0
  52. pymodaq/extensions/bayesian/acquisition/__init__.py +2 -0
  53. pymodaq/extensions/bayesian/acquisition/acquisition_function_factory.py +80 -0
  54. pymodaq/extensions/bayesian/acquisition/base_acquisition_function.py +105 -0
  55. pymodaq/extensions/bayesian/bayesian_optimization.py +143 -0
  56. pymodaq/extensions/bayesian/utils.py +180 -0
  57. pymodaq/extensions/console.py +73 -0
  58. pymodaq/extensions/daq_logger/__init__.py +1 -0
  59. pymodaq/extensions/daq_logger/abstract.py +52 -0
  60. pymodaq/extensions/daq_logger/daq_logger.py +519 -0
  61. pymodaq/extensions/daq_logger/db/__init__.py +0 -0
  62. pymodaq/extensions/daq_logger/db/db_logger.py +300 -0
  63. pymodaq/extensions/daq_logger/db/db_logger_models.py +100 -0
  64. pymodaq/extensions/daq_logger/h5logging.py +84 -0
  65. pymodaq/extensions/daq_scan.py +1218 -0
  66. pymodaq/extensions/daq_scan_ui.py +241 -0
  67. pymodaq/extensions/data_mixer/__init__.py +0 -0
  68. pymodaq/extensions/data_mixer/daq_0Dviewer_DataMixer.py +97 -0
  69. pymodaq/extensions/data_mixer/data_mixer.py +262 -0
  70. pymodaq/extensions/data_mixer/model.py +108 -0
  71. pymodaq/extensions/data_mixer/models/__init__.py +0 -0
  72. pymodaq/extensions/data_mixer/models/equation_model.py +91 -0
  73. pymodaq/extensions/data_mixer/models/gaussian_fit_model.py +65 -0
  74. pymodaq/extensions/data_mixer/parser.py +53 -0
  75. pymodaq/extensions/data_mixer/utils.py +23 -0
  76. pymodaq/extensions/h5browser.py +9 -0
  77. pymodaq/extensions/optimizers_base/__init__.py +0 -0
  78. pymodaq/extensions/optimizers_base/optimizer.py +1016 -0
  79. pymodaq/extensions/optimizers_base/thread_commands.py +22 -0
  80. pymodaq/extensions/optimizers_base/utils.py +427 -0
  81. pymodaq/extensions/pid/__init__.py +16 -0
  82. pymodaq/extensions/pid/actuator_controller.py +14 -0
  83. pymodaq/extensions/pid/daq_move_PID.py +154 -0
  84. pymodaq/extensions/pid/pid_controller.py +1016 -0
  85. pymodaq/extensions/pid/utils.py +189 -0
  86. pymodaq/extensions/utils.py +111 -0
  87. pymodaq/icon.ico +0 -0
  88. pymodaq/post_treatment/__init__.py +6 -0
  89. pymodaq/post_treatment/load_and_plot.py +352 -0
  90. pymodaq/resources/__init__.py +0 -0
  91. pymodaq/resources/config_template.toml +57 -0
  92. pymodaq/resources/preset_default.xml +1 -0
  93. pymodaq/resources/setup_plugin.py +73 -0
  94. pymodaq/splash.png +0 -0
  95. pymodaq/utils/__init__.py +0 -0
  96. pymodaq/utils/array_manipulation.py +6 -0
  97. pymodaq/utils/calibration_camera.py +180 -0
  98. pymodaq/utils/chrono_timer.py +203 -0
  99. pymodaq/utils/config.py +53 -0
  100. pymodaq/utils/conftests.py +5 -0
  101. pymodaq/utils/daq_utils.py +158 -0
  102. pymodaq/utils/data.py +128 -0
  103. pymodaq/utils/enums.py +6 -0
  104. pymodaq/utils/exceptions.py +38 -0
  105. pymodaq/utils/gui_utils/__init__.py +10 -0
  106. pymodaq/utils/gui_utils/loader_utils.py +75 -0
  107. pymodaq/utils/gui_utils/utils.py +18 -0
  108. pymodaq/utils/gui_utils/widgets/lcd.py +8 -0
  109. pymodaq/utils/h5modules/__init__.py +2 -0
  110. pymodaq/utils/h5modules/module_saving.py +526 -0
  111. pymodaq/utils/leco/__init__.py +25 -0
  112. pymodaq/utils/leco/daq_move_LECODirector.py +217 -0
  113. pymodaq/utils/leco/daq_xDviewer_LECODirector.py +163 -0
  114. pymodaq/utils/leco/director_utils.py +74 -0
  115. pymodaq/utils/leco/leco_director.py +166 -0
  116. pymodaq/utils/leco/pymodaq_listener.py +364 -0
  117. pymodaq/utils/leco/rpc_method_definitions.py +43 -0
  118. pymodaq/utils/leco/utils.py +74 -0
  119. pymodaq/utils/logger.py +6 -0
  120. pymodaq/utils/managers/__init__.py +0 -0
  121. pymodaq/utils/managers/batchscan_manager.py +346 -0
  122. pymodaq/utils/managers/modules_manager.py +589 -0
  123. pymodaq/utils/managers/overshoot_manager.py +242 -0
  124. pymodaq/utils/managers/preset_manager.py +229 -0
  125. pymodaq/utils/managers/preset_manager_utils.py +262 -0
  126. pymodaq/utils/managers/remote_manager.py +484 -0
  127. pymodaq/utils/math_utils.py +6 -0
  128. pymodaq/utils/messenger.py +6 -0
  129. pymodaq/utils/parameter/__init__.py +10 -0
  130. pymodaq/utils/parameter/utils.py +6 -0
  131. pymodaq/utils/scanner/__init__.py +5 -0
  132. pymodaq/utils/scanner/scan_config.py +16 -0
  133. pymodaq/utils/scanner/scan_factory.py +259 -0
  134. pymodaq/utils/scanner/scan_selector.py +477 -0
  135. pymodaq/utils/scanner/scanner.py +324 -0
  136. pymodaq/utils/scanner/scanners/_1d_scanners.py +174 -0
  137. pymodaq/utils/scanner/scanners/_2d_scanners.py +299 -0
  138. pymodaq/utils/scanner/scanners/__init__.py +1 -0
  139. pymodaq/utils/scanner/scanners/sequential.py +224 -0
  140. pymodaq/utils/scanner/scanners/tabular.py +319 -0
  141. pymodaq/utils/scanner/utils.py +110 -0
  142. pymodaq/utils/svg/__init__.py +6 -0
  143. pymodaq/utils/svg/svg_renderer.py +20 -0
  144. pymodaq/utils/svg/svg_view.py +35 -0
  145. pymodaq/utils/svg/svg_viewer2D.py +50 -0
  146. pymodaq/utils/tcp_ip/__init__.py +6 -0
  147. pymodaq/utils/tcp_ip/mysocket.py +12 -0
  148. pymodaq/utils/tcp_ip/serializer.py +13 -0
  149. pymodaq/utils/tcp_ip/tcp_server_client.py +772 -0
  150. pymodaq-5.1.6.dist-info/METADATA +238 -0
  151. pymodaq-5.1.6.dist-info/RECORD +154 -0
  152. pymodaq-5.1.6.dist-info/WHEEL +4 -0
  153. pymodaq-5.1.6.dist-info/entry_points.txt +7 -0
  154. pymodaq-5.1.6.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,519 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+
4
+ """Automated scanning module functionalities for PyMoDAQ
5
+
6
+ Contains all objects related to the DAQScan module, to do automated scans, saving data...
7
+ """
8
+
9
+ import sys
10
+ from collections import OrderedDict
11
+ import datetime
12
+ from typing import TYPE_CHECKING, Union
13
+
14
+ from pymodaq_utils.logger import set_logger, get_module_name
15
+ from pymodaq_gui.utils.dock import Dock, DockArea
16
+ from pymodaq_utils.config import Config
17
+ from pymodaq_gui.parameter import ioxml
18
+
19
+ from qtpy import QtWidgets
20
+ from qtpy.QtCore import QObject, Slot, QThread, Signal, Qt
21
+
22
+ from pymodaq_gui.utils.widgets import QLED
23
+
24
+
25
+ from pymodaq.extensions.daq_logger.h5logging import H5Logger
26
+ from pymodaq.utils.managers.modules_manager import ModulesManager
27
+ from pymodaq.utils.data import DataActuator, DataToExport
28
+ from pymodaq.extensions.utils import CustomExt
29
+
30
+ if TYPE_CHECKING:
31
+ from pymodaq.dashboard import DashBoard
32
+
33
+
34
+ config = Config()
35
+ logger = set_logger(get_module_name(__file__))
36
+
37
+
38
+ try:
39
+ import sqlalchemy
40
+ from pymodaq.extensions.daq_logger.db.db_logger import DataBaseLogger
41
+ is_sql = True
42
+ except Exception as e:
43
+ is_sql = False
44
+ logger.info('To enable logging to database install: sqalchemy and sqlalchemy_utils packages as'
45
+ ' well as the backend for your specific database, for instance psycopg2 for'
46
+ ' PostGreSQL database')
47
+
48
+ LOG_TYPES = ['None', 'H5 File']
49
+ if is_sql:
50
+ LOG_TYPES.append('SQL DataBase')
51
+
52
+
53
+ class DAQ_Logger(CustomExt):
54
+ """
55
+ Main class initializing a DAQ_Logger module
56
+ """
57
+ command_DAQ_signal = Signal(list)
58
+ status_signal = Signal(str)
59
+
60
+ params = [
61
+ {'title': 'Log Type:', 'name': 'log_type', 'type': 'str', 'value': '', 'readonly': True},
62
+ ]
63
+
64
+ def __init__(self, dockarea: DockArea = None, dashboard: 'DashBoard' = None):
65
+ """
66
+
67
+ Parameters
68
+ ----------
69
+ dockarea: DockArea
70
+ instance of the modified pyqtgraph Dockarea
71
+ dashboard: DashBoard
72
+ instance of the pymodaq dashboard
73
+ """
74
+
75
+ super().__init__(dockarea, dashboard)
76
+
77
+ self.wait_time = 1000
78
+ self.logger: Union[H5Logger, DataBaseLogger] = None
79
+ self.setup_ui()
80
+
81
+ def setup_actions(self):
82
+ '''
83
+ subclass method from ActionManager
84
+ '''
85
+ logger.debug('setting actions')
86
+ self.add_action('quit', 'Quit', 'close2', "Quit program", toolbar=self.toolbar)
87
+ self.toolbar.addSeparator()
88
+ self.add_action('start', 'Start Logging', 'run2', "Start the logging",
89
+ checkable=True, toolbar=self.toolbar)
90
+ self.add_action('stop', 'Stop', 'stop', 'Stop/pause logging',
91
+ checkable=False, toolbar=self.toolbar)
92
+
93
+ log_type_combo = QtWidgets.QComboBox()
94
+ log_type_combo.addItems(LOG_TYPES)
95
+ log_type_combo.currentTextChanged.connect(self.set_log_type)
96
+ self._actions['log_type'] = self.toolbar.addWidget(log_type_combo)
97
+ self.toolbar.addSeparator()
98
+ self.add_action('grab_all', 'Grab All', 'run_all', "Grab all selected detectors's data and actuators's value",
99
+ checkable=False, toolbar=self.toolbar)
100
+ self.add_action('stop_all', 'Stop All', 'stop_all', "Stop all selected detectors and actuators",
101
+ checkable=False, toolbar=self.toolbar)
102
+ self.add_action('infos', 'Log infos', 'information2', "Show log file",
103
+ checkable=False, toolbar=self.toolbar)
104
+
105
+ self.set_action_enabled('start', False)
106
+ self.set_action_enabled('stop', False)
107
+
108
+ logger.debug('actions set')
109
+
110
+ def setup_docks(self):
111
+ logger.debug('setting docks')
112
+ self.docks['detectors'] = Dock("Detectors")
113
+ splitter = QtWidgets.QSplitter(Qt.Vertical)
114
+ self.docks['detectors'].addWidget(splitter)
115
+ splitter.addWidget(self.settings_tree)
116
+ splitter.addWidget(self.modules_manager.settings_tree)
117
+ self.dockarea.addDock(self.docks['detectors'])
118
+
119
+ self.docks['logger_settings'] = Dock("Logger Settings")
120
+ self.dockarea.addDock(self.docks['logger_settings'], 'right', self.docks['detectors'])
121
+
122
+ self.statusbar.setMaximumHeight(25)
123
+ self.status_widget = QtWidgets.QLabel('Initializing')
124
+ self.statusbar.addPermanentWidget(self.status_widget)
125
+
126
+ self.start_log_time = QtWidgets.QDateTimeEdit()
127
+ self.start_log_time.setReadOnly(True)
128
+ self.start_log_time.setToolTip('Logging started at:')
129
+ self.statusbar.addPermanentWidget(self.start_log_time)
130
+
131
+ self.logging_state = QLED()
132
+ self.logging_state.setToolTip('logging status: green (running), red (idle)')
133
+ self.logging_state.clickable = False
134
+ self.statusbar.addPermanentWidget(self.logging_state)
135
+
136
+ def connect_things(self):
137
+ self.status_signal[str].connect(self.dashboard.add_status)
138
+ self._actions['quit'].connect_to(self.quit_fun)
139
+
140
+ self._actions['start'].connect_to(self.start_logging)
141
+ self._actions['stop'].connect_to(self.stop_logging)
142
+ self._actions['grab_all'].connect_to(self.start_all)
143
+ self._actions['stop_all'].connect_to(self.stop_all)
144
+
145
+ self._actions['infos'].connect_to(self.dashboard.show_log)
146
+
147
+ def setup_menu(self, menubar: QtWidgets.QMenuBar = None):
148
+ """
149
+ """
150
+ file_menu = menubar.addMenu('File')
151
+ self.affect_to('infos', file_menu)
152
+
153
+ def value_changed(self, param):
154
+ if param.name() == 'log_type':
155
+ if param.value() != 'None':
156
+ self.set_action_enabled('start', True)
157
+ self.set_action_enabled('stop', True)
158
+ self.set_logger(param.value())
159
+
160
+ def set_logger(self, logger_interface):
161
+ if self.logger is not None:
162
+ self.logger.close()
163
+ self.docks['logger_settings'].removeWidgets()
164
+
165
+ if logger_interface == 'H5 File':
166
+ self.logger = H5Logger(self.modules_manager)
167
+ elif logger_interface == 'SQL DataBase':
168
+ self.logger = DataBaseLogger(self.dashboard.preset_file.stem)
169
+ else:
170
+ return
171
+
172
+ self.docks['logger_settings'].addWidget(self.logger.settings_tree)
173
+
174
+ def quit_fun(self):
175
+ """
176
+ Quit the current instance of DAQ_scan and close on cascade move and detector modules.
177
+
178
+ See Also
179
+ --------
180
+ quit_fun
181
+ """
182
+ try:
183
+ self.logger.close()
184
+ except Exception as e:
185
+ logger.exception(str(e))
186
+
187
+ self.dockarea.parent().close()
188
+
189
+ def set_continuous_save(self):
190
+ """
191
+ Set a continous save file using the base path located file with
192
+ a header-name containing date as a string.
193
+
194
+ See Also
195
+ --------
196
+ daq_utils.set_current_scan_path
197
+ """
198
+ if self.logger is not None:
199
+ self.do_continuous_save = True
200
+ self.logger.settings.child('N_saved').show()
201
+ self.logger.settings.child('N_saved').setValue(0)
202
+
203
+ settings_str = b'<All_settings>'
204
+ settings_str += ioxml.parameter_to_xml_string(self.dashboard.settings)
205
+ settings_str += ioxml.parameter_to_xml_string(
206
+ self.dashboard.preset_manager.preset_params)
207
+ if self.dashboard.settings.child('loaded_files', 'overshoot_file').value() != '':
208
+ settings_str += ioxml.parameter_to_xml_string(
209
+ self.dashboard.overshoot_manager.overshoot_params)
210
+ if self.dashboard.settings.child('loaded_files', 'roi_file').value() != '':
211
+ settings_str += ioxml.parameter_to_xml_string(
212
+ self.dashboard.roi_saver.roi_presets)
213
+ settings_str += ioxml.parameter_to_xml_string(self.settings)
214
+ settings_str += ioxml.parameter_to_xml_string(self.logger.settings)
215
+ settings_str += b'</All_settings>'
216
+
217
+ if not self.logger.init_logger(settings_str):
218
+ return False
219
+ logger.addHandler(self.logger.get_handler())
220
+ return True
221
+ else:
222
+ return False
223
+
224
+ def set_logging(self):
225
+ """
226
+
227
+ """
228
+ status = self.set_continuous_save()
229
+ if status:
230
+ modules_log = self.modules_manager.detectors_all + self.modules_manager.actuators_all
231
+ if modules_log != []:
232
+ # check if the modules are initialized
233
+ for module in modules_log:
234
+ if not module.initialized_state:
235
+ logger.error(f'module {module.title} is not initialized')
236
+ return False
237
+
238
+ # create the detectors in the chosen logger
239
+ for mod in modules_log:
240
+ settings_str = b'<All_settings>'
241
+ settings_str += ioxml.parameter_to_xml_string(mod.settings)
242
+
243
+ if mod.module_type == 'DAQ_Viewer':
244
+ for viewer in mod.ui.viewers:
245
+ if hasattr(viewer, 'roi_manager'):
246
+ settings_str += ioxml.parameter_to_xml_string(
247
+ viewer.roi_manager.settings)
248
+ settings_str += b'</All_settings>'
249
+ if mod.module_type == 'DAQ_Viewer':
250
+ self.logger.add_detector(mod.title, settings_str)
251
+ elif mod.module_type == 'DAQ_Move':
252
+ self.logger.add_actuator(mod.title, settings_str)
253
+
254
+ self._actions['start'].setEnabled(True)
255
+ self._actions['stop'].setEnabled(True)
256
+ return True
257
+ else:
258
+ self.update_status('Cannot start logging... No detectors selected')
259
+ self._actions['start'].setEnabled(False)
260
+ self._actions['stop'].setEnabled(True)
261
+ return False
262
+
263
+ else:
264
+ self.update_status('Cannot start logging... check connections')
265
+ self._actions['start'].setEnabled(False)
266
+ self._actions['stop'].setEnabled(True)
267
+ return False
268
+
269
+ def start_all(self):
270
+ for det in self.modules_manager.detectors:
271
+ det.grab()
272
+ for act in self.modules_manager.actuators:
273
+ act.grab()
274
+
275
+ def stop_all(self):
276
+ for det in self.modules_manager.detectors:
277
+ det.stop_grab()
278
+ for act in self.modules_manager.actuators:
279
+ act.stop_grab()
280
+
281
+ def set_log_type(self, log_type):
282
+ self.settings.child('log_type').setValue(log_type)
283
+
284
+ def start_logging(self):
285
+ """
286
+ Start a logging.
287
+ """
288
+ self.status_widget.setText('Starting logging')
289
+
290
+ self.overshoot = False
291
+ res = self.set_logging()
292
+
293
+ # mandatory to deal with multithreads
294
+ if self.runner_thread is not None:
295
+ self.command_DAQ_signal.disconnect()
296
+ self.exit_runner_thread()
297
+ self.runner_thread = None
298
+
299
+ self.runner_thread = QThread()
300
+
301
+ log_acquisition = DAQ_Logging(self.settings, self.logger, self.modules_manager)
302
+
303
+ log_acquisition.moveToThread(self.runner_thread)
304
+
305
+ self.command_DAQ_signal[list].connect(log_acquisition.queue_command)
306
+ log_acquisition.status_sig[list].connect(self.thread_status)
307
+
308
+ self.runner_thread.log_acquisition = log_acquisition
309
+ self.runner_thread.start()
310
+
311
+ self._actions['start'].setEnabled(False)
312
+ QtWidgets.QApplication.processEvents()
313
+ self.logging_state.set_as_false()
314
+
315
+ self.command_DAQ_signal.emit(["start_logging"])
316
+ self.status_widget.setText('Running acquisition')
317
+
318
+ def stop_logging(self):
319
+ """
320
+ Emit the command_DAQ signal "stop_acquisiion".
321
+
322
+ See Also
323
+ --------
324
+ set_ini_positions
325
+ """
326
+ preset_items_det = self.modules_manager.detectors
327
+ for det in preset_items_det:
328
+ det.stop()
329
+ self.command_DAQ_signal.emit(["stop_acquisition"])
330
+
331
+ if not self.dashboard.overshoot:
332
+ status = 'Data Logging has been stopped by user'
333
+ else:
334
+ status = 'Data Logging has been stopped due to overshoot'
335
+
336
+ self.update_status(status)
337
+ self._actions['start'].setEnabled(True)
338
+
339
+ @Slot(list)
340
+ def thread_status(self, status): # general function to get datas/infos from all threads back to the main
341
+ """
342
+ | General function to get datas/infos from all threads back to the main.
343
+ |
344
+
345
+ Switch the status with :
346
+ * *"Update status"* : Update the status bar with the status attribute txt message
347
+ * *"Update_scan_index"* : Set the value of the User Interface - indice_scan_sb attribute.
348
+ * *"Scan_done"* : Save the scan and init the positions
349
+ * *"Timeout"* : Set the "Timeout occured" in the User Interface-log message
350
+
351
+ See Also
352
+ --------
353
+ update_status, save_scan, set_ini_positions
354
+ """
355
+ if status[0] == "Update_Status":
356
+ self.update_status(status[1], wait_time=self.wait_time)
357
+
358
+ elif status[0] == "Timeout":
359
+ self.status_widget.setText('Timeout occurred')
360
+
361
+ def update_status(self, txt, wait_time=0):
362
+ """
363
+ Show the txt message in the status bar with a delay of wait_time ms.
364
+
365
+ =============== =========== =======================
366
+ **Parameters** **Type** **Description**
367
+ *txt* string The message to show
368
+ *wait_time* int the delay of showing
369
+ *log_type* string the type of the log
370
+ =============== =========== =======================
371
+ """
372
+ try:
373
+ self.statusbar.showMessage(txt, wait_time)
374
+ logger.info(txt)
375
+ except Exception as e:
376
+ logger.exception(str(e))
377
+
378
+
379
+ class DAQ_Logging(QObject):
380
+ """
381
+
382
+ """
383
+
384
+ scan_data_tmp = Signal(OrderedDict)
385
+ status_sig = Signal(list)
386
+
387
+ def __init__(self, settings=None, logger=None, modules_manager: ModulesManager = None):
388
+
389
+ """
390
+ DAQ_Logging deal with the acquisition part of daq_scan.
391
+
392
+ See Also
393
+ --------
394
+ custom_tree.parameter_to_xml_string
395
+ """
396
+
397
+ super(QObject, self).__init__()
398
+
399
+ self.stop_logging_flag = False
400
+ self.settings = settings
401
+ self.ini_time = 0
402
+ self.ind_log = 0
403
+ self.modules_manager: ModulesManager = modules_manager
404
+ self.modules_manager.detectors_changed.connect(self.update_connect_detectors)
405
+ self.modules_manager.actuators_changed.connect(self.update_connect_actuators)
406
+ self.data_logger = logger
407
+
408
+ @Slot(list)
409
+ def queue_command(self, command):
410
+ """
411
+ Treat the queue of commands from the current command to act, between :
412
+ * *start_logging*
413
+ * *stop_acquisition*
414
+ * *set_ini_position*
415
+ * *move_stages*
416
+
417
+ =============== ============== =========================
418
+ **Parameters** **Type** **Description**
419
+ command string list the command string list
420
+ =============== ============== =========================
421
+
422
+ See Also
423
+ --------
424
+ start_logging, set_ini_positions, move_stages
425
+ """
426
+ if command[0] == "start_logging":
427
+ self.start_logging()
428
+
429
+ elif command[0] == "stop_acquisition":
430
+ self.stop_scan_flag = True
431
+ self.stop_logging()
432
+
433
+ def do_save_continuous(self, data):
434
+ """
435
+
436
+ """
437
+ try:
438
+ self.data_logger.add_data(data)
439
+ except Exception as e:
440
+ logger.exception(str(e))
441
+
442
+ def format_actuators_data(self, data_act: DataActuator):
443
+ data = DataToExport(name=data_act.name, data=[data_act])
444
+ self.do_save_continuous(data)
445
+
446
+ def connect_actuators(self, connect=True):
447
+ """Connect actuators to DAQ_Logging do_save_continuous method
448
+
449
+ Parameters
450
+ ----------
451
+ connect: bool
452
+ If True make the connection else disconnect
453
+ """
454
+ self.modules_manager.connect_actuators(connect=connect, slot=self.format_actuators_data, signal='current_value')
455
+
456
+ def update_connect_actuators(self):
457
+ try:
458
+ self.connect_actuators(False)
459
+ except:
460
+ pass
461
+ self.connect_actuators()
462
+
463
+ def connect_detectors(self, connect=True):
464
+ """Connect detectors to DAQ_Logging do_save_continuous method
465
+
466
+ Parameters
467
+ ----------
468
+ connect: bool
469
+ If True make the connection else disconnect
470
+ """
471
+ self.modules_manager.connect_detectors(connect=connect, slot=self.do_save_continuous)
472
+
473
+ def update_connect_detectors(self):
474
+ try:
475
+ self.connect_detectors(False)
476
+ except :
477
+ pass
478
+ self.connect_detectors()
479
+
480
+ def stop_logging(self):
481
+ try:
482
+ self.connect_detectors(connect=False)
483
+ self.connect_actuators(connect=False)
484
+ except Exception as e:
485
+ logger.exception(str(e))
486
+
487
+ if self.stop_logging_flag:
488
+ status = 'Data Acquisition has been stopped by user'
489
+ self.status_sig.emit(["Update_Status", status])
490
+ if self.data_logger is not None:
491
+ self.data_logger.stop_logger()
492
+
493
+ def start_logging(self):
494
+ try:
495
+ self.connect_detectors()
496
+ self.connect_actuators()
497
+ self.stop_logging_flag = False
498
+ self.status_sig.emit(["Update_Status", "Acquisition has started"])
499
+
500
+ except Exception as e:
501
+ logger.exception(str(e))
502
+
503
+
504
+ def main():
505
+ from pymodaq_gui.utils.utils import mkQApp
506
+ from pymodaq.utils.gui_utils.loader_utils import load_dashboard_with_preset
507
+
508
+ app = mkQApp('DAQLogger')
509
+ preset_file_name = config('presets', f'default_preset_for_logger')
510
+
511
+ dashboard, extension, win = load_dashboard_with_preset(preset_file_name, 'DAQLogger')
512
+
513
+ app.exec()
514
+
515
+ return dashboard, extension, win
516
+
517
+
518
+ if __name__ == '__main__':
519
+ main()
File without changes