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_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 #3
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 #4
0
    def add_circle(self,
                   pos,
                   col='black',
                   radius=10,
                   thickness=None,
                   operation=None,
                   pen=None):
        """Draw a circle on this pixmap.

        Args:
            pos (QPoint): centre point
            col (str): line colour
            radius (int): circle radius
            thickness (float): line thickness
            operation (str): compositing operation
            pen (QPen): override pen
        """
        from psyhive import qt

        _pos = qt.get_p(pos)
        _col = qt.get_col(col)
        _pen = pen or QtGui.QPen(_col)
        if thickness:
            _pen.setWidthF(thickness)
        _rect = QtCore.QRect(_pos.x() - radius,
                             _pos.y() - radius, radius * 2, radius * 2)

        _pnt = HPainter()
        _pnt.begin(self)
        _pnt.set_operation(operation)
        _pnt.setPen(_pen)
        _pnt.drawArc(_rect, 0, 360 * 16)
        _pnt.end()

        return _rect
Exemple #5
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 #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_line(self,
                 pt1,
                 pt2,
                 col='black',
                 thickness=None,
                 operation=None,
                 pen=None,
                 verbose=0):
        """Draw a straight line on this pixmap.

        Args:
            pt1 (QPoint): start point
            pt2 (QPoint): end point
            col (str): line colour
            thickness (float): line thickness
            operation (str): compositing operation
            pen (QPen): override pen (ignores all other pen attrs)
            verbose (int): print process data
        """
        from psyhive import qt

        _pt1 = qt.get_p(pt1)
        _pt2 = qt.get_p(pt2)

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

            lprint("COL", _col, verbose=verbose)

        _pnt = HPainter()
        _pnt.begin(self)
        _pnt.setPen(_pen)
        _pnt.set_operation(operation)
        _pnt.drawLine(_pt1.x(), _pt1.y(), _pt2.x(), _pt2.y())
        _pnt.end()
Exemple #8
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()