示例#1
0
 def addPlugins(self):
     self.btns = {}
     for plugin in plugins:
         b = pg.ButtonItem(icons.getIcon(plugin.iconName),
                           width=14,
                           parentItem=self)
         b.clicked.connect(partial(self.setPluginVisible, plugin.name))
         self.btns[plugin.name] = b
示例#2
0
 def __init__(self,
              orientation,
              pen=None,
              linkView=None,
              parent=None,
              maxTickLength=-5,
              showValues=True):
     # Note - development branch of pyqtgraph adds extra argument textPen here.
     pg.AxisItem.__init__(self, orientation, pen, None, linkView, parent,
                          maxTickLength, showValues)
     self.set_lmt_btns = []
     self.aset_lmt_btns = []
     path = os.path.dirname(os.path.abspath(__file__))
     self.autorange_toggle_off_pixmap = QtGui.QPixmap(
         os.path.join(path, 'autorange_toggle_off.png'))
     self.autorange_toggle_on_pixmap = QtGui.QPixmap(
         os.path.join(path, 'autorange_toggle_on.png'))
     for type in range(2):
         # set limit button
         btn = pg.ButtonItem(
             QtGui.QPixmap(os.path.join(path, 'ellipsis.png')), 14, self)
         btn.setZValue(-1000)
         btn.setFlag(btn.ItemNegativeZStacksBehindParent)
         btn.clicked.connect(partial(self.set_lmt_btn_clicked,
                                     type))  # late binding if function used
         self.set_lmt_btns.append(btn)
         # autoset limit button
         btn = pg.ButtonItem(pg.pixmaps.getPixmap('auto'), 14, self)
         btn.setZValue(-1000)
         btn.setFlag(btn.ItemNegativeZStacksBehindParent)
         btn.clicked.connect(partial(self.aset_lmt_btn_clicked,
                                     type))  # late binding if function used
         self.aset_lmt_btns.append(btn)
     # enable autorange button
     btn = pg.ButtonItem(self.autorange_toggle_off_pixmap, 14, self)
     btn.setZValue(-1000)
     btn.setFlag(btn.ItemNegativeZStacksBehindParent)
     btn.clicked.connect(self.enable_auto_range_btn_clicked
                         )  # late binding if function used
     self.enable_auto_range_btn = btn
     self.mouseHovering = False
     self.buttons_enabled = True
     self.updateButtons()
示例#3
0
    def addCursors(self, hasPlugins):
        if hasPlugins:
            # if we have no plugins, the cursor btn is part of a different plot widget
            self.cursBtn = pg.ButtonItem(icons.getIcon("cursor"),
                                         width=14,
                                         parentItem=self)

        self.c1 = RelPosCursor(1 / 3, label="C1")
        self.c2 = RelPosCursor(2 / 3, label="C2")
        self.addItem(self.c1)
        self.addItem(self.c2)
        self.cursors = dict(
            (idx, c) for idx, c in enumerate([self.c1, self.c2]))
        self.proxies = [
            pg.SignalProxy(c.sigPositionChanged,
                           rateLimit=30,
                           slot=self.updateCursorVals)
            for c in self.cursors.values()
        ]
        for k, v in self.cursors.items():
            v.idx = k
        if hasPlugins:
            self.cursBtn.clicked.connect(self.setCursorsVisible)
        self.cursorVisChanged.connect(self.toggleCursorVis)
示例#4
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')
示例#5
0
    def __init__(self, parent=None, mode='bar', curve=False):
        self.parent = parent
        pg.GraphicsWidget.__init__(self)
        self.buttons = {}

        if mode == 'bar':
            self.buttons['lock'] = pg.ButtonItem(pg.pixmaps.getPixmap('lock'),
                                                 14, self)
            self.buttons['lock'].setPos(0, 0)
            self.buttons['lock'].setOpacity(0.4)
            self.buttons['del'] = pg.ButtonItem(pg.pixmaps.getPixmap('del'),
                                                14, self)
            self.buttons['del'].setPos(20, 0)
            self.buttons['del'].setOpacity(1)
            self.buttons['contour'] = pg.ButtonItem(
                pg.pixmaps.getPixmap('contour'), 14, self)
            self.buttons['lock'].setToolTip("lock aspect")
            self.buttons['del'].setToolTip("delete")
            self.buttons['contour'].setToolTip("select contour")
            if curve:
                self.buttons['curve'] = pg.ButtonItem(
                    pg.pixmaps.getPixmap('curve'), 14, self)
                self.buttons['curve'].setPos(40, 0)
                self.buttons['curve'].setOpacity(0.4)
                self.buttons['color'] = pg.ButtonItem(
                    pg.pixmaps.getPixmap('color'), 14, self)
                self.buttons['color'].setPos(60, 0)
                self.buttons['color'].setOpacity(0.4)
                self.buttons['contour'].setPos(80, 0)
                self.buttons['contour'].setOpacity(0.4)

                self.buttons['curve'].setToolTip("draw curve")
                self.buttons['color'].setToolTip("set draw pen")

                self.colorWidget = ColorWidegt(parent=self.parent)
                #self.colorWidget
                #self.buttons['color'].clicked.connect(self.color_clicked)
                self.colorWidget.buttons['cancel'].clicked.connect(
                    self.cancel_clicked)
            else:
                self.buttons['contour'].setPos(40, 0)
        elif mode == 'panel':
            self.buttons['lock'] = pg.ButtonItem(pg.pixmaps.getPixmap('lock'),
                                                 16, self)
            self.buttons['lock'].setPos(0, 0)
            self.buttons['lock'].setOpacity(0.4)
            self.buttons['restore'] = pg.ButtonItem(
                pg.pixmaps.getPixmap('restore'), 16, self)
            self.buttons['restore'].setPos(22, 0)
            self.buttons['restore'].setOpacity(1)
            self.buttons['tri'] = pg.ButtonItem(pg.pixmaps.getPixmap('tri'),
                                                16, self)
            self.buttons['tri'].setPos(44, 0)
            self.buttons['tri'].setOpacity(0.4)

            self.buttons['lock'].setToolTip("lock aspect")
            self.buttons['restore'].setToolTip("restore alignment")
            self.buttons['tri'].setToolTip(
                "show triangulation (only for piecewise affine)")

            pass