Esempio n. 1
0
    def __init__(self, name, ui=None, terminals={}, **kwargs):
        super().__init__(name=name, terminals=terminals, **kwargs)
        self.widget = None
        self.geometry = None

        if ui is None:
            if hasattr(self, 'uiTemplate'):
                ui = self.uiTemplate
            else:
                ui = []

        self.ui, self.stateGroup, self.ctrls, self.values = generateUi(ui)
        if self.stateGroup:
            self.stateGroup.sigChanged.connect(self.state_changed)
Esempio n. 2
0
    def add_channel(self, name=None):
        channel = len(self.channel_groups)

        if not name:
            name = f"Channel {channel}"

        channel_group = [('channel', 'text', {
            'values': f'Channel {channel}',
            'group': name
        }), ('delay', 'doubleSpin', {
            'group': name
        }), ('fraction', 'doubleSpin', {
            'group': name
        }), ('offset', 'doubleSpin', {
            'group': name
        }),
                         ('polarity', 'combo', {
                             'values': ["Negative", "Positive"],
                             'group': name
                         }), ('sample_interval', 'doubleSpin', {
                             'group': name
                         }), ('threshold', 'doubleSpin', {
                             'group': name
                         }), ('timerange_low', 'doubleSpin', {
                             'group': name
                         }), ('timerange_high', 'doubleSpin', {
                             'group': name
                         }), ('walk', 'doubleSpin', {
                             'group': name
                         })]

        self.channel_groups[name] = generateUi(channel_group)
        ui, stateGroup, ctrls, attrs = self.channel_groups[name]
        self.values[name] = attrs[name]

        self.layout.addWidget(ui)
        stateGroup.sigChanged.connect(self.state_changed)

        self.from_channel.addItem(name)
        self.to_channel.addItem(name)

        return ui, stateGroup, ctrls, attrs
Esempio n. 3
0
    def __init__(self,
                 topics=None,
                 terms=None,
                 addr=None,
                 uiTemplate=None,
                 parent=None,
                 **kwargs):
        super().__init__(parent)
        self.node = kwargs.get('node', None)
        self.units = kwargs.get('units', {})

        self.fetcher = None
        if addr:
            self.fetcher = AsyncFetcher(topics, terms, addr, parent=self)
            self.fetcher.start()

        self.plot_view = self.addPlot()
        if self.node:
            # node is passed in on subprocess
            self.viewbox_proxy = pg.SignalProxy(
                self.plot_view.vb.sigRangeChangedManually,
                delay=0.5,
                slot=lambda args: self.node.sigStateChanged.emit(self.node))
            self.plot_view.autoBtn.clicked.connect(
                lambda args: self.node.sigStateChanged.emit(self.node))

        self.plot_view.showGrid(True, True)

        ax = self.plot_view.getAxis('bottom')
        ax.enableAutoSIPrefix(enable=bool(self.units))
        ax.setZValue(100)

        ay = self.plot_view.getAxis('left')
        ay.enableAutoSIPrefix(enable=bool(self.units))
        ay.setZValue(100)

        self.plot_view.setMenuEnabled(False)

        self.configure_btn = pg.ButtonItem(pg.pixmaps.getPixmap('ctrl'),
                                           14,
                                           parentItem=self.plot_view)
        self.configure_btn.clicked.connect(self.configure_plot)
        self.configure_btn.show()

        self.plot = {}  # { name : PlotDataItem }
        self.trace_ids = {}  # { trace_idx : name }
        self.trace_attrs = {}
        self.legend_editors = {}
        self.annotation_editors = {}
        self.annotation_traces = {}

        self.terms = terms

        self.last_updated = pg.LabelItem(parent=self.plot_view)
        self.pixel_value = pg.LabelItem(parent=self.plot_view)
        self.hover_proxy = pg.SignalProxy(self.sceneObj.sigMouseMoved,
                                          rateLimit=30,
                                          slot=self.cursor_hover_evt)

        if uiTemplate is None:
            uiTemplate = [
                ('Title', 'text'),
                ('Show Grid', 'check', {
                    'checked': True
                }),
                # ('Auto Range', 'check', {'checked': True}),
                # x axis
                ('Label', 'text', {
                    'group': 'X Axis'
                }),
                ('Log Scale', 'check', {
                    'group': 'X Axis',
                    'checked': False
                }),
                # y axis
                ('Label', 'text', {
                    'group': 'Y Axis'
                }),
                ('Log Scale', 'check', {
                    'group': 'Y Axis',
                    'checked': False
                })
            ]

        self.uiTemplate = uiTemplate
        self.ui, self.stateGroup, self.ctrls, self.plot_attrs = generateUi(
            self.uiTemplate)

        if self.stateGroup:
            self.stateGroup.sigChanged.connect(self.state_changed)

        ctrl_layout = self.ui.layout()

        self.legend = None
        if kwargs.get('legend', True):
            self.legend = self.plot_view.addLegend()
            self.legend_layout = QtGui.QFormLayout()

            self.legend_groupbox = QtWidgets.QGroupBox()
            self.legend_groupbox.setTitle("Legend")
            self.legend_groupbox.setLayout(self.legend_layout)
            ctrl_layout.addWidget(self.legend_groupbox)
            self.ctrls["Legend"] = self.legend_groupbox

        self.annotation_layout = QtGui.QFormLayout()
        self.annotation_groupbox = QtWidgets.QGroupBox()
        self.annotation_groupbox.setTitle("Annotations")
        self.annotation_groupbox.setLayout(self.annotation_layout)
        ctrl_layout.addWidget(self.annotation_groupbox)
        self.ctrls["Annotations"] = self.annotation_groupbox

        self.annotation_type = QtGui.QComboBox(parent=self.annotation_groupbox)
        self.annotation_type.addItem("Line", LineEditor)
        self.annotation_type.addItem("Circle", CircleEditor)
        self.annotation_type.addItem("Rect", RectEditor)
        self.annotation_layout.addWidget(self.annotation_type)

        self.add_annotation_btn = QtWidgets.QPushButton(
            "Add", self.annotation_groupbox)
        self.add_annotation_btn.clicked.connect(self.add_annotation)
        self.annotation_layout.addWidget(self.add_annotation_btn)

        self.apply_btn = QtWidgets.QPushButton("Apply", self.ui)
        self.apply_btn.clicked.connect(self.apply_clicked)
        ctrl_layout.addWidget(self.apply_btn)

        self.win = QtGui.QMainWindow()
        scrollArea = QtWidgets.QScrollArea(parent=self.win)
        scrollArea.setWidgetResizable(True)
        scrollArea.setWidget(self.ui)
        self.win.setCentralWidget(scrollArea)
        if self.node:
            self.win.setWindowTitle(self.node.name() + ' configuration')
Esempio n. 4
0
    def __init__(self, parent=None):
        super().__init__(parent)

        self.uiTemplate = [("num hits", "intSpin", {
            "value": 1,
            "min": 1
        }), ("uniform parameters", "check"), ("DLD", "check"),
                           ("cfd_wfbinbeg", "intSpin", {
                               "value": 0,
                               "min": 0
                           }),
                           ("cfd_wfbinend", "intSpin", {
                               "value": 1,
                               "min": 1
                           })]

        self.ui, self.stateGroup, self.ctrls, self.values = generateUi(
            self.uiTemplate)
        self.stateGroup.sigChanged.connect(self.state_changed)

        self.layout = QtGui.QFormLayout()
        self.setLayout(self.layout)

        self.layout.addRow(self.ui)

        addBtn = QtWidgets.QPushButton("Add", parent=self)
        addBtn.clicked.connect(self.add_channel)

        removeBtn = QtWidgets.QPushButton("Remove", parent=self)
        removeBtn.clicked.connect(self.remove_channel)

        hbox = QtWidgets.QHBoxLayout()
        hbox.addWidget(addBtn)
        hbox.addWidget(removeBtn)
        self.layout.addRow(hbox)

        hbox = QtWidgets.QHBoxLayout()
        hbox.addWidget(QtWidgets.QLabel("Copy", parent=self))

        params = [
            'all parameters', 'channel', 'delay', 'fraction', 'offset',
            'polarity', 'sample_interval', 'threshold', 'timerange_high',
            'timerange_low', 'walk'
        ]

        self.copy_param = QtWidgets.QComboBox()
        for p in params:
            self.copy_param.addItem(p)

        hbox.addWidget(self.copy_param)
        hbox.addWidget(QtWidgets.QLabel("from", parent=self))

        self.from_channel = QtWidgets.QComboBox(parent=self)
        hbox.addWidget(self.from_channel)

        hbox.addWidget(QtWidgets.QLabel("to", parent=self))
        self.to_channel = QtWidgets.QComboBox(parent=self)
        hbox.addWidget(self.to_channel)

        copyBtn = QtWidgets.QPushButton("Copy", parent=self)
        copyBtn.clicked.connect(self.copy_channel)
        hbox.addWidget(copyBtn)

        self.layout.addRow(hbox)

        self.channel_groups = {}
        self.add_channel()
Esempio n. 5
0
    def __init__(self, node=None, parent=None, **kwargs):
        super().__init__(parent)

        if 'uiTemplate' in kwargs:
            self.uiTemplate = kwargs.pop('uiTemplate')
        else:
            self.uiTemplate = [
                # Point
                ('symbol', 'combo', {
                    'values': [
                        'o', 't', 't1', 't2', 't3', 's', 'p', 'h', 'star', '+',
                        'd', 'None'
                    ],
                    'value':
                    kwargs.get('symbol', 'o'),
                    'group':
                    'Point'
                }),
                ('Brush', 'color', {
                    'value': kwargs.get('color', (0, 0, 255)),
                    'group': 'Point'
                }),
                ('Size', 'intSpin', {
                    'min': 1,
                    'value': 14,
                    'group': 'Point'
                }),
                # Line
                ('color', 'color', {
                    'group': 'Line',
                    'value': kwargs.get('line_color', (255, 255, 255))
                }),
                ('width', 'intSpin', {
                    'min': 1,
                    'value': 1,
                    'group': 'Line'
                }),
                ('style', 'combo', {
                    'values': line_styles.keys(),
                    'value': kwargs.get('style', 'Solid'),
                    'group': 'Line'
                })
            ]

        self.ui, self.stateGroup, self.ctrls, self.trace_attrs = generateUi(
            self.uiTemplate)

        if self.stateGroup:
            self.stateGroup.sigChanged.connect(self.state_changed)

        self.node = node

        self.layout = QtGui.QGridLayout()
        self.setLayout(self.layout)

        self.layout.addWidget(self.ui, 0, 0, -1, 2)
        self.layout.setRowStretch(0, 1)
        self.layout.setColumnStretch(0, 1)

        self.plot_widget = pg.GraphicsLayoutWidget()
        self.plot_widget.setFixedSize(200, 100)

        self.plot_view = self.plot_widget.addPlot()
        self.plot_view.setMenuEnabled(False)
        # self.plot_view.addLegend()

        ax = self.plot_view.getAxis('bottom')
        ay = self.plot_view.getAxis('left')
        self.plot_view.vb.removeItem(ax)
        self.plot_view.vb.removeItem(ay)
        self.plot_view.vb.setMouseEnabled(False, False)

        self.trace = None
        self.attrs = None
        self.update_plot()

        self.layout.addWidget(self.plot_widget, 0, 2, -1, -1)