def createNetPath(self, brushColor: str, painterPath: QPainterPath, isOccupyPathItem: bool): """ Create a QGraphicsPathItem for a network path Args: brushColor (str) : The color for filling the rectangles painterPath (QPainterPath) : The path to be inserted to the item isOccupyPathItem (bool) : Whether the path is occupied or unoccupied path """ # Generate the path item if not created if isOccupyPathItem: if self.occupiedPathItem is None: self.occupiedPathItem = QGraphicsPathItem(self) pathItem = self.occupiedPathItem else: if self.unoccupiedPathItem is None: self.unoccupiedPathItem = QGraphicsPathItem(self) pathItem = self.unoccupiedPathItem if pathItem is None: pathItem = QGraphicsPathItem(self) # Set the item parameters pathItem.setPath(painterPath) pathItem.setPen( QPen(QColor(self.netColor), self.netThickness, style=Qt.SolidLine)) pathItem.setBrush(QBrush(QColor(brushColor))) pathItem.setZValue(0)
def __init__(self): super(Canvas, self).__init__() global scene scene = QGraphicsScene() self.setScene(scene) self.path1 = QPainterPath() self.path2 = QPainterPath() global viewport viewport = self.viewport() global new_path new_path = QPainterPath() global pathitem1, pathitem2, new_pathitem pathitem1 = QGraphicsPathItem() pathitem2 = QGraphicsPathItem() new_pathitem = QGraphicsPathItem() global pen pen = QPen(Qt.black, 10) pathitem1.setPen(pen) eraser = QPen(Qt.white, 10) pathitem2.setPen(eraser) global item item = pathitem1 scene.addItem(item)
def __init__(self, from_virtual_helix_item: PathVirtualHelixItemT, is_fwd: bool, from_index: int, nearby_idxs: List[int], to_vh_id_num: int, prexoveritem_manager: PreXoverManagerT): """Summary Args: from_virtual_helix_item: Description is_fwd: is this a forward strand? from_index: index of the Virtual Helix this xover is coming from nearby_idxs: to_vh_id_num: Virtual Helix number this Xover point might connect to prexoveritem_manager: Manager of the PreXoverItems """ super(QGraphicsRectItem, self).__init__(BASE_RECT, from_virtual_helix_item) self.adapter = PropertyWrapperObject(self) self._tick_marks = QGraphicsPathItem(self) self._tick_marks.setAcceptHoverEvents(True) self._bond_item = QGraphicsPathItem(self) self._bond_item.hide() self._label = PreXoverLabel(is_fwd, self) self._path = QGraphicsPathItem() self.setZValue(styles.ZPREXOVERITEM) self.setPen(getNoPen()) self.resetItem(from_virtual_helix_item, is_fwd, from_index, nearby_idxs, to_vh_id_num, prexoveritem_manager) self._getActiveTool = from_virtual_helix_item.viewroot( ).manager.activeToolGetter
def get_elements(self, cell, height): result = [] current = [] rectangles = self.doc.elementsByTagName('rect') for i in range(rectangles.size()): rect = rectangles.item(i).toElement() fill = '#aaaaaa' item = QGraphicsRectItem(float(rect.attribute('x')), float(rect.attribute('y')), float(rect.attribute('width')), float(rect.attribute('height'))) item.setBrush(QBrush(QColor(fill))) result.append(item) if rect.attribute('id') == str(cell): side_fill = fill size = item.rect().getRect() for j in range(1, height+1): x = size[0] - 12 * j y = size[1] - 20 * j if j == height: side_fill = '#ff0000' top = QGraphicsRectItem(x, y, size[2], size[3]) top.setBrush(QBrush(QColor(fill).darker(200))) current.append(top) path = QPainterPath() path.moveTo(x + size[2], y + size[3]) path.lineTo(x + size[2] + 12, y + size[3] + 20) path.lineTo(x + 12, y + size[3] + 20) path.lineTo(x, y + size[3]) front = QGraphicsPathItem(path) front.setBrush(QBrush(QColor(side_fill))) current.append(front) path = QPainterPath() path.moveTo(x + size[2], y + size[3]) path.lineTo(x + size[2] + 12, y + size[3] + 20) path.lineTo(x + size[2] + 12, y + 20) path.lineTo(x + size[2], y) right = QGraphicsPathItem(path) right.setBrush(QBrush(QColor(side_fill).lighter())) current.append(right) return result + current
def __init__(self, radius: float, center_x: float, center_y: float, start_angle: float, end_angle: float, clockwise, line_width: float, line_color=Qt.black, fill_color=Qt.transparent): super().__init__() # The supporting rectangle if end_angle < start_angle: end_angle += 2 * math.pi start_angle = -start_angle end_angle = -end_angle shift = end_angle - start_angle if clockwise: shift = -shift - 2 * math.pi x, y = center_x - radius, center_y - radius self.rect = QRectF(x, y, 2 * radius, 2 * radius) # The underlying QGraphicsPathItem self.painter_path = QPainterPath( QPointF(center_x + math.cos(start_angle) * radius, center_y - math.sin(start_angle) * radius)) self.painter_path.arcTo(self.rect, math.degrees(start_angle), math.degrees(shift)) self.path = QGraphicsPathItem(self.painter_path) self.path.setBrush(QtGui.QBrush(fill_color)) pen = QPen() pen.setWidthF(line_width) pen.setColor(line_color) self.path.setPen(pen) self._visible = 1
def visualize(self): """ called when user clicks draw lsystem. This visualizes the lsystem to allow setup before the actual lsystification takes place """ self.getdata() self.run_lsystem() old_group = self.layersModel.itemFromIndex( self.parent.layersList.currentIndex()).get_graphics_items_group() if old_group: self.parent.scene.removeItem(old_group) group = QGraphicsItemGroup() path = QPainterPath() for idx, point in enumerate( self.lsysteminterpreter.globalstate["pts"]): x = point[0][0][0] y = point[0][1][0] direction = point[1] x = x * self.xscale + self.xoffs y = y * self.yscale + self.yoffs if idx == 0: path.moveTo(x, y) else: path.lineTo(x, y) item = QGraphicsPathItem(path) pen = QPen() pen.setWidth(self.strokeWidth) item.setPen(pen) group.addToGroup(item) self.addNewGraphicsItems(group)
def _initLabel(self): """Display the length of the insertion.""" self._label = InsertionLabel(self) self._seq_item = QGraphicsPathItem(parent=self) self._seq_text = None self.show()
def addPath(self): self.removePath() self.path = QGraphicsPathItem(self.sideWays.setPaintPath(True)) self.path.setPen(QPen(QColor(self.color), 3, Qt.DashDotLine)) self.path.setZValue(common['pathZ']) self.scene.addItem(self.path) self.pathSet = True
def mousePressEvent(self, evt: QtGui.QMouseEvent) -> None: image_rect : QRectF=self._pixmap.boundingRect() mouse_pos = self.mapToScene(evt.pos()) if evt.buttons() == QtCore.Qt.LeftButton: if self.current_tool == SELECTION_TOOL.BOX: # create rectangle self.setDragMode(QGraphicsView.NoDrag) self._rectangle_tool_origin=evt.pos() geometry = QRect(self._rectangle_tool_origin,QSize()) self._rectangle_tool_picker.setGeometry(geometry) self._rectangle_tool_picker.show() elif self.current_tool == SELECTION_TOOL.POLYGON: if image_rect.contains(mouse_pos): if self._current_polygon is None: self._current_polygon=EditablePolygon() self._current_polygon.label = self._current_label self._current_polygon.tag = self._dataset self._current_polygon.signals.deleted.connect(self.delete_polygon_slot) self._scene.addItem(self._current_polygon) self._current_polygon.addPoint(mouse_pos) else: self._current_polygon.addPoint(mouse_pos) elif self.current_tool == SELECTION_TOOL.ELLIPSE: if image_rect.contains(mouse_pos): self.setDragMode(QGraphicsView.NoDrag) ellipse_rec=QtCore.QRectF(mouse_pos.x(),mouse_pos.y(),0,0) self._current_ellipse=EditableEllipse() self._current_ellipse.tag = self.dataset self._current_ellipse.label=self._current_label self._current_ellipse.setRect(ellipse_rec) self._scene.addItem(self._current_ellipse) elif self.current_tool == SELECTION_TOOL.FREE: # consider only the points into the image if image_rect.contains(mouse_pos): self.setDragMode(QGraphicsView.NoDrag) self._last_point_drawn=mouse_pos self._current_free_path=QGraphicsPathItem() self._current_free_path.setOpacity(0.6) self._current_free_path.setPen(self._free_Path_pen) painter=QPainterPath() painter.moveTo(self._last_point_drawn) self._current_free_path.setPath(painter) self._scene.addItem(self._current_free_path) elif self.current_tool == SELECTION_TOOL.EXTREME_POINTS: if image_rect.contains(mouse_pos): if not self._extreme_points.full(): def delete_point(idx): del self._extreme_points.queue[idx] idx=self._extreme_points.qsize() editable_pt=EditablePolygonPoint(idx) editable_pt.signals.deleted.connect(delete_point) editable_pt.setPos(mouse_pos) self._scene.addItem(editable_pt) self._extreme_points.put(editable_pt) else: self.setDragMode(QGraphicsView.ScrollHandDrag) super(ImageViewer, self).mousePressEvent(evt)
def __init__(self, parent=None, **kwargs): Annotation.__init__(self, parent, **kwargs) self.setFlag(QGraphicsItem.ItemIsMovable) self.setFlag(QGraphicsItem.ItemIsSelectable) self.setFocusPolicy(Qt.ClickFocus) self.__textMargins = (2, 2, 2, 2) rect = self.geometry().translated(-self.pos()) ################################ # PyQt 5.10 crashes because of this call (3) #self.__framePathItem = QGraphicsPathItem(self) self.__framePathItem = QGraphicsPathItem(None) self.__framePathItem.setPen(QPen(Qt.NoPen)) self.__textItem = GraphicsTextEdit(self) self.__textItem.setPlaceholderText(self.tr("Enter text here")) self.__textItem.setPos(2, 2) self.__textItem.setTextWidth(rect.width() - 4) self.__textItem.setTabChangesFocus(True) self.__textItem.setTextInteractionFlags(Qt.NoTextInteraction) self.__textItem.setFont(self.font()) self.__textInteractionFlags = Qt.NoTextInteraction layout = self.__textItem.document().documentLayout() layout.documentSizeChanged.connect(self.__onDocumentSizeChanged) self.__updateFrame()
def __init__(self, part_item, grid_type): """Summary previous_grid_bounds (tuple): a tuple corresponding to the bounds of the grid. Args: part_item (TYPE): Description grid_type (TYPE): Description """ super(GridItem, self).__init__(parent=part_item) self.setFlag(QGraphicsItem.ItemClipsChildrenToShape) self._path = None self.part_item = part_item self._path = QGraphicsPathItem(self) self.dots = (styles.DOT_SIZE, styles.DOT_SIZE / 2) # self.allow_snap = part_item.window().action_vhelix_snap.isChecked() self._draw_gridpoint_coordinates = False self.draw_lines = False self.points = [] self.points_dict = dict() self.previous_grid_bounds = None self.bounds = None self.grid_type = None self.setPen( getPenObj(styles.GRAY_STROKE, styles.EMPTY_HELIX_STROKE_WIDTH)) self.setGridType(grid_type) self.previous_grid_type = grid_type
def __init__(self, virtual_helix_item, xover_item, strand3p, idx): """Summary Args: virtual_helix_item (cadnano.views.pathview.virtualhelixitem.VirtualHelixItem): from vhi xover_item (TYPE): Description strand3p (Strand): reference to the 3' strand idx (int): the base index within the virtual helix """ super(ForcedXoverNode3, self).__init__(virtual_helix_item) self._vhi = virtual_helix_item self._xover_item = xover_item self._idx = idx self.is_forward = strand3p.strandSet().isForward() self._is_on_top = self.is_forward self._partner_virtual_helix = virtual_helix_item self._blank_thing = QGraphicsRectItem(_blankRect, self) self._blank_thing.setBrush(QBrush(Qt.white)) self._path_thing = QGraphicsPathItem(self) self.configurePath() self._label = None self.setPen(_NO_PEN) self.setBrush(_NO_BRUSH) self.setRect(_rect) self.setZValue(styles.ZENDPOINTITEM + 1)
def __init__(self, *args, **kwargs): KineticsDisplayItem.__init__(self, *args, **kwargs) points = [ QtCore.QPointF(0, TableItem.defaultWidth / 2), QtCore.QPointF(TableItem.defaultHeight / 2 - 2, 0), QtCore.QPointF(TableItem.defaultWidth / 2 + 2, 0), QtCore.QPointF(TableItem.defaultWidth, TableItem.defaultHeight / 2), ] path = QtGui.QPainterPath() path.moveTo(points[0]) for p in points[1:]: path.lineTo(p) path.moveTo(p) path.moveTo(0, 0) path.lineTo(TableItem.defaultWidth, 0) path.moveTo(-(TableItem.defaultWidth / 3), TableItem.defaultHeight / 4) path.lineTo((TableItem.defaultWidth + 10), TableItem.defaultHeight / 4) self.gobj = QGraphicsPathItem(path, self) #self.gobj.setToolTip("Need to see what to show unlike conc/nint for pool") tabledoc = (moose.element(self.mobj.path)).outputValue self.gobj.setToolTip(str(tabledoc)) self.gobj.setPen( QtGui.QPen(QtCore.Qt.black, 2, Qt.Qt.SolidLine, Qt.Qt.RoundCap, Qt.Qt.RoundJoin)) self.gobj.mobj = self.mobj
def drawGlyph(self, scene, glyph, offsetX=0, offsetY=0, color=(255, 255, 255)): path = QPainterPath() path.setFillRule(Qt.WindingFill) for c in self.decomposedPaths(glyph): segs = c.segments path.moveTo(segs[-1].points[-1].x, segs[-1].points[-1].y) for seg in segs: tuples = [(a.x, a.y) for a in seg.points] flattuples = list(sum(tuples, ())) if len(tuples) == 2: path.quadTo(*flattuples) elif len(tuples) == 3: path.cubicTo(*flattuples) else: path.lineTo(*flattuples) line = QGraphicsPathItem() line.setBrush(QColor(*color)) p = QPen() p.setStyle(Qt.NoPen) line.setPen(p) line.setPath(path) reflect = QTransform(1, 0, 0, -1, 0, 0) reflect.translate(offsetX, offsetY) # print(f"Drawing {glyph} at offset {offsetX} {offsetY}") line.setTransform(reflect) scene.addItem(line)
def small_size(self): global item, new_pathitem, new_path pen.setWidth(5) new_pathitem = QGraphicsPathItem() new_pathitem.setPen(pen) new_path = QPainterPath() item = new_pathitem scene.addItem(item)
def updateNewPath(self): if self.pts: ## list of points self.removeNewPath() ## clean up just in case self.newPath = QGraphicsPathItem(self.sideWays.setPaintPath()) self.newPath.setPen(QPen(QColor(self.color), 3, Qt.DashDotLine)) self.newPath.setZValue(common['pathZ']) self.scene.addItem(self.newPath) ## only one - no group needed self.newPathSet = True
def colour(self): global item, new_pathitem, new_path pen.setColor(QColorDialog.getColor()) new_pathitem = QGraphicsPathItem() new_pathitem.setPen(pen) new_path = QPainterPath() item = new_pathitem scene.addItem(item)
def addPainterPath(self, tag): color = getColorStr() path = sidePath.pathLoader(tag) ## return painter path pathPt = path.pointAtPercent(0.0) ## so its consistent ## use painter path pathItem = QGraphicsPathItem(path) pathItem.setPen(QPen(QColor(color), 3, Qt.DashDotLine)) pathItem.setFlag(QGraphicsPathItem.ItemIsMovable, False) self.pathGroup.addToGroup(pathItem) self.addTag(tag, color, pathPt)
def __init__(self, parent: QGraphicsItem = None): """ Args: parent: default is ``None`` """ super(PathWorkplaneOutline, self).__init__(parent) self.setPen(getNoPen()) self._path = QGraphicsPathItem(self) self._path.setBrush(getNoBrush()) self._path.setPen(newPenObj(styles.BLUE_STROKE, 0))
def loadfrom(self): global filename, item, new_path, new_pathitem filename = QFileDialog.getOpenFileName(None, 'Choose file')[0] pixmap = QPixmap(filename) scene.addPixmap(pixmap) new_pathitem = QGraphicsPathItem() new_pathitem.setPen(pen) new_path = QPainterPath() item = new_pathitem scene.addItem(item)
def finish(self): """ return the wrapped up result of the calculations :return: qgraphicsitemgroup """ item = QGraphicsPathItem(self.path) pen = QPen() pen.setWidth(self.strokeWidth) item.setPen(pen) self.group.addToGroup(item) self.prevPos = None return self.group
def __init__(self, from_virtual_helix_item, is_fwd, from_index, nearby_idxs, to_vh_id_num, prexoveritem_manager): """Summary Args: from_virtual_helix_item (cadnano.views.pathview.virtualhelixitem.VirtualHelixItem): Description is_fwd (TYPE): Description from_index (TYPE): Description to_vh_id_num (TYPE): Description prexoveritem_manager (TYPE): Description """ super(QGraphicsRectItem, self).__init__(BASE_RECT, from_virtual_helix_item) self.adapter = PropertyWrapperObject(self) self._tick_marks = QGraphicsPathItem(self) self._tick_marks.setAcceptHoverEvents(True) self._bond_item = QGraphicsPathItem(self) self._bond_item.hide() self._label = PreXoverLabel(is_fwd, self) self._path = QGraphicsPathItem() self.setZValue(styles.ZPREXOVERITEM) self.setPen(getNoPen()) self.resetItem(from_virtual_helix_item, is_fwd, from_index, nearby_idxs, to_vh_id_num, prexoveritem_manager)
def show_shape(item): """Highlight the shape of item.""" sh = QGraphicsPathItem() path = item.shape() # The shape path was returned in the item's coordinates # FIXME: translate is not enough when itemIgnoresTranformation path.translate(item.scenePos()) sh.setPath(path) pen = QPen(Qt.magenta, 1.5, Qt.DashLine) pen.setCosmetic(True) # thickness does not scale sh.setPen(pen) item.scene().addItem(sh) return sh
def __init__(self, node1, node2, engine, cost=None): super().__init__() self.node1 = node1 self.node2 = node2 self.engine = engine self.cost = cost self.arrow_length = 15 self.setPen(self.node1.pen) # Crearea unui path invizibil si adaugarea lui in scene self.direct_path = QGraphicsPathItem() self.direct_path.setPen(QPen(QColor(0, 0, 0, 0))) self.engine.view.scene.addItem(self.direct_path)
def initCharPath(self): """ Init the item that holds the character There is one path item that holds the character This method is activated by start line if the char item was not created to create the new and only one """ self.dirty = True self.charPath = QGraphicsPathItem(self) self.charPath.setPen( QPen(QColor(self.shapeColor), self.shapeLineThickness)) self.charPath.setZValue(1) self.charPath.originalPos = self.charPath.pos() self.charPath.setPath(QPainterPath())
def drawCross(self, scene, x, y, color): path = QPainterPath() path.moveTo(x - 50, y) path.lineTo(x + 50, y) path.moveTo(x, y - 50) path.lineTo(x, y + 50) line = QGraphicsPathItem() p = QPen(QColor(*color)) p.setWidth(5) line.setPen(p) line.setPath(path) reflect = QTransform(1, 0, 0, -1, 0, 0) line.setTransform(reflect) scene.addItem(line)
def __init__(self, virtual_helix_item, strand, insertion): super(InsertionItem, self).__init__(virtual_helix_item) self.hide() self._strand = strand self._insertion = insertion self._seq_item = QGraphicsPathItem(parent=self) self._is_on_top = is_on_top = virtual_helix_item.isStrandOnTop(strand) y = 0 if is_on_top else _BW self.setPos(_BW * insertion.idx(), y) self.setZValue(styles.ZINSERTHANDLE) self._initLabel() self._initClickArea() self.updateItem() self.show()
def _initLabel(self): """Display the length of the insertion.""" self._label = label = QGraphicsTextItem("", parent=self) label.setFont(_font) label.setTextInteractionFlags(Qt.TextEditorInteraction) label.inputMethodEvent = self.inputMethodEventHandler label.keyPressEvent = self.textkeyPressEvent label.mousePressEvent = self.labelMousePressEvent label.mouseDoubleClickEvent = self.mouseDoubleClickEvent label.setTextWidth(-1) self._label = label self._seqItem = QGraphicsPathItem(parent=self) self._seqText = None self.updateItem() self.show()
def mousePressEvent(self, evt: QtGui.QMouseEvent) -> None: if evt.buttons() == QtCore.Qt.LeftButton: if self.selection_mode == SELECTION_MODE.BOX: self.setDragMode(QGraphicsView.NoDrag) self._box_origin = evt.pos() self._box_picker.setGeometry(QRect(self._box_origin, QSize())) self._box_picker.show() elif self._selection_mode == SELECTION_MODE.POLYGON: pixmap_rect: QRectF = self._pixmap.boundingRect() new_point = self.mapToScene(evt.pos()) # consider only the points intothe image if pixmap_rect.contains(new_point): if self._current_polygon is None: self._current_polygon = EditablePolygon() self._current_polygon.signals.deleted.connect( self.delete_polygon_slot) self._scene.addItem(self._current_polygon) self._current_polygon.addPoint(new_point) else: self._current_polygon.addPoint(new_point) elif self._selection_mode == SELECTION_MODE.FREE: # start drawing new_point = self.mapToScene(evt.pos()) pixmap_rect: QRectF = self._pixmap.boundingRect() # consider only the points intothe image if pixmap_rect.contains(new_point): self.setDragMode(QGraphicsView.NoDrag) pen = QPen(QtGui.QColor(235, 72, 40)) pen.setWidth(10) self._last_point_drawn = new_point self._current_free_path = QGraphicsPathItem() self._current_free_path.setOpacity(0.6) self._current_free_path.setPen(pen) painter = QPainterPath() painter.moveTo(self._last_point_drawn) self._current_free_path.setPath(painter) self._scene.addItem(self._current_free_path) else: self.setDragMode(QGraphicsView.ScrollHandDrag) super(ImageViewer, self).mousePressEvent(evt)
def __init__(self, isCrack, he, parent=None): super(createDiscretionWindow, self).__init__(parent) self.highlight = QGraphicsPathItem() self.highlight.setPath(he) pen = QPen(Qt.red, 2) self.highlight.setPen(pen) self.highlight.setZValue(1) self.parent().scene.addItem(self.highlight) self.setupUi(self) self.move(1450, -1) self.isCrack = isCrack self.lineEdit_number_of_elements.setFocus(True) self.lineEdit_number_of_elements.textChanged.connect(self.change_number_of_discontinous_elements) self.radioButton_2.toggled.connect(self.setDiscontinousBoxState) if self.isCrack == True: self.checkBox_isCrack.setChecked(True) self.radioButton_2.setChecked(True) self.checkBox_isCrack.setEnabled(False) self.groupBox_type_of_discretization.setEnabled(False)