Python PyQt5.QtCore.QPointF() Examples
The following are 30
code examples of PyQt5.QtCore.QPointF().
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 also want to check out all available functions/classes of the module
PyQt5.QtCore
, or try the search function
.
Example #1
Source File: view.py From eddy with GNU General Public License v3.0 | 6 votes |
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 #2
Source File: visual.py From stytra with GNU General Public License v3.0 | 6 votes |
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 #3
Source File: landBattleMap.py From imperialism-remake with GNU General Public License v3.0 | 6 votes |
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 #4
Source File: visual.py From stytra with GNU General Public License v3.0 | 6 votes |
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 #5
Source File: multiplot.py From kite with GNU General Public License v3.0 | 6 votes |
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
Source File: graphol.py From eddy with GNU General Public License v3.0 | 6 votes |
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 #7
Source File: graphml.py From eddy with GNU General Public License v3.0 | 6 votes |
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 #8
Source File: qt.py From eddy with GNU General Public License v3.0 | 6 votes |
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 #9
Source File: lab2.py From Computer-graphics with MIT License | 6 votes |
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 #10
Source File: lab2.py From Computer-graphics with MIT License | 6 votes |
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 #11
Source File: flujo.py From pychemqt with GNU General Public License v3.0 | 6 votes |
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 #12
Source File: lab2.py From Computer-graphics with MIT License | 6 votes |
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 #13
Source File: geometry.py From eddy with GNU General Public License v3.0 | 6 votes |
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 #14
Source File: quickplotter.py From phidl with MIT License | 6 votes |
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 #15
Source File: view.py From eddy with GNU General Public License v3.0 | 6 votes |
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 #16
Source File: diagram.py From eddy with GNU General Public License v3.0 | 6 votes |
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 #17
Source File: diagram.py From eddy with GNU General Public License v3.0 | 6 votes |
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 #18
Source File: graphol.py From eddy with GNU General Public License v3.0 | 5 votes |
def importAttributeNode(self, e): """ Build an Attribute node using the given QDomElement. :type e: QDomElement :rtype: AttributeNode """ label = self.getLabelFromElement(e) node = self.importGenericNode(Item.AttributeNode, e) node.setBrush(QtGui.QBrush(QtGui.QColor(e.attribute('color', '#fcfcfc')))) node.setText(label.text()) node.setTextPos(node.mapFromScene(QtCore.QPointF(int(label.attribute('x')), int(label.attribute('y'))))) return node
Example #19
Source File: graphml.py From eddy with GNU General Public License v3.0 | 5 votes |
def translateLabelPos(node): """ Translate the given label position in yEd coordinates. :type node: AbstractNode :rtype: QtCore.QPointF """ return node.label.pos() + \ QtCore.QPointF(node.width() / 2, node.height() / 2) - \ QtCore.QPointF(node.label.width() / 2, node.label.height() / 2) + \ QtCore.QPointF(2.0, 2.0)
Example #20
Source File: geometry.py From eddy with GNU General Public License v3.0 | 5 votes |
def midpoint(p1, p2): """ Calculate the midpoint between the given points. :type p1: QQPointF :type p2: QPointF :rtype: QPointF """ return QtCore.QPointF(((p1.x() + p2.x()) / 2), ((p1.y() + p2.y()) / 2))
Example #21
Source File: graphol.py From eddy with GNU General Public License v3.0 | 5 votes |
def importDomainRestrictionNode(self, d, e): """ Build a DomainRestriction node using the given QDomElement. :type d: Diagram :type e: QDomElement :rtype: DomainRestrictionNode """ x = e.firstChildElement('label') n = self.importGenericNode(d, Item.DomainRestrictionNode, e) n.setText(x.text()) n.setTextPos(n.mapFromScene(QtCore.QPointF(int(x.attribute('x')), int(x.attribute('y'))))) return n
Example #22
Source File: graphol.py From eddy with GNU General Public License v3.0 | 5 votes |
def importGenericEdge(self, d, i, e): """ Build an edge using the given item type and QDomElement. :type d: Diagram :type i: Item :type e: QDomElement :rtype: AbstractEdge """ points = [] point = e.firstChildElement('point') while not point.isNull(): points.append(QtCore.QPointF(int(point.attribute('x')), int(point.attribute('y')))) point = point.nextSiblingElement('point') edge = d.factory.create(i, **{ 'id': e.attribute('id'), 'source': self.buffer[d.name][e.attribute('source')], 'target': self.buffer[d.name][e.attribute('target')], 'breakpoints': points[1:-1] }) path = edge.source.painterPath() if path.contains(edge.source.mapFromScene(points[0])): edge.source.setAnchor(edge, points[0]) path = edge.target.painterPath() if path.contains(edge.target.mapFromScene(points[-1])): edge.target.setAnchor(edge, points[-1]) edge.source.addEdge(edge) edge.target.addEdge(edge) return edge
Example #23
Source File: graphol.py From eddy with GNU General Public License v3.0 | 5 votes |
def importConceptNode(self, d, e): """ Build a Concept node using the given QDomElement. :type d: Diagram :type e: QDomElement :rtype: ConceptNode """ x = e.firstChildElement('label') n = self.importGenericNode(d, Item.ConceptNode, e) n.setBrush(QtGui.QBrush(QtGui.QColor(e.attribute('color', '#fcfcfc')))) n.setText(x.text()) n.setTextPos(n.mapFromScene(QtCore.QPointF(int(x.attribute('x')), int(x.attribute('y'))))) return n
Example #24
Source File: graphol.py From eddy with GNU General Public License v3.0 | 5 votes |
def importRoleNode(self, e): """ Build a Role node using the given QDomElement. :type e: QDomElement :rtype: RoleNode """ label = self.getLabelFromElement(e) node = self.importGenericNode(Item.RoleNode, e) node.setBrush(QtGui.QBrush(QtGui.QColor(e.attribute('color', '#fcfcfc')))) node.setText(label.text()) node.setTextPos(node.mapFromScene(QtCore.QPointF(int(label.attribute('x')), int(label.attribute('y'))))) return node
Example #25
Source File: graphol.py From eddy with GNU General Public License v3.0 | 5 votes |
def importGenericNode(self, item, e): """ Build a node using the given item type and QDomElement. :type item: Item :type e: QDomElement :rtype: AbstractNode """ geometry = self.getGeometryFromElement(e) node = self.diagram.factory.create(item, **{ '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
Example #26
Source File: graphol.py From eddy with GNU General Public License v3.0 | 5 votes |
def importGenericEdge(self, item, e): """ Build an edge using the given item type and QDomElement. :type item: Item :type e: QDomElement :rtype: AbstractEdge """ points = [] point = self.getPointInsideElement(e) while not point.isNull(): points.append(QtCore.QPointF(int(point.attribute('x')), int(point.attribute('y')))) point = self.getPointBesideElement(point) edge = self.diagram.factory.create(item, **{ 'id': e.attribute('id'), 'source': self.nodes[e.attribute('source')], 'target': self.nodes[e.attribute('target')], 'breakpoints': points[1:-1] }) path = edge.source.painterPath() if path.contains(edge.source.mapFromScene(points[0])): edge.source.setAnchor(edge, points[0]) path = edge.target.painterPath() if path.contains(edge.target.mapFromScene(points[-1])): edge.target.setAnchor(edge, points[-1]) edge.source.addEdge(edge) edge.target.addEdge(edge) return edge
Example #27
Source File: graphol.py From eddy with GNU General Public License v3.0 | 5 votes |
def importConceptNode(self, e): """ Build a Concept node using the given QDomElement. :type e: QDomElement :rtype: ConceptNode """ label = self.getLabelFromElement(e) node = self.importGenericNode(Item.ConceptNode, e) node.setBrush(QtGui.QBrush(QtGui.QColor(e.attribute('color', '#fcfcfc')))) node.setText(label.text()) node.setTextPos(node.mapFromScene(QtCore.QPointF(int(label.attribute('x')), int(label.attribute('y'))))) return node
Example #28
Source File: graphol.py From eddy with GNU General Public License v3.0 | 5 votes |
def importDomainRestrictionNode(self, e): """ Build a DomainRestriction node using the given QDomElement. :type e: QDomElement :rtype: DomainRestrictionNode """ label = self.getLabelFromElement(e) node = self.importGenericNode(Item.DomainRestrictionNode, e) node.setText(label.text()) node.setTextPos(node.mapFromScene(QtCore.QPointF(int(label.attribute('x')), int(label.attribute('y'))))) return node
Example #29
Source File: graphol.py From eddy with GNU General Public License v3.0 | 5 votes |
def importRangeRestrictionNode(self, e): """ Build a RangeRestriction node using the given QDomElement. :type e: QDomElement :rtype: RangeRestrictionNode """ label = self.getLabelFromElement(e) node = self.importGenericNode(Item.RangeRestrictionNode, e) node.setText(label.text()) node.setTextPos(node.mapFromScene(QtCore.QPointF(int(label.attribute('x')), int(label.attribute('y'))))) return node
Example #30
Source File: graphol.py From eddy with GNU General Public License v3.0 | 5 votes |
def importValueDomainNode(self, e): """ Build a Value-Domain node using the given QDomElement. :type e: QDomElement :rtype: ValueDomainNode """ label = self.getLabelFromElement(e) node = self.importGenericNode(Item.ValueDomainNode, e) node.setBrush(QtGui.QBrush(QtGui.QColor(e.attribute('color', '#fcfcfc')))) node.setText(label.text()) node.setTextPos(node.mapFromScene(QtCore.QPointF(int(label.attribute('x')), int(label.attribute('y'))))) return node