def catch(exprs: Sequence[str]) -> bool:
     """Detection function for solution polygons."""
     points, _ = self.solution_polygon(
         exprs[0],
         exprs[1:-1],
         exprs[-1],
         self.vpoints
     )
     if len(points) < 3:
         points = convex_hull(
             [(x + self.sr, y + self.sr) for x, y in points]
             + [(x - self.sr, y - self.sr) for x, y in points],
             as_qpoint=True
         )
     else:
         points = [QPointF(x, y) for x, y in points]
     polygon = QPolygonF(points)
     if rect:
         return polygon.intersects(
             QPolygonF(self.selector.to_rect(self.zoom)))
     else:
         return polygon.containsPoint(
             QPointF(self.selector.x, -self.selector.y) * self.zoom,
             Qt.WindingFill
         )
Exemplo n.º 2
0
def qwtDrawPanel(painter, rect, pal, lw):
    if lw > 0.0:
        if rect.width() == 0.0:
            painter.setPen(pal.window().color())
            painter.drawLine(rect.topLeft(), rect.bottomLeft())
            return
        if rect.height() == 0.0:
            painter.setPen(pal.window().color())
            painter.drawLine(rect.topLeft(), rect.topRight())
            return
        lw = min([lw, rect.height() / 2.0 - 1.0])
        lw = min([lw, rect.width() / 2.0 - 1.0])
        outerRect = rect.adjusted(0, 0, 1, 1)
        innerRect = outerRect.adjusted(lw, lw, -lw, -lw)
        lines = [QPolygonF(), QPolygonF()]
        lines[0] += outerRect.bottomLeft()
        lines[0] += outerRect.topLeft()
        lines[0] += outerRect.topRight()
        lines[0] += innerRect.topRight()
        lines[0] += innerRect.topLeft()
        lines[0] += innerRect.bottomLeft()
        lines[1] += outerRect.topRight()
        lines[1] += outerRect.bottomRight()
        lines[1] += outerRect.bottomLeft()
        lines[1] += innerRect.bottomLeft()
        lines[1] += innerRect.bottomRight()
        lines[1] += innerRect.topRight()
        painter.setPen(Qt.NoPen)
        painter.setBrush(pal.light())
        painter.drawPolygon(lines[0])
        painter.setBrush(pal.dark())
        painter.drawPolygon(lines[1])
    painter.fillRect(rect.adjusted(lw, lw, -lw + 1, -lw + 1), pal.window())
Exemplo n.º 3
0
def array2d_to_qpolygonf(xdata, ydata):
    """
    Utility function to convert two 1D-NumPy arrays representing curve data 
    (X-axis, Y-axis data) into a single polyline (QtGui.PolygonF object). 
    This feature is compatible with PyQt4, PyQt5 and PySide2 (requires QtPy).
    
    License/copyright: MIT License © Pierre Raybaut 2020.
    
    :param numpy.ndarray xdata: 1D-NumPy array (numpy.float64)
    :param numpy.ndarray ydata: 1D-NumPy array (numpy.float64)
    :return: Polyline
    :rtype: QtGui.QPolygonF
    """
    dtype = np.float
    if not (xdata.size == ydata.size == xdata.shape[0] == ydata.shape[0]
            and xdata.dtype == ydata.dtype == dtype):
        raise ValueError(
            "Arguments must be 1D, float64 NumPy arrays with same size")
    size = xdata.size
    polyline = QPolygonF(size)
    if PYSIDE2:  # PySide2 (obviously...)
        address = shiboken2.getCppPointer(polyline.data())[0]
        buffer = (ctypes.c_double * 2 * size).from_address(address)
    else:  # PyQt4, PyQt5
        buffer = polyline.data()
        buffer.setsize(2 * size * np.finfo(dtype).dtype.itemsize)
    memory = np.frombuffer(buffer, dtype)
    memory[:(size - 1) * 2 + 1:2] = xdata
    memory[1:(size - 1) * 2 + 2:2] = ydata
    return polyline
Exemplo n.º 4
0
 def mousePressEvent(self, event):
     super().mousePressEvent(event)
     if not self._roiMode:
         return
     self._appendPointToRoi(event.scenePos(), self._roiPolygon, False)
     self._roiItem.setPolygon(self._roiPolygon)
     self._tempRoiPolygon = QPolygonF(self._roiPolygon)
     self._tempRoiPolygon.append(QPointF())
Exemplo n.º 5
0
 def catch(exprs: Sequence[str]) -> bool:
     """Detection function for solution polygons."""
     points, _ = self.solution_polygon(exprs[0], exprs[1:-1],
                                       exprs[-1], self.vpoints)
     polygon = QPolygonF(points)
     if rect:
         return polygon.intersects(
             QPolygonF(self.selector.to_rect(self.zoom)))
     else:
         return polygon.containsPoint(
             QPointF(self.selector.x, self.selector.y),
             Qt.WindingFill)
Exemplo n.º 6
0
 def enableRoiMode(self, enable):
     if enable == self._roiMode:
         return
     if enable:
         self._roiPolygon = QPolygonF()
         self._roiItem.setPolygon(self._roiPolygon)
         self._tempRoiPolygon = QPolygonF(self._roiPolygon)
         self._tempRoiPolygon.append(QPointF())
     if not enable:
         self._roiItem.setPolygon(self._roiPolygon)
         self.roiChanged.emit(self._roiPolygon)
     self._roiMode = enable
     self.roiModeChanged.emit(enable)
Exemplo n.º 7
0
    def setData(self, data):

        xvals = data.coords[data.dims[-1]]
        yvals = data.coords[data.dims[-2]]
        xmin = float(xvals.min())
        xmax = float(xvals.max())
        ymin = float(yvals.min())
        ymax = float(yvals.max())

        # Position the image according to coords
        shape = data.shape
        a = [(0, shape[-1]), (shape[-2] - 1, shape[-1]), (shape[-2] - 1, 1), (0, 1)]

        # b = [(ymin, xmax), (ymax, xmax), (ymax, xmin), (ymin, xmin)]
        b = [(xmax, ymin), (xmax, ymax), (xmin, ymax), (xmin, ymin)]

        quad1 = QPolygonF()
        quad2 = QPolygonF()
        for p, q in zip(a, b):
            quad1.append(QPointF(*p))
            quad2.append(QPointF(*q))

        transform = QTransform()
        QTransform.quadToQuad(quad1, quad2, transform)

        # Bind coords from the xarray to the timeline axis
        # super(SliceableGraphicsView, self).setImage(img, autoRange, autoLevels, levels, axes, np.asarray(img.coords[img.dims[0]]), pos, scale, transform, autoHistogramRange, levelMode)
        self.image_item.setImage(np.asarray(data), autoLevels=False)
        self.image_item.setTransform(transform)

        # Label the image axes
        self.view.setLabel('left', data.dims[-2])
        self.view.setLabel('bottom', data.dims[-1])
Exemplo n.º 8
0
    def transform(self, img=None):
        if not self._geometry or not self.displaymode == DisplayMode.remesh:
            return super(EwaldCorrected, self).transform(
                img)  # Do pixel space transform when not calibrated

        from camsaxs import remesh_bbox

        img, q_x, q_z = remesh_bbox.remesh(np.squeeze(img),
                                           self._geometry,
                                           reflection=False,
                                           alphai=None)

        # Build Quads
        shape = img.shape
        a = shape[-2] - 1, 0  # bottom-left
        b = shape[-2] - 1, shape[-1] - 1  # bottom-right
        c = 0, shape[-1] - 1  # top-right
        d = 0, 0  # top-left

        quad1 = QPolygonF()
        quad2 = QPolygonF()
        for p, q in zip([a, b, c, d],
                        [a, b, c, d]):  # the zip does the flip :P
            quad1.append(QPointF(*p[::-1]))
            quad2.append(QPointF(q_x[q], q_z[q]))

        transform = QTransform()
        QTransform.quadToQuad(quad1, quad2, transform)

        for item in self.view.items:
            if isinstance(item, ImageItem):
                item.setTransform(transform)
        self._transform = transform

        return img, self._transform
Exemplo n.º 9
0
 def paintEvent(self, event: QPaintEvent):
     painter = QPainter(self)
     painter.drawImage(self.rect(), self.image)
     if self.show_frame:
         painter.save()
         pen = QPen()
         pen.setWidth(2)
         pen.setColor(QColor("black"))
         painter.setPen(pen)
         rect = QRect(1, 1, self.width() - 2, self.height() - 2)
         painter.drawRect(rect)
         pen.setColor(QColor("white"))
         painter.setPen(pen)
         rect = QRect(3, 3, self.width() - 6, self.height() - 6)
         painter.drawRect(rect)
         painter.restore()
     if self.show_arrow:
         painter.save()
         triangle = QPolygonF()
         dist = 4
         point1 = QPoint(self.width() - self.triangle_width, 0)
         size = QSize(20, self.height() // 2)
         rect = QRect(point1, size)
         painter.fillRect(rect, QColor("white"))
         triangle.append(point1 + QPoint(dist, dist))
         triangle.append(point1 + QPoint(size.width() - dist, dist))
         triangle.append(point1 + QPoint(size.width() // 2,
                                         size.height() - dist))
         painter.setBrush(Qt.black)
         painter.drawPolygon(triangle, Qt.WindingFill)
         painter.restore()
Exemplo n.º 10
0
def qwtDrawTriangleSymbols(painter, type, points, numPoint, symbol):
    size = symbol.size()
    pen = QPen(symbol.pen())
    pen.setJoinStyle(Qt.MiterJoin)
    painter.setPen(pen)
    painter.setBrush(symbol.brush())
    sw2 = 0.5 * size.width()
    sh2 = 0.5 * size.height()
    for pos in points:
        x = pos.x()
        y = pos.y()
        x1 = x - sw2
        x2 = x1 + size.width()
        y1 = y - sh2
        y2 = y1 + size.height()
        if type == QwtTriangle.Left:
            triangle = [QPointF(x2, y1), QPointF(x1, y), QPointF(x2, y2)]
        elif type == QwtTriangle.Right:
            triangle = [QPointF(x1, y1), QPointF(x2, y), QPointF(x1, y2)]
        elif type == QwtTriangle.Up:
            triangle = [QPointF(x1, y2), QPointF(x, y1), QPointF(x2, y2)]
        elif type == QwtTriangle.Down:
            triangle = [QPointF(x1, y1), QPointF(x, y2), QPointF(x2, y1)]
        else:
            raise TypeError("Unknown triangle type %s" % type)
        painter.drawPolygon(QPolygonF(triangle))
Exemplo n.º 11
0
def qwtDrawHexagonSymbols(painter, points, numPoints, symbol):
    painter.setBrush(symbol.brush())
    painter.setPen(symbol.pen())
    cos30 = np.cos(30 * np.pi / 180.0)
    dx = 0.5 * (symbol.size().width() - cos30)
    dy = 0.25 * symbol.size().height()
    for pos in points:
        x = pos.x()
        y = pos.y()
        x1 = x - dx
        y1 = y - 2 * dy
        x2 = x1 + 1 * dx
        x3 = x1 + 2 * dx
        y2 = y1 + 1 * dy
        y3 = y1 + 3 * dy
        y4 = y1 + 4 * dy
        hexa = [
            QPointF(x2, y1),
            QPointF(x3, y2),
            QPointF(x3, y3),
            QPointF(x2, y4),
            QPointF(x1, y3),
            QPointF(x1, y2),
        ]
        painter.drawPolygon(QPolygonF(hexa))
Exemplo n.º 12
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)
Exemplo n.º 13
0
 def paintEvent(self, event: QPaintEvent):
     painter = QPainter(self)
     painter.save()
     painter.setRenderHint(QPainter.Antialiasing)
     size = min(self.width(), self.height())
     rect = QRect(0, 0, size, size)
     painter.setBrush(self.background_color)
     painter.setPen(self.background_color)
     painter.drawEllipse(rect)
     painter.setBrush(self.main_color)
     painter.setPen(self.main_color)
     factor = self.nominator / self.denominator
     radius = size / 2
     if factor > 0.5:
         painter.drawChord(rect, 0, 16 * 360 * 0.5)
         painter.drawChord(rect, 16 * 180, 16 * 360 * (factor - 0.5))
         zero_point = QPointF(0, radius)
     else:
         painter.drawChord(rect, 0, 16 * 360 * factor)
         zero_point = QPointF(size, radius)
     mid_point = QPointF(radius, radius)
     point = mid_point + QPointF(
         math.cos(math.pi * (factor * 2)) * radius, -math.sin(math.pi * (factor * 2)) * radius
     )
     polygon = QPolygonF()
     polygon += mid_point
     polygon += zero_point
     polygon += point
     painter.drawPolygon(polygon)
     painter.restore()
Exemplo n.º 14
0
    def draw_solution(self, func: str, args: Sequence[str], target: str,
                      pos: Sequence[VPoint]) -> None:
        """Draw the solution triangle."""
        points, color = self.solution_polygon(func, args, target, pos)
        color.setAlpha(150)
        pen = QPen(color)
        pen.setWidth(self.joint_size)
        self.painter.setPen(pen)

        def draw_arrow(index: int, text: str) -> None:
            """Draw arrow."""
            x0, y0 = points[index]
            x1, y1 = points[-1]
            self.draw_arrow(x0,
                            -y0,
                            x1,
                            -y1,
                            zoom=False,
                            line=False,
                            text=text)

        draw_arrow(0, args[1])
        if func == 'PLLP':
            draw_arrow(1, args[2])
        color.setAlpha(30)
        self.painter.setBrush(QBrush(color))
        self.painter.drawPolygon(QPolygonF([QPointF(x, y) for x, y in points]))
        self.painter.setBrush(Qt.NoBrush)
Exemplo n.º 15
0
    def draw_solution(
        self,
        func: str,
        args: Sequence[str],
        target: str,
        pos: Sequence[VPoint]
    ) -> None:
        """Draw the solution triangle."""
        points, color = self.solution_polygon(func, args, target, pos)
        color.setAlpha(150)
        pen = QPen(color)
        pen.setWidth(self.joint_size)
        self.painter.setPen(pen)

        def draw_arrow(index: int, text: str) -> None:
            """Draw arrow."""
            self.__draw_arrow(
                points[-1].x(),
                points[-1].y(),
                points[index].x(),
                points[index].y(),
                text=text
            )

        draw_arrow(0, args[1])
        if func == 'PLLP':
            draw_arrow(1, args[2])
        color.setAlpha(30)
        self.painter.setBrush(QBrush(color))
        self.painter.drawPolygon(QPolygonF(points))
        self.painter.setBrush(Qt.NoBrush)
Exemplo n.º 16
0
    def draw_icon(self, painter):
        path = QPainterPath(QPointF(0, 0.3))
        path.lineTo(0, 0.9)
        path.lineTo(1, 0.3)
        path.lineTo(1, 0.9)
        path.closeSubpath()
        painter.drawPath(path)
        painter.drawLine(QPointF(0.5, 0.6), QPointF(0.5, 0.15))

        # Draw the arrow end-caps
        painter.setBrush(QBrush(QColor(0, 0, 0)))

        top_arrow_point = QPointF(0.65, 0.36)
        arrow = QPolygonF([
            QPointF(-0.09, 0.0),
            QPointF(-0.005, 0.0),
            QPointF(-0.005, 0.8),
            QPointF(0.005, 0.8),
            QPointF(0.005, 0.0),
            QPointF(0.09, 0.0),
            QPointF(0.00, -0.25)
        ])

        t = QTransform()
        t.rotate(35)
        top_arrow_r = t.map(arrow)
        arrow_l = top_arrow_r.translated(top_arrow_point)
        painter.drawPolygon(arrow_l)

        painter.setBrush(self._interlock_brush)
        painter.drawRect(QRectF(0.3, 0, 0.4, 0.15))
Exemplo n.º 17
0
    def draw_icon(self, painter):
        path = QPainterPath(QPointF(0, 0.3))
        path.lineTo(0, 0.9)
        path.lineTo(1, 0.3)
        path.lineTo(1, 0.9)
        path.closeSubpath()
        painter.drawPath(path)

        prev_brush = painter.brush()
        prev_pen = painter.pen()

        painter.setPen(Qt.NoPen)
        painter.setBrush(self._arrow_brush)
        arrow = QPolygonF([
            QPointF(0.2, 0),
            QPointF(0.2, 0.20),
            QPointF(0.5, 0.40),
            QPointF(0.8, 0.20),
            QPointF(0.8, 0)
        ])
        painter.drawPolygon(arrow)

        painter.setPen(prev_pen)
        painter.setBrush(prev_brush)
        painter.drawLine(QPointF(0.2, 0), QPointF(0.5, 0.20))
        painter.drawLine(QPointF(0.2, 0.20), QPointF(0.5, 0.40))
        painter.drawLine(QPointF(0.5, 0.20), QPointF(0.8, 0))
        painter.drawLine(QPointF(0.5, 0.40), QPointF(0.8, 0.20))

        painter.drawLine(QPointF(0.5, 0.6), QPointF(0.5, 0.0))
Exemplo n.º 18
0
    def draw_arrow(self, QPainter, point_1: QPointF,
                   point_2: QPointF) -> 'QPolygonF':
        """
        绘制箭头。
        :param QPainter:
        :param point_1:
        :param point_2:
        :return:
        """

        line = QLineF(point_1, point_2)

        v = line.unitVector()

        v.setLength(20)  # 改变单位向量的大小,实际就是改变箭头长度
        v.translate(QPointF(int(line.dx() / 2), int(line.dy() / 2)))

        n = v.normalVector()  # 法向量
        n.setLength(n.length() * 0.2)  # 这里设定箭头的宽度
        n2 = n.normalVector().normalVector()  # 两次法向量运算以后,就得到一个反向的法向量
        p1 = v.p2()
        p2 = n.p2()
        p3 = n2.p2()
        if PYSIDE2:
            QPainter.drawPolygon([p1, p2, p3])
        else:
            QPainter.drawPolygon(p1, p2, p3)
        return QPolygonF([p1, p2, p3, p1])
Exemplo n.º 19
0
 def _paint_diamond(self, painter):
     size = self._size
     X = [0, size / 2, 0, -size / 2, 0]
     Y = [size / 2, 0, -size / 2, 0, size / 2]
     points = [QPointF(x, y) for x, y in zip(X, Y)]
     polygon = QPolygonF(points)
     painter.drawPolygon(polygon, len(points))
Exemplo n.º 20
0
 def initCoords(self):
     w = 10
     h = 10
     r = 6
     coords = [(-r / 2, r), (r / 2, 0), (-r / 2, -r)]
     coords = [(x + w, y + h) for x, y in coords]
     coords = [QPointF(x, y) for x, y in coords]
     coords = QPolygonF(coords)
     self.coords = coords
Exemplo n.º 21
0
 def draw_item(self, painter):
     """
     Draws the Polygon after setting up the canvas with a call to
     ```PyDMDrawing.draw_item```.
     """
     super(PyDMDrawingPolygon, self).draw_item(painter)
     maxsize = not self.is_square()
     x, y, w, h = self.get_bounds(maxsize=not self.is_square())
     poly = self._calculate_drawing_points(x, y, w, h)
     painter.drawPolygon(QPolygonF(poly))
Exemplo n.º 22
0
    def draw_item(self, painter):
        """
        Draws the triangle after setting up the canvas with a call to
        ```PyDMDrawing.draw_item```.
        """
        super(PyDMDrawingTriangle, self).draw_item(painter)
        x, y, w, h = self.get_bounds(maxsize=True)
        points = self._calculate_drawing_points(x, y, w, h)

        painter.drawPolygon(QPolygonF(points))
Exemplo n.º 23
0
 def draw_icon(self, painter):
     painter.drawEllipse(QPointF(0.5, 0.5), 0.5, 0.5)
     painter.drawChord(QRectF(0.0, 0.0, 1.0, 1.0), 45 * 16, -120 * 16)
     painter.drawChord(QRectF(0.0, 0.0, 1.0, 1.0), 135 * 16, 120 * 16)
     bottom_arrow_point = QPointF(0.5, 0.8)
     painter.drawLine(bottom_arrow_point, QPointF(0.5, 0.7))
     curve_start = QPointF(0.5, 0.7)
     bend_angle = 25
     curve_end_l = QPointF(
         0.4 * math.cos(math.radians(90 + bend_angle)) + 0.5,
         -0.4 * math.sin(math.radians(90 + bend_angle)) + 0.5)
     c1 = QPointF(0.5, 0.4)
     path = QPainterPath(curve_start)
     path.quadTo(c1, curve_end_l)
     painter.drawPath(path)
     curve_end_r = QPointF(
         0.4 * math.cos(math.radians(90 - bend_angle)) + 0.5,
         -0.4 * math.sin(math.radians(90 - bend_angle)) + 0.5)
     path = QPainterPath(curve_start)
     path.quadTo(c1, curve_end_r)
     painter.drawPath(path)
     # Draw the arrow end-caps
     painter.setBrush(QBrush(QColor(0, 0, 0)))
     arrow = QPolygonF(
         [QPointF(-0.025, 0.0),
          QPointF(0.025, 0.0),
          QPointF(0.0, 0.025)])
     painter.drawPolygon(arrow.translated(bottom_arrow_point))
     t = QTransform()
     t.rotate(180.0 - 25.0)
     arrow_l = t.map(arrow)
     arrow_l = arrow_l.translated(curve_end_l)
     painter.drawPolygon(arrow_l)
     t = QTransform()
     t.rotate(180.0 + 25.0)
     arrow_r = t.map(arrow)
     arrow_r = arrow_r.translated(curve_end_r)
     painter.drawPolygon(arrow_r)
Exemplo n.º 24
0
def qwtCombinePathList(rect, pathList):
    if not pathList:
        return QPainterPath()

    ordered = [None] * 8
    for subPath in pathList:
        index = -1
        br = subPath.controlPointRect()
        if br.center().x() < rect.center().x():
            if br.center().y() < rect.center().y():
                if abs(br.top() - rect.top()) < abs(br.left() - rect.left()):
                    index = 1
                else:
                    index = 0
            else:
                if abs(br.bottom() - rect.bottom) < abs(br.left() -
                                                        rect.left()):
                    index = 6
                else:
                    index = 7
            if subPath.currentPosition().y() > br.center().y():
                qwtRevertPath(subPath)
        else:
            if br.center().y() < rect.center().y():
                if abs(br.top() - rect.top()) < abs(br.right() - rect.right()):
                    index = 2
                else:
                    index = 3
            else:
                if abs(br.bottom() - rect.bottom()) < abs(br.right() -
                                                          rect.right()):
                    index = 5
                else:
                    index = 4
            if subPath.currentPosition().y() < br.center().y():
                qwtRevertPath(subPath)
        ordered[index] = subPath
    for i in range(4):
        if ordered[2 * i].isEmpty() != ordered[2 * i + 1].isEmpty():
            return QPainterPath()
    corners = QPolygonF(rect)
    path = QPainterPath()
    for i in range(4):
        if ordered[2 * i].isEmpty():
            path.lineTo(corners[i])
        else:
            path.connectPath(ordered[2 * i])
            path.connectPath(ordered[2 * i + 1])
    path.closeSubpath()
    return path
Exemplo n.º 25
0
def qwtDrawBox(p, rect, pal, lw):
    if lw > 0.0:
        if rect.width() == 0.0:
            p.setPen(pal.dark().color())
            p.drawLine(rect.topLeft(), rect.bottomLeft())
            return
        if rect.height() == 0.0:
            p.setPen(pal.dark().color())
            p.drawLine(rect.topLeft(), rect.topRight())
            return
        lw = min([lw, rect.height() / 2.0 - 1.0])
        lw = min([lw, rect.width() / 2.0 - 1.0])
        outerRect = rect.adjusted(0, 0, 1, 1)
        polygon = QPolygonF(outerRect)
        if outerRect.width() > 2 * lw and outerRect.height() > 2 * lw:
            innerRect = outerRect.adjusted(lw, lw, -lw, -lw)
            polygon = polygon.subtracted(innerRect)
        p.setPen(Qt.NoPen)
        p.setBrush(pal.dark())
        p.drawPolygon(polygon)
    windowRect = rect.adjusted(lw, lw, -lw + 1, -lw + 1)
    if windowRect.isValid():
        p.fillRect(windowRect, pal.window())
Exemplo n.º 26
0
 def insertRows(self, row, count, parent=QModelIndex()):
     if row > len(self._data):
         return False
     self.beginInsertRows(parent, row, row + count - 1)
     for i in range(count):
         self._data.insert(
             row,
             types.SimpleNamespace(fileName=None,
                                   locData=None,
                                   locOptions=None,
                                   roi=QPolygonF(),
                                   frameRange=(0, 0)))
     self.endInsertRows()
     return True
Exemplo n.º 27
0
    def draw_icon(self, painter):
        painter.drawEllipse(QPointF(0.5, 0.5), 0.5, 0.5)
        painter.drawChord(QRectF(0.0, 0.0, 1.0, 1.0), 45 * 16, -120 * 16)
        painter.drawChord(QRectF(0.0, 0.0, 1.0, 1.0), 135 * 16, 120 * 16)
        circle_arrow_point = QPointF(0.3, 0.5)

        brush = painter.brush()
        pen = painter.pen()

        painter.setBrush(self.centerBrush)
        painter.setPen(QColor("transparent"))
        painter.drawEllipse(QPointF(0.5, 0.5), 0.2, 0.2)

        painter.setBrush(brush)
        painter.setPen(pen)

        painter.drawArc(QRectF(0.3, 0.3, 0.4, 0.4), 90 * 16, -270 * 16)

        arrow = QPolygonF(
            [QPointF(-0.025, 0.0),
             QPointF(0.025, 0.0),
             QPointF(0.0, -0.025)])
        painter.setBrush(QBrush(QColor(0, 0, 0)))
        painter.drawPolygon(arrow.translated(circle_arrow_point))
Exemplo n.º 28
0
    def setImage(self, img, **kwargs):

        if hasattr(img, 'coords'):

            if 'transform' not in kwargs:

                xvals = img.coords[img.dims[-2]]
                yvals = img.coords[img.dims[-1]]
                xmin = float(xvals.min())
                xmax = float(xvals.max())
                ymin = float(yvals.min())
                ymax = float(yvals.max())

                # Position the image according to coords
                shape = img.shape
                a = [(0, shape[-2]), (shape[-1] - 1, shape[-2]),
                     (shape[-1] - 1, 1), (0, 1)]

                b = [(ymin, xmin), (ymax, xmin), (ymax, xmax), (ymin, xmax)]

                quad1 = QPolygonF()
                quad2 = QPolygonF()
                for p, q in zip(a, b):
                    quad1.append(QPointF(*p))
                    quad2.append(QPointF(*q))

                transform = QTransform()
                QTransform.quadToQuad(quad1, quad2, transform)

                kwargs['transform'] = transform

            if 'xvals' not in kwargs:
                kwargs['xvals'] = np.asarray(img.coords[img.dims[0]])

            # Set the timeline axis label from dims
            self.ui.roiPlot.setLabel('bottom', img.dims[0])

            # Label the image axes
            self.axesItem.setLabel('left', img.dims[-2])
            self.axesItem.setLabel('bottom', img.dims[-1])

            # Add a bit more size
            self.ui.roiPlot.setMinimumSize(QSize(0, 70))

        # Bind coords from the xarray to the timeline axis
        super(XArrayView, self).setImage(img, **kwargs)
Exemplo n.º 29
0
    def drawSteps(self, painter, xMap, yMap, canvasRect, from_, to):
        """
        Draw steps

        :param QPainter painter: Painter
        :param qwt.scale_map.QwtScaleMap xMap: Maps x-values into pixel coordinates.
        :param qwt.scale_map.QwtScaleMap yMap: Maps y-values into pixel coordinates.
        :param QRectF canvasRect: Contents rectangle of the canvas
        :param int from_: Index of the first point to be painted
        :param int to: Index of the last point to be painted. If to < 0 the curve will be painted to its last point.

        .. seealso::

            :py:meth:`draw()`, :py:meth:`drawSticks()`,
            :py:meth:`drawDots()`, :py:meth:`drawLines()`
        """
        size = 2 * (to - from_) + 1
        if QT_API == "pyside6":
            polygon = QPolygonF()
            polygon.resize(size)
        elif QT_API == "pyqt6":
            polygon = QPolygonF([QPointF(0, 0)] * size)
        else:
            polygon = QPolygonF(size)
        inverted = self.orientation() == Qt.Vertical
        if self.__data.attributes & self.Inverted:
            inverted = not inverted
        series = self.data()
        ip = 0
        for i in range(from_, to + 1):
            sample = series.sample(i)
            xi = xMap.transform(sample.x())
            yi = yMap.transform(sample.y())
            if ip > 0:
                p0 = polygon[ip - 2]
                if inverted:
                    polygon[ip - 1] = QPointF(p0.x(), yi)
                else:
                    polygon[ip - 1] = QPointF(xi, p0.y())
            polygon[ip] = QPointF(xi, yi)
            ip += 2
        painter.drawPolyline(polygon)
        if self.__data.brush.style() != Qt.NoBrush:
            self.fillCurve(painter, xMap, yMap, canvasRect, polygon)
Exemplo n.º 30
0
def qwtDrawDiamondSymbols(painter, points, numPoints, symbol):
    size = symbol.size()
    pen = QPen(symbol.pen())
    pen.setJoinStyle(Qt.MiterJoin)
    painter.setPen(pen)
    painter.setBrush(symbol.brush())
    for pos in points:
        x1 = pos.x() - 0.5 * size.width()
        y1 = pos.y() - 0.5 * size.height()
        x2 = x1 + size.width()
        y2 = y1 + size.height()
        polygon = QPolygonF()
        polygon += QPointF(pos.x(), y1)
        polygon += QPointF(x1, pos.y())
        polygon += QPointF(pos.x(), y2)
        polygon += QPointF(x2, pos.y())
        painter.drawPolygon(polygon)