Exemple #1
0
    def add_polygon(self, pts, col, outline='black', thickness=1.0):
        """Draw a polygon on this pixmap.

        Args:
            pts (QPointF list): polygon points
            col (QColor): fill colour
            outline (str|None): outline colour (if any)
            thickness (float): line thickness
        """
        from psyhive import qt

        if outline:
            _pen = QtGui.QPen(outline)
            _pen.setCapStyle(Qt.RoundCap)
            if thickness:
                _pen.setWidthF(thickness)
        else:
            _pen = QtGui.QPen()
            _pen.setStyle(Qt.NoPen)

        _col = qt.get_col(col)
        _brush = QtGui.QBrush(_col)
        _poly = QtGui.QPolygonF()
        for _pt in pts:
            _pt = qt.get_p(_pt)
            _poly.append(_pt)

        _pnt = HPainter()
        _pnt.begin(self)
        _pnt.setBrush(_brush)
        _pnt.setPen(_pen)
        _pnt.drawPolygon(_poly)
        _pnt.end()
Exemple #2
0
    def add_square(self, pos, size, col='black', thickness=None):
        """Draw a square.

        Args:
            pos (QPoint): square position
            size (QSize): square size
            col (str): square colour
            thickness (float): line thickness
        """
        from psyhive import qt

        _pos = qt.get_p(pos)
        _size = qt.get_size(size)
        _rect = QtCore.QRect(_pos, _size)

        _brush = QtGui.QBrush(qt.HColor(0, 0, 0, 0))
        _col = qt.get_col(col)
        _pen = QtGui.QPen(_col)
        if thickness:
            _pen.setWidthF(thickness)

        _pnt = qt.HPainter()
        _pnt.begin(self)
        _pnt.setPen(_pen)
        _pnt.setBrush(_brush)
        _pnt.drawRect(_rect)
        _pnt.end()

        return _rect
Exemple #3
0
    def set_col(self, col):
        """Set text colour of this item.

        Args:
            col (str|QColor): colour to apply
        """
        _brush = QtGui.QBrush(get_col(col))
        self.setForeground(_brush)
Exemple #4
0
    def set_col(self, col):
        """Set colour for this progress bar.

        Args:
            col (str): colour to apply
        """
        _col = get_col(col)
        _palette = QtGui.QPalette()
        _brush = QtGui.QBrush(_col)
        for _state in [QtGui.QPalette.Active, QtGui.QPalette.Inactive]:
            _palette.setBrush(_state, QtGui.QPalette.Highlight, _brush)
        self.setPalette(_palette)
Exemple #5
0
    def add_dot(self,
                pos,
                col='black',
                radius=1.0,
                outline=None,
                thickness=None,
                operation=None,
                render_hint=None):
        """Draw a circle on this pixmap.

        Args:
            pos (QPoint): centre point
            col (str): dot colour
            radius (float): dot radius
            outline (QPen): apply outline pen
            thickness (float): line thickness
            operation (str): compositing operation
            render_hint (RenderHint): add render hint
        """
        from psyhive import qt

        _pos = qt.get_p(pos)
        _col = qt.get_col(col)
        _brush = QtGui.QBrush(_col)

        # Set outline
        if thickness:
            _pen = QtGui.QPen(qt.get_col('Black'))
            _pen.setWidthF(thickness)
        elif not outline:
            _pen = QtGui.QPen(_col)
            _pen.setStyle(Qt.NoPen)
        elif isinstance(outline, QtGui.QPen):
            _pen = outline
        elif isinstance(outline, six.string_types):
            _out_col = qt.get_col(outline)
            _pen = QtGui.QPen(_out_col)
        else:
            raise ValueError(outline)

        _pnt = HPainter()
        _pnt.begin(self)
        _pnt.setBrush(_brush)
        _pnt.setPen(_pen)
        if render_hint:
            _pnt.setRenderHint(render_hint)
        _pnt.set_operation(operation)
        _pnt.drawEllipse(_pos.x() - radius,
                         _pos.y() - radius, radius * 2, radius * 2)
        _pnt.end()
Exemple #6
0
    def add_rounded_rect(self,
                         pos,
                         size,
                         col='White',
                         bevel=5,
                         anchor='TL',
                         pen=None,
                         outline=True):
        """Draw a rounded rectangle on this pixmap.

        Args:
            pos (QPoint): position
            size (QSize): rectangle size
            col (str): rectangle fill colour
            bevel (int): edge bevel
            anchor (str): position anchor point
            pen (QPen): override pen
            outline (bool): show outline

        Returns:
            (QRect): draw region
        """
        from psyhive import qt

        if isinstance(col, QtGui.QPixmap):
            _col = col
        else:
            _col = qt.get_col(col)
        _brush = QtGui.QBrush(_col)
        _rect = _get_rect(pos=pos, size=size, anchor=anchor)

        # Set pen
        _pen = None
        if pen:
            _pen = pen
        elif not outline:
            _pen = QtGui.QPen(_col)
            _pen.setStyle(Qt.NoPen)

        _pnt = qt.HPainter()
        _pnt.begin(self)
        if _pen:
            _pnt.setPen(_pen)
        _pnt.setBrush(_brush)
        _pnt.drawRoundedRect(_rect, bevel, bevel)
        _pnt.end()

        return _rect
Exemple #7
0
    def add_rect(self,
                 pos,
                 size,
                 col='white',
                 outline='black',
                 operation=None,
                 anchor='TL',
                 thickness=None):
        """Draw a rectangle on this pixmap.

        Args:
            pos (QPoint): position
            size (QSize): rectangle size
            col (str): rectangle colour
            outline (str): outline colour
            operation (str): overlay mode
            anchor (str): position anchor point
            thickness (float): line thickness
        """
        from psyhive import qt

        _col = qt.get_col(col)
        _brush = QtGui.QBrush(_col)
        _rect = _get_rect(pos=pos, size=size, anchor=anchor)

        # Set outline
        if outline:
            _pen = QtGui.QPen(outline)
        else:
            _pen = QtGui.QPen()
            _pen.setStyle(Qt.NoPen)
        if thickness:
            _pen.setWidthF(thickness)

        _pnt = HPainter()
        _pnt.begin(self)
        _pnt.set_operation(operation)
        _pnt.setPen(_pen)
        _pnt.setBrush(_brush)
        _pnt.drawRect(_rect)
        _pnt.end()

        return _rect
Exemple #8
0
    def __init__(self, text=None, col=None, data=None):
        """Constructor.

        Args:
            text (str): display text
            col (str): text colour
            data (any): data to store with item
        """
        self._col = col or self._col
        super(HTreeWidgetItem, self).__init__()

        if text and isinstance(text, six.string_types):
            self.setText(0, text)

        if self._col:
            _brush = QtGui.QBrush(get_col(self._col))
            self.setForeground(0, _brush)
        if data:
            self.setData(0, Qt.UserRole, data)
Exemple #9
0
    def add_path(self, pts, col='black', thickness=None, pen=None):
        """Draw a path on this pixmap.

        Args:
            pts (QPoint list): list of points in path
            col (str): path colour
            thickness (float): line thickness
            pen (QPen): override pen (ignores all other pen attrs)
        """
        from psyhive import qt

        # Set pen
        if pen:
            _pen = pen
        else:
            _col = qt.get_col(col)
            _pen = pen or QtGui.QPen(_col)
            _pen.setCapStyle(Qt.RoundCap)
            if thickness:
                _pen.setWidthF(thickness)

        _brush = QtGui.QBrush()
        _brush.setStyle(Qt.NoBrush)

        # Make path object
        _path = QtGui.QPainterPath()
        _path.moveTo(qt.get_p(pts[0]))
        for _pt in pts[1:]:
            _path.lineTo(qt.get_p(_pt))

        _pnt = HPainter()
        _pnt.begin(self)
        _pnt.setPen(_pen)
        _pnt.setBrush(_brush)
        _pnt.drawPath(_path)
        _pnt.end()
Exemple #10
0
def set_maya_palette():
    """Apply maya palette.

    This allows interfaces outside maya to use the same colouring.
    """
    _base_palette = QtGui.QPalette()

    _base_palette.setBrush(QtGui.QPalette.Window, QtGui.QBrush(MID_COLOR))
    _base_palette.setBrush(QtGui.QPalette.WindowText, QtGui.QBrush(TEXT_COLOR))
    _base_palette.setBrush(QtGui.QPalette.Foreground,
                           QtGui.QBrush(BRIGHT_COLOR))
    _base_palette.setBrush(QtGui.QPalette.Base, QtGui.QBrush(DARK_COLOR))
    _base_palette.setBrush(QtGui.QPalette.AlternateBase,
                           QtGui.QBrush(ALTERNATE_BASE_COLOR))
    _base_palette.setBrush(QtGui.QPalette.ToolTipBase,
                           QtGui.QBrush(BASE_COLOR))
    _base_palette.setBrush(QtGui.QPalette.ToolTipText,
                           QtGui.QBrush(TEXT_COLOR))

    _base_palette.setBrush(QtGui.QPalette.Text, QtGui.QBrush(TEXT_COLOR))
    _base_palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Text,
                           QtGui.QBrush(DISABLED_TEXT_COLOR))

    _base_palette.setBrush(QtGui.QPalette.Button, QtGui.QBrush(LIGHT_COLOR))
    _base_palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Button,
                           QtGui.QBrush(DISABLED_BUTTON_COLOR))
    _base_palette.setBrush(QtGui.QPalette.ButtonText, QtGui.QBrush(TEXT_COLOR))
    _base_palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.ButtonText,
                           QtGui.QBrush(DISABLED_TEXT_COLOR))
    _base_palette.setBrush(QtGui.QPalette.BrightText, QtGui.QBrush(TEXT_COLOR))
    _base_palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.BrightText,
                           QtGui.QBrush(DISABLED_TEXT_COLOR))

    _base_palette.setBrush(QtGui.QPalette.Light, QtGui.QBrush(LIGHT_COLOR))
    _base_palette.setBrush(QtGui.QPalette.Midlight,
                           QtGui.QBrush(MID_LIGHT_COLOR))
    _base_palette.setBrush(QtGui.QPalette.Mid, QtGui.QBrush(MID_COLOR))
    _base_palette.setBrush(QtGui.QPalette.Dark, QtGui.QBrush(DARK_COLOR))
    _base_palette.setBrush(QtGui.QPalette.Shadow, QtGui.QBrush(SHADOW_COLOR))

    _base_palette.setBrush(QtGui.QPalette.Highlight,
                           QtGui.QBrush(HIGHLIGHT_COLOR))
    _base_palette.setBrush(QtGui.QPalette.HighlightedText,
                           QtGui.QBrush(HIGHLIGHTEDTEXT_COLOR))

    # Setup additional palettes for QTabBar and QTabWidget to look more like
    # maya.
    _tab_palette = QtGui.QPalette(_base_palette)
    _tab_palette.setBrush(QtGui.QPalette.Window, QtGui.QBrush(LIGHT_COLOR))
    _tab_palette.setBrush(QtGui.QPalette.Button, QtGui.QBrush(MID_COLOR))

    _widget_palettes = {}
    _widget_palettes["QTabBar"] = _tab_palette
    _widget_palettes["QTabWidget"] = _tab_palette

    QtWidgets.QApplication.setStyle("Plastique")
    QtWidgets.QApplication.setPalette(_base_palette)
    for _name, _palette in _widget_palettes.items():
        QtWidgets.QApplication.setPalette(_palette, _name)