Esempio n. 1
0
    def update_darkmode(self):

        # get colors
        bg_color = self.palette().color(QtGui.QPalette.Base)
        bg_color_rgb = [bg_color.red(), bg_color.green(), bg_color.blue()]
        font_color = self.palette().color(QtGui.QPalette.Text)
        font_color_rgb = [
            font_color.red(),
            font_color.green(),
            font_color.blue()
        ]

        # set bg colors
        self.setBackground(None)  # reload background
        self.p.vb.setBackgroundColor(bg_color_rgb)
        self.legend.opts["brush"] = fn.mkBrush(bg_color_rgb)

        # change label colors
        for pos in ["bottom", "left", "top", "right"]:
            ax = self.p.getAxis(pos)
            try:
                ax.setTextPen(font_color_rgb)
            except AttributeError:
                pass

        self.x_axis.setTextPen(font_color_rgb)
        self.y_axis.setTextPen(font_color_rgb)
        self.legend.opts["labelTextColor"] = fn.mkColor(font_color_rgb)
        self.p.titleLabel.item.setDefaultTextColor(fn.mkColor(font_color_rgb))

        for sample, label in self.legend.items:
            label.setAttr("color", fn.mkColor(font_color_rgb))
            label.setText(label.text)  # force redraw

        self.legend.update()
Esempio n. 2
0
 def setColor(self, color, finished=True):
     self._color = functions.mkColor(color)
     if finished:
         self.sigColorChanged.emit(self)
     else:
         self.sigColorChanging.emit(self)
     self.update()
Esempio n. 3
0
    def paint(self, p, *args):
        ''' Overrides the default implementation so as
            to draw a vertical marker.
        '''
        # draw the text
        super(LineIDMarker, self).paint(p, args)

        # Add marker. Geometry depends on the
        # text being vertical or horizontal.
        points = []
        bounding_rect = self.boundingRect()

        if self._orientation == 'vertical':
            x = bounding_rect.x()
            y = bounding_rect.y() + bounding_rect.height() / 2.

            points.append(QPointF(x, y))
            points.append(QPointF(x - 20, y))
        else:
            x = bounding_rect.x() + bounding_rect.width() / 2.
            y = bounding_rect.y() + bounding_rect.height() * 2.

            points.append(QPointF(x, y))
            points.append(QPointF(x, y - 20))

        polygon = QPolygonF(points)

        pen = QPen(QColor(functions.mkColor(self._color)))
        p.setPen(pen)
        p.drawPolygon(polygon)
Esempio n. 4
0
 def setColor(self, color, finished=True):
     self._color = functions.mkColor(color)
     if finished:
         self.sigColorChanged.emit(self)
     else:
         self.sigColorChanging.emit(self)
     self.update()
Esempio n. 5
0
 def color(self, mode='qcolor'):
     color = functions.mkColor(self._color)
     if mode == 'qcolor':
         return color
     elif mode == 'byte':
         return (color.red(), color.green(), color.blue(), color.alpha())
     elif mode == 'float':
         return (color.red()/255., color.green()/255., color.blue()/255., color.alpha()/255.)
Esempio n. 6
0
 def setColor(self, color, finished=True):
     """Sets the button's color and emits both sigColorChanged and sigColorChanging."""
     self._color = functions.mkColor(color)
     if finished:
         self.sigColorChanged.emit(self)
     else:
         self.sigColorChanging.emit(self)
     self.update()
Esempio n. 7
0
 def setColor(self, color, finished=True):
     """Sets the button's color and emits both sigColorChanged and sigColorChanging."""
     self._color = functions.mkColor(color)
     if finished:
         self.sigColorChanged.emit(self)
     else:
         self.sigColorChanging.emit(self)
     self.update()
Esempio n. 8
0
 def setLabelTextColor(self, *args, **kargs):
     """
     Sets the color of the label text.
     *pen* can be a QPen or any argument accepted by
     :func:`pyqtgraph.mkColor() <pyqtgraph.mkPen>`
     """
     self.opts['labelTextColor'] = fn.mkColor(*args, **kargs)
     for sample, label in self.items:
         label.setAttr('color', self.opts['labelTextColor'])
Esempio n. 9
0
 def color(self, mode='qcolor'):
     color = functions.mkColor(self._color)
     if mode == 'qcolor':
         return color
     elif mode == 'byte':
         return (color.red(), color.green(), color.blue(), color.alpha())
     elif mode == 'float':
         return (color.red() / 255., color.green() / 255.,
                 color.blue() / 255., color.alpha() / 255.)
Esempio n. 10
0
    def __init__(self, text, plot_item, color=(0,0,0), orientation='horizontal'):

        self._plot_item = plot_item
        self._orientation = orientation
        self._color = functions.mkColor(color)

        anchor = orientations[orientation]['anchor']
        angle = orientations[orientation]['angle']

        super(LineIDMarker, self).__init__(text=text, color=color, anchor=anchor, angle=angle)
Esempio n. 11
0
    def __init__(self, name, opts):
        self.fieldName = name
        vals = opts.get('values', [])
        if isinstance(vals, list):
            vals = OrderedDict([(v, str(v)) for v in vals])
        # childs = [{'name': v, 'type': 'group', 'children': [
        #             {'name': 'Symbol', 'type': 'list', 'values':['o', 's', 't', 't1', '+', 'd'], 'value': 'o'},
        #             {'name': 'Symbol size', 'type': 'int', 'value': 10},
        #             {'name': 'Symbol pen', 'type': 'group', 'expanded': False, 'children': [
        #                 {'name': 'Color', 'type': 'color', 'value': fn.mkColor('w')},
        #                 {'name': 'Width', 'type': 'float', 'value': 1.0},
        #             ]}
        # ]} for v in vals]

        childs = []
        for val, vname in vals.items():
            ch = ptree.Parameter.create(
                name=vname,
                type='bool',
                value=False,
                children=[
                    dict(name='Symbol',
                         type='list',
                         values=['o', 's', 't', 't1', '+', 'd'],
                         value='o'),
                    dict(name='Symbol size', type='int', value=10),
                    dict(name='Symbol pen',
                         type='group',
                         expanded=False,
                         children=[
                             dict(name='Color',
                                  type='color',
                                  value=fn.mkColor('w')),
                             dict(name='Width', type='float', value=1.0),
                         ])
                ])
            ch.maskValue = val
            childs.append(ch)

        ptree.types.SimpleParameter.__init__(self,
                                             name=name,
                                             autoIncrementName=True,
                                             removable=True,
                                             renamable=True,
                                             type='bool',
                                             value=True,
                                             children=childs)
Esempio n. 12
0
    def update_darkmode(self):

        dark = isDarkWindow()

        # get font color
        font_color = self.palette().color(QtGui.QPalette.Text)
        font_color_rgb = [font_color.red(), font_color.green(), font_color.blue()]

        # set colors
        for p in [self.p0, self.p1]:
            p.vb.setBackgroundColor("k" if dark else "w")
            for pos in ["bottom", "left", "top", "right"]:
                ax = p.getAxis(pos)
                ax.setTextPen(fn.mkColor(font_color_rgb))  # black text

        c = LINE_COLOR_DARK if dark else LINE_COLOR_LIGHT
        self.p1.getAxis("top").setPen(width=self.LW * 2 / 3, color=c)
Esempio n. 13
0
    def update_darkmode(self):

        # get colors
        bg_color = self.palette().color(QtGui.QPalette.Base)
        bg_color_rgb = [bg_color.red(), bg_color.green(), bg_color.blue()]
        font_color = self.palette().color(QtGui.QPalette.Text)
        font_color_rgb = [font_color.red(), font_color.green(), font_color.blue()]

        # set colors
        self.setBackground(None)
        for p in [self.p0, self.p1]:
            p.vb.setBackgroundColor(bg_color_rgb)
            for pos in ['bottom', 'left', 'top', 'right']:
                ax = p.getAxis(pos)
                ax.setTextPen(fn.mkColor(font_color_rgb))  # black text

        c = LINE_COLOR_DARK if isDarkWindow() else LINE_COLOR_LIGHT
        self.p1.getAxis('top').setPen(width=self.LW*2/3, color=c)
Esempio n. 14
0
    def paint(self, p, *args):
        """
        Overrides the default implementation so as
        to draw a vertical marker below the text.
        """
        # draw the text first.
        #
        # Note that this actually doesn't work. Commenting out this call to
        # the base class doesn't prevent the text to be painted on screen
        # regardless. Tests with the base class itself prove that the base
        # class paint() is not responsible for painting the text. Even when
        # the base class' code in its paint() method is replaced by a sole
        # 'pass' statement, the text still shows up on the plot. Thus there is
        # something else in either pyqtgraph or pyqt that paints the text even
        # though the entire painting mechanism in the classes is disabled.
        super(LineIDMarker, self).paint(p, args)

        # Add marker. Geometry depends on the
        # text being vertical or horizontal.
        points = []

        # get the text-only bounding rectangle.
        bounding_rect = super(LineIDMarker, self).boundingRect()

        if self._orientation == 'vertical':
            x = bounding_rect.x()
            y = bounding_rect.y() + bounding_rect.height() / 2.

            points.append(QPointF(x, y))
            points.append(QPointF(x - 20, y))
        else:
            x = bounding_rect.x() + bounding_rect.width() / 2.
            y = bounding_rect.y() + bounding_rect.height() * 2.

            points.append(QPointF(x, y))
            points.append(QPointF(x, y - 20))

        polygon = QPolygonF(points)

        pen = QPen(QColor(functions.mkColor(self._color)))
        p.setPen(pen)
        p.drawPolygon(polygon)
Esempio n. 15
0
    def paint(self, p, *args):
        """
        Overrides the default implementation so as
        to draw a vertical marker below the text.
        """
        # draw the text first.
        #
        # Note that this actually doesn't work. Commenting out this call to
        # the base class doesn't prevent the text to be painted on screen
        # regardless. Tests with the base class itself prove that the base
        # class paint() is not responsible for painting the text. Even when
        # the base class' code in its paint() method is replaced by a sole
        # 'pass' statement, the text still shows up on the plot. Thus there is
        # something else in either pyqtgraph or pyqt that paints the text even
        # though the entire painting mechanism in the classes is disabled.
        super(LineIDMarker, self).paint(p, args)

        # Add marker. Geometry depends on the
        # text being vertical or horizontal.
        points = []

        # get the text-only bounding rectangle.
        bounding_rect = super(LineIDMarker, self).boundingRect()

        if self._orientation == 'vertical':
            x = bounding_rect.x()
            y = bounding_rect.y() + bounding_rect.height() / 2.

            points.append(QPointF(x, y))
            points.append(QPointF(x - 20, y))
        else:
            x = bounding_rect.x() + bounding_rect.width() / 2.
            y = bounding_rect.y() + bounding_rect.height() * 2.

            points.append(QPointF(x, y))
            points.append(QPointF(x, y - 20))

        polygon = QPolygonF(points)

        pen = QPen(QColor(functions.mkColor(self._color)))
        p.setPen(pen)
        p.drawPolygon(polygon)
Esempio n. 16
0
 def __init__(self, name, opts):
     self.fieldName = name
     units = opts.get('units', '')
     ptree.types.SimpleParameter.__init__(
         self,
         name=name,
         autoIncrementName=True,
         removable=True,
         renamable=True,
         type='bool',
         value=True,
         children=[
             #dict(name="Field", type='list', value=name, values=fields),
             dict(name='Min',
                  type='float',
                  value=0.0,
                  suffix=units,
                  siPrefix=True),
             dict(name='Max',
                  type='float',
                  value=1.0,
                  suffix=units,
                  siPrefix=True),
             dict(name='Symbol',
                  type='list',
                  values=['o', 's', 't', 't1', '+', 'd'],
                  value='o'),
             dict(name='Symbol size', type='int', value=10),
             dict(name='Symbol pen',
                  type='group',
                  expanded=False,
                  children=[
                      dict(name='Color',
                           type='color',
                           value=fn.mkColor('w')),
                      dict(name='Width', type='float', value=1.0),
                  ])
         ])
Esempio n. 17
0
    def setTitle(self, text, fontScaling=None, color=None, font=None):
        # work around pyqtplot which forces the title to be HTML
        if text is None:
            self.p.setTitle(None)  # clears title and hides title column
        else:
            self.p.setTitle(
                '')  # makes title column visible, sets placeholder text
            self.p.titleLabel.item.setPlainText(
                text)  # replace HTML with plain text

        if color is not None:
            color = fn.mkColor(color)
            self.p.titleLabel.item.setDefaultTextColor(color)

        if font is not None:
            self.p.titleLabel.item.setFont(font)

        if fontScaling is not None:
            font = self.p.titleLabel.item.font()
            defaultFontSize = QtWidgets.QLabel('test').font().pointSize()
            fontSize = round(defaultFontSize * fontScaling, 1)
            font.setPointSize(fontSize)
            self.p.titleLabel.item.setFont(font)
Esempio n. 18
0
    def setData(self, **kwds):
        """
        Update the data displayed by this item. All arguments are optional;
        for example it is allowed to update text while leaving colors unchanged, etc.

        ====================  ==================================================
        **Arguments:**
        ------------------------------------------------------------------------
        pos                   (3,) array of floats specifying text location.
        color                 QColor or array of ints [R,G,B] or [R,G,B,A]. (Default: Qt.white)
        text                  String to display.
        font                  QFont (Default: QFont('Helvetica', 16))
        ====================  ==================================================
        """
        args = ['pos', 'color', 'text', 'font']
        for k in kwds.keys():
            if k not in args:
                raise ArgumentError(
                    'Invalid keyword argument: %s (allowed arguments are %s)' %
                    (k, str(args)))
        for arg in args:
            if arg in kwds:
                value = kwds[arg]
                if arg == 'pos':
                    if isinstance(value, np.ndarray):
                        if value.shape != (3, ):
                            raise ValueError('"pos.shape" must be (3,).')
                    elif isinstance(value, (tuple, list)):
                        if len(value) != 3:
                            raise ValueError('"len(pos)" must be 3.')
                elif arg == 'color':
                    value = fn.mkColor(value)
                elif arg == 'font':
                    if isinstance(value, QtGui.QFont) is False:
                        raise TypeError('"font" must be QFont.')
                setattr(self, arg, value)
        self.update()
Esempio n. 19
0
    def setText(self, text, **args):
        """Set the text and text properties in the label. Accepts optional arguments for auto-generating
        a CSS style string:

        ==================== ==============================
        **Style Arguments:**
        color                (str) example: 'CCFF00'
        size                 (str) example: '8pt'
        bold                 (bool)
        italic               (bool)
        ==================== ==============================
        """
        self.text = text
        opts = self.opts
        for k in args:
            opts[k] = args[k]
        
        optlist = []
        
        color = self.opts['color']
        if color is None:
            color = pg.getConfigOption('foreground')
        color = fn.mkColor(color)
        optlist.append('color: #' + fn.colorStr(color)[:6])
        if 'size' in opts:
            optlist.append('font-size: ' + opts['size'])
        if 'bold' in opts and opts['bold'] in [True, False]:
            optlist.append('font-weight: ' + {True:'bold', False:'normal'}[opts['bold']])
        if 'italic' in opts and opts['italic'] in [True, False]:
            optlist.append('font-style: ' + {True:'italic', False:'normal'}[opts['italic']])
        full = "<span style='%s'>%s</span>" % ('; '.join(optlist), text)
        #print full
        self.item.setHtml(full)
        self.updateMin()
        self.resizeEvent(None)
        self.updateGeometry()
Esempio n. 20
0
 def color(self):
     return functions.mkColor(self._color)
Esempio n. 21
0
 def colorValue(self):
     return fn.mkColor(Parameter.value(self))
Esempio n. 22
0
 def color(self):
     return functions.mkColor(self._color)
Esempio n. 23
0
 def colorValue(self):
     return fn.mkColor(Parameter.value(self))
Esempio n. 24
0
    def __init__(self, parent=None):
        super(ScatterPlotWidget, self).__init__(self)
        self._hidden = True

        bg = fn.mkColor(getConfigOption('background'))
        bg.setAlpha(255)  # we need to do that, since in default widget alpha is set to 50, but we want it BLACK!