Python PyQt5.QtCore.QPointF() Examples

The following are 30 code examples for showing how to use PyQt5.QtCore.QPointF(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module PyQt5.QtCore , or try the search function .

Example 1
Project: phidl   Author: amccaugh   File: quickplotter.py    License: MIT License 6 votes vote down vote up
def add_polygons(self, polygons, color = '#A8F22A', alpha = 1):
        qcolor = QColor()
        qcolor.setNamedColor(color)
        qcolor.setAlphaF(alpha)
        for points in polygons:
            qpoly = QPolygonF( [QPointF(p[0], p[1]) for p in points] )
            scene_poly = self.scene.addPolygon(qpoly)
            scene_poly.setBrush(qcolor)
            scene_poly.setPen(self.pen)
            self.scene_polys.append(scene_poly)
            # Update custom bounding box
            sr = scene_poly.sceneBoundingRect()
            if len(self.scene_polys) == 1:
                self.scene_xmin = sr.left()
                self.scene_xmax = sr.right()
                self.scene_ymin = sr.top()
                self.scene_ymax = sr.bottom()
            else:
                self.scene_xmin = min(self.scene_xmin, sr.left())
                self.scene_xmax = max(self.scene_xmax, sr.right())
                self.scene_ymin = min(self.scene_ymin, sr.top())
                self.scene_ymax = max(self.scene_ymax, sr.bottom()) 
Example 2
Project: Computer-graphics   Author: Panda-Lewandowski   File: lab2.py    License: MIT License 6 votes vote down vote up
def transfer():
    global epi_x, epi_y, p1, p2, p3, p4, rect
    write_log()
    dx = window.spin_trans_x.value()
    dy = window.spin_trans_y.value()
    scene.clear()
    p1 = [p1[0] + dx, p1[1] + dy]
    p2 = [p2[0] + dx, p2[1] + dy]
    p3 = [p3[0] + dx, p3[1] + dy]
    p4 = [p4[0] + dx, p4[1] + dy]
    rect[0] = QPointF(p1[0], p1[1])
    rect[1] = QPointF(p2[0], p2[1])
    rect[2] = QPointF(p3[0], p3[1])
    rect[3] = QPointF(p4[0], p4[1])
    scene.addPolygon(rect, pen=p, brush=b)
    epi_x = [x + dx for x in epi_x]
    epi_y = [y + dy for y in epi_y]
    l = len(epi_x)
    for i in range(l):
        scene.addLine(epi_x[i], epi_y[i], epi_x[i] + 0.01, epi_y[i] + 0.01, pen=p) 
Example 3
Project: Computer-graphics   Author: Panda-Lewandowski   File: lab2.py    License: MIT License 6 votes vote down vote up
def set():
    global epi_x, epi_y, p1, p2, p3, p4, rect
    scene.clear()
    dx = 500
    dy = 500
    kx = 10
    ky = 10
    p1 = [-10 * kx + dx, -10 * ky + dy]
    p2 = [-10 * kx + dx + 20 * kx, -10 * ky + dy]
    p3 = [-10 * kx + dx + 20 * kx, -10 * ky + dy + 20 * ky]
    p4 = [-10 * kx + dx, -10 * ky + dy + 20 * ky]

    rect[0] = QPointF(p1[0], p1[1])
    rect[1] = QPointF(p2[0], p2[1])
    rect[2] = QPointF(p3[0], p3[1])
    rect[3] = QPointF(p4[0], p4[1])
    epi_x = []
    epi_y = []
    scene.addPolygon(rect, pen=p, brush=b)
    for t in np.arange(0, 4 * math.pi, 0.001):
        x = 5 * math.cos(t) * kx - 2 * math.cos(5 / 2 * t) * kx + dx
        y = 5 * math.sin(t) * ky - 2 * math.sin(5 / 2 * t) * ky + dy
        epi_x.append(x)
        epi_y.append(y)
        scene.addLine(x, y, x + 0.01, y + 0.01, pen=p) 
Example 4
Project: Computer-graphics   Author: Panda-Lewandowski   File: lab2.py    License: MIT License 6 votes vote down vote up
def undo():
    global b_epi_x, b_epi_y, b1, b2, b3, b4, epi_x, epi_y, p1, p2, p3, p4, btn_undo
    epi_x = b_epi_x
    epi_y = b_epi_y
    p1 = b1
    p2 = b2
    p3 = b3
    p4 = b4
    rect[0] = QPointF(p1[0], p1[1])
    rect[1] = QPointF(p2[0], p2[1])
    rect[2] = QPointF(p3[0], p3[1])
    rect[3] = QPointF(p4[0], p4[1])
    scene.clear()
    scene.addPolygon(rect, pen=p, brush=b)
    l = len(epi_x)
    for i in range(l):
        scene.addLine(epi_x[i], epi_y[i], epi_x[i] + 0.01, epi_y[i] + 0.01, pen=p) 
Example 5
Project: kite   Author: pyrocko   File: multiplot.py    License: GNU General Public License v3.0 6 votes vote down vote up
def paint(self, painter, option, parent):
        if self.line.length() == 0.:
            return
        painter.setPen(self.arrow_pen)
        painter.setRenderHint(QtGui.QPainter.Antialiasing)
        painter.setCompositionMode(QtGui.QPainter.CompositionMode_SourceOver)

        arrow_length = self.line.length() * .3 * (self.relative_length / 100.)
        d = self.line.angle()
        head_p1 = self.p2 - QtCore.QPointF(
            num.sin(d*d2r + num.pi/3) * arrow_length,
            num.cos(d*d2r + num.pi/3) * arrow_length)

        head_p2 = self.p2 - QtCore.QPointF(
            num.sin(d*d2r + num.pi - num.pi/3) * arrow_length,
            num.cos(d*d2r + num.pi - num.pi/3) * arrow_length)

        painter.drawLine(self.line)
        painter.drawPolyline(*[head_p1, self.p2, head_p2]) 
Example 6
Project: imperialism-remake   Author: Trilarion   File: landBattleMap.py    License: GNU General Public License v3.0 6 votes vote down vote up
def position_to_grid_position(self, position):
        """function position_to_grid_position

        :param position: QPointF

        returns int, int return (column,row) corresponding to the QPointF
        """
        if not isinstance(position, QPointF):
            raise ValueError('position must be a QPointF instance')
        estimated_column = round(position.x() / (2 * self.get_size_tile()))
        estimated_row = round(position.y() / (math.sqrt(3) * self.get_size_tile()))
        for r in range(estimated_row - 3, estimated_row + 4):
            for c in range(estimated_column - 3, estimated_column + 4):
                field_index = self.grid_position_to_index(c, r)
                if len(self.fields) > field_index and self.fields[field_index].enable and \
                        self.fields[field_index].hexa.containsPoint(position, Qt.OddEvenFill):
                    return c, r
        return -1, -1 
Example 7
Project: stytra   Author: portugueslab   File: visual.py    License: GNU General Public License v3.0 6 votes vote down vote up
def paint(self, p, w, h):
        if self._experiment.calibrator is not None:
            mm_px = self._experiment.calibrator.mm_px
        else:
            mm_px = 1

        self.clip(p, w, h)

        # draw the black background
        p.setBrush(QBrush(QColor(*self.background_color)))
        p.drawRect(QRect(-1, -1, w + 2, h + 2))

        imw, imh = self.get_unit_dims(w, h)

        dx = self.x / mm_px
        dy = self.y / mm_px

        # rotate the coordinate transform around the position of the fish
        tr = self.get_transform(w, h, dx, dy)
        p.setTransform(tr)

        for idx, idy in product(*self.get_tile_ranges(imw, imh, w, h, tr)):
            self.draw_block(p, QPointF(idx * imw, idy * imh), w, h)

        p.resetTransform() 
Example 8
Project: stytra   Author: portugueslab   File: visual.py    License: GNU General Public License v3.0 6 votes vote down vote up
def paint(self, p, w, h):
        super().paint(p, w, h)

        if self._experiment.calibrator is not None:
            mm_px = self._experiment.calibrator.mm_px
        else:
            mm_px = 1

        # draw the background
        p.setPen(Qt.NoPen)
        p.setBrush(QBrush(QColor(*self.background_color)))
        self.clip(p, w, h)
        p.drawRect(QRect(-1, -1, w + 2, h + 2))

        # draw the circle
        p.setBrush(QBrush(QColor(*self.circle_color)))
        p.drawEllipse(QPointF(self.x * w, self.y * h), self.radius * w, self.radius * h) 
Example 9
Project: pychemqt   Author: jjgomera   File: flujo.py    License: GNU General Public License v3.0 6 votes vote down vote up
def keyPressEvent(self, event):
        if event.key() == QtCore.Qt.Key_Delete or event.key() == QtCore.Qt.Key_Backspace:
            self.delete()
        elif event.key() == QtCore.Qt.Key_Escape:
            self.setSelected(False)
        elif event.key() == QtCore.Qt.Key_Return or event.key() == QtCore.Qt.Key_Enter:
            self.mouseDoubleClickEvent()
        elif event.key() == QtCore.Qt.Key_Up:
            self.setPos(QtCore.QPointF(self.pos().x(), self.pos().y() - factor))
            self.mouseMoveEvent()
        elif event.key() == QtCore.Qt.Key_Down:
            self.setPos(QtCore.QPointF(self.pos().x(), self.pos().y() + factor))
            self.mouseMoveEvent()
        elif event.key() == QtCore.Qt.Key_Left:
            self.setPos(QtCore.QPointF(self.pos().x() - factor, self.pos().y()))
            self.mouseMoveEvent()
        elif event.key() == QtCore.Qt.Key_Right:
            self.setPos(QtCore.QPointF(self.pos().x() + factor, self.pos().y()))
            self.mouseMoveEvent() 
Example 10
Project: eddy   Author: danielepantaleone   File: view.py    License: GNU General Public License v3.0 6 votes vote down vote up
def setGridSize(self, size):
        """
        Sets the grid size.
        """
        action = self.session.action('toggle_grid')
        size = clamp(size, 0)
        if size <= 0 or not action.isChecked():
            brush = QtGui.QBrush(QtCore.Qt.NoBrush)
        else:
            image = QtGui.QImage(size, size, QtGui.QImage.Format_RGB32)
            image.fill(QtCore.Qt.white)
            painter = QtGui.QPainter(image)
            painter.setPen(QtGui.QPen(QtGui.QBrush(QtGui.QColor(80, 80, 80, 255)), 1, QtCore.Qt.SolidLine))
            painter.drawPoint(QtCore.QPointF(0, 0))
            painter.end()
            brush = QtGui.QBrush(image)
        self.setBackgroundBrush(brush) 
Example 11
Project: eddy   Author: danielepantaleone   File: view.py    License: GNU General Public License v3.0 6 votes vote down vote up
def startMove(self, delta, rate):
        """
        Start the view movement.
        :type delta: QtCore.QPointF
        :type rate: float
        """
        if self.mv_Timer:
            self.stopMove()

        # Move the view: this is needed before the timer so that if we keep
        # moving the mouse fast outside the viewport rectangle we still are able
        # to move the view; if we don't do this the timer may not have kicked in
        # and thus we remain with a non-moving view with a unfocused graphics item.
        self.moveBy(delta)

        # Setup a timer for future move, so the view keeps moving
        # also if we are not moving the mouse anymore but we are
        # holding the position outside the viewport rect.
        self.mv_Timer = QtCore.QTimer()
        connect(self.mv_Timer.timeout, self.moveBy, delta)
        self.mv_Timer.start(rate) 
Example 12
Project: eddy   Author: danielepantaleone   File: diagram.py    License: GNU General Public License v3.0 6 votes vote down vote up
def items(self, mixed=None, mode=QtCore.Qt.IntersectsItemShape, **kwargs):
        """
        Returns a collection of items ordered from TOP to BOTTOM.
        If no argument is supplied, an unordered list containing all the elements in the diagram is returned.
        :type mixed: T <= QPointF | QRectF | QPolygonF | QPainterPath
        :type mode: ItemSelectionMode
        :rtype: list
        """
        if mixed is None:
            items = super().items()
        elif isinstance(mixed, QtCore.QPointF):
            x = mixed.x() - (Diagram.SelectionRadius / 2)
            y = mixed.y() - (Diagram.SelectionRadius / 2)
            w = Diagram.SelectionRadius
            h = Diagram.SelectionRadius
            items = super().items(QtCore.QRectF(x, y, w, h), mode)
        else:
            items = super().items(mixed, mode)
        return sorted([
            x for x in items
                if (kwargs.get('nodes', True) and x.isNode() or
                    kwargs.get('edges', True) and x.isEdge() or
                    kwargs.get('labels', False) and x.isLabel()) and
                    x not in kwargs.get('skip', set())
        ], key=lambda i: i.zValue(), reverse=True) 
Example 13
Project: eddy   Author: danielepantaleone   File: diagram.py    License: GNU General Public License v3.0 6 votes vote down vote up
def visibleRect(self, margin=0):
        """
        Returns a rectangle matching the area of visible items.
        :type margin: float
        :rtype: QtCore.QRectF
        """
        items = self.items()
        if items:
            x = set()
            y = set()
            for item in items:
                b = item.mapRectToScene(item.boundingRect())
                x.update({b.left(), b.right()})
                y.update({b.top(), b.bottom()})
            return QtCore.QRectF(QtCore.QPointF(min(x) - margin, min(y) - margin), QtCore.QPointF(max(x) + margin, max(y) + margin))
        return QtCore.QRectF() 
Example 14
Project: eddy   Author: danielepantaleone   File: graphol.py    License: GNU General Public License v3.0 6 votes vote down vote up
def importGenericNode(d, i, e):
        """
        Build a node using the given item type and QDomElement.
        :type d: Diagram
        :type i: Item
        :type e: QDomElement
        :rtype: AbstractNode
        """
        geometry = e.firstChildElement('geometry')
        node = d.factory.create(i, **{
            'id': e.attribute('id'),
            'height': int(geometry.attribute('height')),
            'width': int(geometry.attribute('width'))
        })
        node.setPos(QtCore.QPointF(int(geometry.attribute('x')), int(geometry.attribute('y'))))
        return node

    #############################################
    #   ONTOLOGY DIAGRAMS : MAIN IMPORT
    ################################# 
Example 15
Project: eddy   Author: danielepantaleone   File: graphml.py    License: GNU General Public License v3.0 6 votes vote down vote up
def optimizeLabelPos(node):
        """
        Perform updates on the position of the label of the given Domain o Range restriction node.
        This is due to yEd not using the label to denote the 'exists' restriction and because Eddy
        adds the label automatically, it may overlap some other elements hence we try to give it
        some more visibility by moving it around the node till it overlaps less stuff.
        :type node: T <= DomainRestrictionNode|RangeRestrictionNode
        """
        if node.type() in {Item.DomainRestrictionNode, Item.RangeRestrictionNode}:
            if node.restriction() is Restriction.Exists:
                if not node.label.isMoved() and node.label.collidingItems():
                    x = [-30, -15, 0, 15, 30]
                    y = [0, 12, 22, 32, 44]
                    pos = node.label.pos()
                    for offset_x, offset_y in itertools.product(x, y):
                        node.label.setPos(pos + QtCore.QPointF(offset_x, offset_y))
                        if not node.label.collidingItems():
                            break
                    else:
                        node.label.setPos(pos)

    #############################################
    #   MAIN IMPORT
    ################################# 
Example 16
Project: eddy   Author: danielepantaleone   File: qt.py    License: GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, width, height, color, border=None):
        """
        Initialize the icon.
        :type width: T <= int | float
        :type height: T <= int | float
        :type color: str
        :type border: str
        """
        pixmap = QtGui.QPixmap(width, height)
        painter = QtGui.QPainter(pixmap)
        painter.setRenderHint(QtGui.QPainter.Antialiasing)
        path = QtGui.QPainterPath()
        path.addRect(QtCore.QRectF(QtCore.QPointF(0, 0), QtCore.QPointF(width, height)))
        painter.fillPath(path, QtGui.QBrush(QtGui.QColor(color)))
        if border:
            painter.setPen(QtGui.QPen(QtGui.QColor(border), 0, QtCore.Qt.SolidLine))
            painter.drawPath(path)
        painter.end()
        super().__init__(pixmap) 
Example 17
Project: eddy   Author: danielepantaleone   File: geometry.py    License: GNU General Public License v3.0 6 votes vote down vote up
def projection(line, p):
    """
    Calculate the projection of the given point on the given line.
    Will return a tuple containing the length of the segment connecting the
    original point with its projection, and the coordinate of the projected point.
    :type line: QLineF
    :type p: QPointF
    :rtype: tuple
    """
    x1 = line.x1()
    y1 = line.y1()
    x2 = line.x2()
    y2 = line.y2()
    x3 = p.x()
    y3 = p.y()

    kk = ((y2 - y1) * (x3 - x1) - (x2 - x1) * (y3 - y1)) / (math.pow(y2 - y1, 2) + math.pow(x2 - x1, 2))
    x4 = x3 - kk * (y2 - y1)
    y4 = y3 + kk * (x2 - x1)

    p1 = QtCore.QPointF(x3, y3)
    p2 = QtCore.QPointF(x4, y4)

    return distance(p1, p2), p2 
Example 18
Project: pkmeter   Author: pkkid   File: pkcharts.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def paintEvent(self, event):
        if not self.data: return
        QtWidgets.QFrame.paintEvent(self, event)
        painter = QtGui.QPainter()
        painter.begin(self)
        painter.setRenderHint(QtGui.QPainter.Antialiasing)
        # Draw background
        painter.setBrush(QtGui.QBrush(self.bgcolor))
        painter.setPen(Qt.NoPen)
        painter.drawRoundedRect(self.contentsRect(), 2, 2)
        # Draw the Lines
        for i in range(len(self.data[0])):
            path = None
            pen = QtGui.QPen(self.colors[i % len(self.colors)])
            for j in range(len(self.data)):
                value = self.data[j][i]
                prevvalue = self.data[j-1][i]
                if value == -1 or prevvalue == -1:
                    continue
                if not self.showzero and value <= 0 and prevvalue <= 0:
                    continue
                x1 = (self.pxperpt * (j - 0.5) + self.pxperpt / 4) - self.offset
                x2 = (self.pxperpt * j + self.pxperpt / 4) - self.offset
                y1 = self.height() - int((self.height() - 1) * (prevvalue / self.maxvalue))
                y2 = self.height() - int((self.height() - 1) * (value / self.maxvalue))
                path = path or QtGui.QPainterPath(QtCore.QPointF(x1,y1))
                path.cubicTo(x1, y1, x1, y2, x2, y2)
            if path:
                painter.strokePath(path, pen)
        painter.end() 
Example 19
Project: mindfulness-at-the-computer   Author: mindfulness-at-the-computer   File: breathing_dlg.py    License: GNU General Public License v3.0 5 votes vote down vote up
def update_pos_and_origin_point(self, i_view_width: int, i_view_height: int):
        t_pointf = QtCore.QPointF(
            i_view_width / 2 - self.boundingRect().width() / 2,
            i_view_height / 2 - self.boundingRect().height() / 2
        )
        self.setPos(t_pointf)

        self.setTransformOriginPoint(self.boundingRect().center()) 
Example 20
Project: mindfulness-at-the-computer   Author: mindfulness-at-the-computer   File: breathing_dlg.py    License: GNU General Public License v3.0 5 votes vote down vote up
def update_pos_and_origin_point(self, i_view_width: int, i_view_height: int):
        t_pointf = QtCore.QPointF(
            i_view_width / 2 - self.boundingRect().width() / 2,
            i_view_height / 2 - self.boundingRect().height() / 2
        )
        self.setPos(t_pointf)

        self.setTransformOriginPoint(self.boundingRect().center()) 
Example 21
Project: gdb_python_api   Author: jefftrull   File: instrument_srs.py    License: MIT License 5 votes vote down vote up
def _check_for_messages(self):
        from PyQt5.QtCore import QPointF

        # poll command queue
        # not ideal but safe. OK for now.
        if not self.messages.empty():
            op, a, b = self.messages.get()
            if op is 'swap':
                # actually seems to understand the size of the elements:
                self._perform_swap(a, b)
            elif op is 'move':
                self.elements[b] = self.elements[a]
                self.elements[a] = None
                self._perform_move(self.elements[b], QPointF(20+20*b, 20))
            elif op is 'move_from_temp':
                # temporary elements indexed by address, as a string
                (pos, temp_elt) = self.temp_elements[a]
                self.temp_elements[a] = (pos, None)
                self._perform_move(temp_elt, QPointF(20+20*b, 20))
                self.elements[b] = temp_elt
            elif op is 'move_to_temp':
                # see if we know of this temp element
                if b in self.temp_elements:
                    # we already saw this address. reuse its position.
                    (pos, temp_elt) = self.temp_elements[b]
                else:
                    pos = QPointF(20+20*len(self.temp_elements), 60)
                self._perform_move(self.elements[a], pos)
                self.temp_elements[b] = (pos, self.elements[a])
                self.elements[a] = None
            else:
                print('unknown move command from %s to %s' % (a, b)) 
Example 22
Project: gdb_python_api   Author: jefftrull   File: instrument_srs.py    License: MIT License 5 votes vote down vote up
def _perform_swap(self, a, b):
        from PyQt5.QtCore import QPointF, QPropertyAnimation

        elt_a = self.elements[a]
        elt_b = self.elements[b]
        # update positions
        pos_a = elt_a.pos
        pos_b = elt_b.pos

        # animate the exchange: move in an arc above/below a point halfway between
        pos_between = (pos_a + pos_b) / 2
        pos_above = QPointF(pos_between.x(), -10)
        pos_below = QPointF(pos_between.x(), 50)
        anim_a = QPropertyAnimation(self.elements[a], b'pos')
        anim_b = QPropertyAnimation(self.elements[b], b'pos')
        anim_a.setDuration(400)
        anim_b.setDuration(400)
        anim_a.setKeyValueAt(0.5, pos_above)
        anim_b.setKeyValueAt(0.5, pos_below)
        anim_a.setKeyValueAt(1, pos_b)
        anim_b.setKeyValueAt(1, pos_a)
        anim_a.start()
        anim_b.start()
        self.animations.append(anim_a)
        self.animations.append(anim_b)

        # update elements list
        self.elements[a] = elt_b
        self.elements[b] = elt_a 
Example 23
Project: phidl   Author: amccaugh   File: quickplotter.py    License: MIT License 5 votes vote down vote up
def add_port(self, port, is_subport = False):
        if (port.width is None) or (port.width == 0):
            x,y = port.midpoint
            cs = 1 # cross size
            pn = QPointF(x, y+cs)
            ps = QPointF(x, y-cs)
            pe = QPointF(x+cs, y)
            pw = QPointF(x-cs, y)
            qline1 = self.scene.addLine(QLineF(pn, ps))
            qline2 = self.scene.addLine(QLineF(pw, pe))
            port_shapes = [qline1,qline2]
        else:
            point1, point2 = port.endpoints
            point1 = QPointF(point1[0], point1[1])
            point2 = QPointF(point2[0], point2[1])
            qline = self.scene.addLine(QLineF(point1, point2))
            arrow_points = np.array([[0,0],[10,0],[6,4],[6,2],[0,2]])/(40)*port.width
            arrow_qpoly = QPolygonF( [QPointF(p[0], p[1]) for p in arrow_points] )
            port_scene_poly = self.scene.addPolygon(arrow_qpoly)
            port_scene_poly.setRotation(port.orientation)
            port_scene_poly.moveBy(port.midpoint[0], port.midpoint[1])
            port_shapes = [qline,port_scene_poly]
        qtext = self.scene.addText(str(port.name), self.portfont)
        port_items = port_shapes + [qtext]
        rad = port.orientation*np.pi/180
        x,y = port.endpoints[0]*1/4 +  port.endpoints[1]*3/4 + np.array([np.cos(rad), np.sin(rad)])*port.width/8
#        x,y = port.midpoint[0], port.midpoint[1]
#        x,y  = x - qtext.boundingRect().width()/2, y - qtext.boundingRect().height()/2
        qtext.setPos(QPointF(x,y))
        qtext.setFlag(QGraphicsItem.ItemIgnoresTransformations)

        if not is_subport:
            [shape.setPen(self.portpen) for shape in port_shapes]
            qtext.setDefaultTextColor(self.portfontcolor)
            self.portitems += port_items
        else:
            [shape.setPen(self.subportpen) for shape in port_shapes]
            qtext.setDefaultTextColor(self.subportfontcolor)
            self.subportitems += port_items
#        self.portlabels.append(qtext) 
Example 24
Project: phidl   Author: amccaugh   File: quickplotter.py    License: MIT License 5 votes vote down vote up
def add_aliases(self, aliases):
        for name, ref in aliases.items():
            qtext = self.scene.addText(str(name), self.portfont)
            x,y = ref.center
            qtext.setPos(QPointF(x,y))
            qtext.setFlag(QGraphicsItem.ItemIgnoresTransformations)
            self.aliasitems += [qtext] 
Example 25
Project: phidl   Author: amccaugh   File: quickplotter.py    License: MIT License 5 votes vote down vote up
def finalize(self):
        self.scene_bounding_rect = QRectF(QPointF(self.scene_xmin,self.scene_ymin),
                                          QPointF(self.scene_xmax,self.scene_ymax))
        # self.scene_center = [self.scene_bounding_rect.center().x(), self.scene_bounding_rect.center().y()]
        self.scene_size = [self.scene_bounding_rect.width(), self.scene_bounding_rect.height()]
        self.create_grid()
        self.update_grid()

#==============================================================================
#   Grid creation
#============================================================================== 
Example 26
Project: JRTTView   Author: XIVN1987   File: RTTView.py    License: MIT License 5 votes vote down vote up
def initQwtPlot(self):
        self.PlotData  = [[0]*1000 for i in range(N_CURVES)]
        self.PlotPoint = [[QtCore.QPointF(j, 0) for j in range(1000)] for i in range(N_CURVES)]

        self.PlotChart = QChart()

        self.ChartView = QChartView(self.PlotChart)
        self.ChartView.setVisible(False)
        self.vLayout.insertWidget(0, self.ChartView)
        
        self.PlotCurve = [QLineSeries() for i in range(N_CURVES)] 
Example 27
Project: Computer-graphics   Author: Panda-Lewandowski   File: lab2.py    License: MIT License 5 votes vote down vote up
def scale():
    global epi_x, epi_y, p1, p2, p3, p4, rect
    write_log()
    kx = window.spin_kx.value()
    sc_x = window.spin_scl_x.value()
    sc_y = window.spin_scl_y.value()
    ky = window.spin_ky.value()
    #print(kx, ky)

    scene.clear()
    epi_x = [x * kx + (1 - kx) * sc_x for x in epi_x]
    epi_y = [y * ky + (1 - ky) * sc_y for y in epi_y]
    p1 = [p1[0] * kx + (1 - kx) * sc_x, p1[1] * ky + (1 - ky) * sc_y]
    p2 = [p2[0] * kx + (1 - kx) * sc_x, p2[1] * ky + (1 - ky) * sc_y]
    p3 = [p3[0] * kx + (1 - kx) * sc_x, p3[1] * ky + (1 - ky) * sc_y]
    p4 = [p4[0] * kx + (1 - kx) * sc_x, p4[1] * ky + (1 - ky) * sc_y]
    #print(p1.x)

    rect[0] = QPointF(p1[0], p1[1])
    rect[1] = QPointF(p2[0], p2[1])
    rect[2] = QPointF(p3[0], p3[1])
    rect[3] = QPointF(p4[0], p4[1])
    scene.addPolygon(rect, pen=p, brush=b)
    l = len(epi_x)
    for i in range(l):
        scene.addLine(epi_x[i], epi_y[i], epi_x[i] + 0.01, epi_y[i] + 0.01, pen=p) 
Example 28
Project: Computer-graphics   Author: Panda-Lewandowski   File: lab2.py    License: MIT License 5 votes vote down vote up
def turn():
    global epi_x, epi_y, p1, p2, p3, p4, rect
    write_log()
    teta = math.radians(window.spin_deg.value())
    t_x = window.spin_turn_x.value()
    t_y = window.spin_turn_y.value()
    scene.clear()

    rect_t = QPolygonF(4)
    p1 = [t_x + (p1[0] - t_x) * math.cos(teta) + (p1[1] - t_y) * math.sin(teta),
          t_y - (p1[0] - t_x) * math.sin(teta) + (p1[1] - t_y) * math.cos(teta)]
    p2 = [t_x + (p2[0] - t_x) * math.cos(teta) + (p2[1] - t_y) * math.sin(teta),
          t_y - (p2[0] - t_x) * math.sin(teta) + (p2[1] - t_y) * math.cos(teta)]
    p3 = [t_x + (p3[0] - t_x) * math.cos(teta) + (p3[1] - t_y) * math.sin(teta),
          t_y - (p3[0] - t_x) * math.sin(teta) + (p3[1] - t_y) * math.cos(teta)]
    p4 = [t_x + (p4[0] - t_x) * math.cos(teta) + (p4[1] - t_y) * math.sin(teta),
          t_y - (p4[0] - t_x) * math.sin(teta) + (p4[1] - t_y) * math.cos(teta)]
    rect[0] = QPointF(p1[0], p1[1])
    rect[1] = QPointF(p2[0], p2[1])
    rect[2] = QPointF(p3[0], p3[1])
    rect[3] = QPointF(p4[0], p4[1])
    scene.addPolygon(rect, pen=p, brush=b)
    l = len(epi_x)
    for i in range(l):
        x1 = t_x + (epi_x[i] - t_x) * math.cos(teta) + (epi_y[i] - t_y) * math.sin(teta)
        y1 = t_y - (epi_x[i] - t_x) * math.sin(teta) + (epi_y[i] - t_y) * math.cos(teta)
        epi_x[i] = x1
        epi_y[i] = y1
        scene.addLine(epi_x[i], epi_y[i], epi_x[i] + 0.01, epi_y[i] + 0.01, pen=p) 
Example 29
Project: kite   Author: pyrocko   File: tab_quadtree.py    License: GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, leaf):
        self.id = leaf.id
        QtCore.QRectF.__init__(
            self,
            QtCore.QPointF(leaf.llE, leaf.llN + leaf.sizeN),
            QtCore.QPointF(leaf.llE + leaf.sizeE, leaf.llN)) 
Example 30
Project: kite   Author: pyrocko   File: pyrocko.py    License: GNU General Public License v3.0 5 votes vote down vote up
def updateROIPosition(self):
            source = self.source
            vec_x, vec_y = self._vectorToCenter(source.strike)

            self.setAngle(-source.strike, finish=False)
            self.setPos(
                QtCore.QPointF(source.easting - vec_x,
                               source.northing - vec_y),
                finish=False)
            # self.setPos(QtCore.QPointF(source.easting, source.northing),
            #             finish=False)