Debian Codegraph @

pymeasure/display/windows/managed_dock_window.py

raw
1 #
2 # This file is part of the PyMeasure package.
3 #
4 # Copyright (c) 2013-2024 PyMeasure Developers
5 #
6 # Permission is hereby granted, free of charge, to any person obtaining a copy
7 # of this software and associated documentation files (the "Software"), to deal
8 # in the Software without restriction, including without limitation the rights
9 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 # copies of the Software, and to permit persons to whom the Software is
11 # furnished to do so, subject to the following conditions:
12 #
13 # The above copyright notice and this permission notice shall be included in
14 # all copies or substantial portions of the Software.
15 #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 # THE SOFTWARE.
23 #
24
25 import logging
26
27 from ..widgets.dock_widget import DockWidget
28 from ..widgets.log_widget import LogWidget
29 from .managed_window import ManagedWindowBase
30
31 log = logging.getLogger(__name__)
32 log.addHandler(logging.NullHandler())
33
34
35 class ManagedDockWindow(ManagedWindowBase):
36 """
37 Display experiment output with multiple docking windows with
38 :class:`~pymeasure.display.widgets.dock_widget.DockWidget` class.
39
40 :param procedure_class: procedure class describing the experiment (see
41 :class:`~pymeasure.experiment.procedure.Procedure`)
42 :param x_axis: the data column(s) for the x-axis of the plot. This may be a string or a list
43 of strings from the data columns of the procedure. The list length determines the number of
44 plots
45 :param y_axis: the data column(s) for the y-axis of the plot. This may be a string or a list
46 of strings from the data columns of the procedure. The list length determines the number of
47 plots
48 :param linewidth: linewidth for the displayed curves, default is 1
49 :param log_fmt: formatting string for the log-widget
50 :param log_datefmt: formatting string for the date in the log-widget
51 :param \\**kwargs: optional keyword arguments that will be passed to
52 :class:`~pymeasure.display.windows.managed_window.ManagedWindowBase`
53 """
54
55 def __init__(self, procedure_class, x_axis=None, y_axis=None,
56 linewidth=1, log_fmt=None, log_datefmt=None, **kwargs):
57
58 self.x_axis = x_axis
59 self.y_axis = y_axis
60
61 measure_quantities = []
62 # Expand x_axis if it is a list
63 if isinstance(self.x_axis, list):
64 measure_quantities += [*self.x_axis]
65 self.x_axis_labels = self.x_axis
66 # Change x_axis to a string from list for ResultsDialog
67 self.x_axis = self.x_axis[0]
68 else:
69 self.x_axis_labels = [self.x_axis, ]
70 measure_quantities.append(self.x_axis)
71
72 # Expand y_axis if it is a list
73 if isinstance(self.y_axis, list):
74 measure_quantities += [*self.y_axis]
75 self.y_axis_labels = self.y_axis
76 # Change y_axis to a string from list for ResultsDialog
77 self.y_axis = self.y_axis[0]
78 else:
79 self.y_axis_labels = [self.y_axis, ]
80 measure_quantities.append(self.y_axis)
81
82 self.log_widget = LogWidget("Experiment Log", fmt=log_fmt, datefmt=log_datefmt)
83 self.dock_widget = DockWidget("Dock Tab", procedure_class, self.x_axis_labels,
84 self.y_axis_labels, linewidth=linewidth)
85
86 if "widget_list" not in kwargs:
87 kwargs["widget_list"] = ()
88 kwargs["widget_list"] = kwargs["widget_list"] + (self.dock_widget, self.log_widget)
89
90 super().__init__(procedure_class, **kwargs)
91
92 self.browser_widget.browser.measured_quantities.update(measure_quantities)
93
94 logging.getLogger().addHandler(self.log_widget.handler)
95 log.setLevel(self.log_level)
96 log.info("DockWindow connected to logging")