Ejemplo n.º 1
0
 def cellColor(self, index):
     r = index.row()
     c = index.column()
     color_name = self.interface.get_cell_color(r, c)
     color = QColor()
     color.setNamedColor(color_name)
     return color
Ejemplo n.º 2
0
def make_color(color):
    if isinstance(color, tuple):
        return QColor(*color)
    elif isinstance(color, str):
        return QColor(color)
    else:
        raise ValueError('Unknown color %r', color)
Ejemplo n.º 3
0
 def get_pen_color(self, key):
     if self._plot_colors is None:
         self._plot_colors = self._make_plot_cycle()
     color = self._plot_colors[key]
     if not isinstance(color, str):
         return QColor(*color)
     else:
         return QColor(color)
Ejemplo n.º 4
0
 def data(self, index, role):
     if not index.isValid():
         return
     if role == Qt.BackgroundRole:
         r = index.row()
         c = index.column()
         color_name = self.interface.get_cell_color(r, c)
         color = QColor()
         color.setNamedColor(color_name)
         return color
     elif role in (Qt.DisplayRole, Qt.EditRole):
         r = index.row()
         c = index.column()
         return self.interface._get_data(r, c)
Ejemplo n.º 5
0
    def drawBitmap(self, bmp, opt, painter):
        """ Draw the bitmap for the button.

        The bitmap will be drawn with the foreground color set by
        the style sheet and the style option.

        Parameters
        ----------
        bmp : QBitmap
            The bitmap to draw.

        opt : QStyleOption
            The style option to use for drawing.

        painter : QPainter
            The painter to use for drawing.

        """
        # hack to get the current stylesheet foreground color
        hint = QStyle.SH_GroupBox_TextLabelColor
        fg = self.style().styleHint(hint, opt, self)
        # mask signed to unsigned which 'fromRgba' requires
        painter.setPen(QColor.fromRgba(0xffffffff & fg))
        size = self.size()
        im_size = bmp.size()
        x = size.width() / 2 - im_size.width() / 2
        y = size.height() / 2 - im_size.height() / 2
        source = QRect(QPoint(0, 0), im_size)
        dest = QRect(QPoint(x, y), im_size)
        painter.drawPixmap(dest, bmp, source)
Ejemplo n.º 6
0
    def drawBitmap(self, bmp, opt, painter):
        """ Draw the bitmap for the button.

        The bitmap will be drawn with the foreground color set by
        the style sheet and the style option.

        Parameters
        ----------
        bmp : QBitmap
            The bitmap to draw.

        opt : QStyleOption
            The style option to use for drawing.

        painter : QPainter
            The painter to use for drawing.

        """
        # hack to get the current stylesheet foreground color
        hint = QStyle.SH_GroupBox_TextLabelColor
        fg = self.style().styleHint(hint, opt, self)
        # mask signed to unsigned which 'fromRgba' requires
        painter.setPen(QColor.fromRgba(0xffffffff & fg))
        size = self.size()
        im_size = bmp.size()
        x = size.width() / 2 - im_size.width() / 2
        y = size.height() / 2 - im_size.height() / 2
        source = QRect(QPoint(0, 0), im_size)
        dest = QRect(QPoint(x, y), im_size)
        painter.drawPixmap(dest, bmp, source)
Ejemplo n.º 7
0
    def data(self, index, role=Qt.DisplayRole):
        # Do nothing if the dataframe is empty
        if not index.isValid() or not (0 <= index.row() < len(self._data)):
            return None

        if role == Qt.DisplayRole:
            r = index.row()
            c = self._columns[index.column()]
            v = self._data.at[r, c]
            return str(v)
        elif role == Qt.TextAlignmentRole:
            return int(Qt.AlignRight | Qt.AlignVCenter)
        elif role == Qt.BackgroundRole:
            if self._cell_color is not None:
                r = index.row()
                c = self._columns[index.column()]
                name = self._cell_color(r, c)
                color = QColor()
                color.setNamedColor(name)
                return color
Ejemplo n.º 8
0
 def _default_plot(self):
     symbol_code = self.SYMBOL_MAP[self.symbol]
     color = QColor(self.pen_color)
     pen = pg.mkPen(color, width=self.pen_width)
     brush = pg.mkBrush(color)
     return pg.PlotDataItem(pen=pen,
                            antialias=self.antialias,
                            symbol=symbol_code,
                            symbolSize=self.symbol_size,
                            symbolPen=pen,
                            symbolBrush=brush,
                            pxMode=self.symbol_size_unit == 'screen')
    def data(self, index, role=Qt.DisplayRole):
        # Do nothing if the dataframe is empty
        if not index.isValid() or not (0 <= index.row() < len(self._data)):
            return None

        if role == Qt.DisplayRole:
            r = index.row()
            c = self._columns[index.column()]
            v = self._data.at[r, c]
            return str(v)
        elif role == Qt.TextAlignmentRole:
            return int(Qt.AlignRight | Qt.AlignVCenter)
        elif role == Qt.FontRole:
            font = QFont()
            font.setPointSize(font.pointSize()-2)
            return font
        elif role == Qt.BackgroundRole:
            if self._cell_color is not None:
                r = index.row()
                c = self._columns[index.column()]
                name = self._cell_color(r, c)
                color = QColor()
                color.setNamedColor(name)
                return color
Ejemplo n.º 10
0
 def set_background(self, background):
     """Set the background color of the widget."""
     scene = self.scene
     scene.setBackgroundBrush(QColor.fromRgba(background.argb))
 def apply_validator(self, item, label):
     if self.validator and not self.validator(label):
         item.setTextColor(QColor(255, 0, 0))
     else:
         item.setTextColor(QColor(0, 0, 0))