예제 #1
0
    def hoverLeaveEvent(self, event):

        # turn connection highlighting off
        self.parent_node_instance.flow.hovered_port_inst_gate = None
        self.parent_node_instance.flow.update()

        QGraphicsItem.hoverLeaveEvent(self, event)
예제 #2
0
 def hoverEnterEvent(self, event):
     if self.parent_port_instance.type_ == 'data' and self.parent_port_instance.direction == 'output':
         self.setToolTip(
             shorten(str(self.parent_port_instance.val),
                     1000,
                     line_break=True))
     QGraphicsItem.hoverEnterEvent(self, event)
예제 #3
0
 def mouseDoubleClickEvent(
         self, event: PySide2.QtWidgets.QGraphicsSceneMouseEvent):
     print('double clicked')
     print(event.pos())
     print(self.scenePos())
     print(self.pos())
     QGraphicsItem.mouseDoubleClickEvent(self, event)
예제 #4
0
    def __init__(self, action: 'Action', parent=None) -> 'ActionGraphics':
        """
		Constructs a Action Graphics object for the given action.
		
		:param action: The action for which this graphics item represents.
		:type action: Action
		:param parent: None
		:type parent: NoneType
		:return: The graphics of an action.
		:rtype: ActionGraphics
		"""
        QGraphicsItem.__init__(self, parent)
        self.setFlag(QGraphicsItem.ItemIsSelectable)
        self.setCursor(Qt.ArrowCursor)
        self._action = action
        QObject.connect(action, SIGNAL('updated()'), self.updateGraphics)

        self.color = ActionGraphics.COLOR

        self._inputPortGraphics = []
        self._outputPortGraphics = []
        self._wireGraphics = []
        self._actionGraphics = []

        self._inputPortMapping = {}
        self._outputPortMapping = {}

        self._interactivePorts = True
        ActionGraphics.updateGraphics(self)

        self._width = 0
        self._height = 0
예제 #5
0
    def _finalize_gfx(self,
                      gfx: QGraphicsItem,
                      timeout: int,
                      group: Optional[str] = None):
        timeout = min(20000, max(timeout, 1))

        if group is None:
            group = self.current_group

        if group in self.frozen_group:
            self.frozen_group[group].addToGroup(gfx)
        else:
            self.groups[group].append(gfx)
            gfx.setParentItem(self.overlay_area)

        def hide():
            try:
                gfx.scene().removeItem(gfx)
            except AttributeError:
                pass

            try:
                self.groups[group].remove(gfx)
            except (KeyError, ValueError):
                pass

        QTimer.singleShot(timeout, hide)
예제 #6
0
 def __init__(self, chart):
     QGraphicsItem.__init__(self, chart)
     self._chart = chart
     self._text = ""
     self._textRect = QRectF()
     self._anchor = QPointF()
     self._font = QFont()
     self._rect = QRectF()
예제 #7
0
 def __init__(self, chart):
     QGraphicsItem.__init__(self, chart)
     self._chart = chart
     self._text = ""
     self._textRect = QRectF()
     self._anchor = QPointF()
     self._font = QFont()
     self._rect = QRectF()
예제 #8
0
    def __init__(self, chart):
        QGraphicsItem.__init__(self, chart)

        self.chart = chart
        self.rect = QRectF()
        self.anchor = QPointF()
        self.text_rect = QRectF()
        self.text = ""
        self.font = QFont()
예제 #9
0
    def __init__(self, color: QColor, x: int, y: int, parent=None):
        QGraphicsItem.__init__(self, parent)
        self.x = x
        self.y = y
        self.color = color
        self.stuff = []
        self.setZValue((x + y) % 2)

        self.setFlags(self.ItemIsSelectable | self.ItemIsMovable)
        self.setAcceptHoverEvents(True)
예제 #10
0
    def __init__(self, parent=None):
        QGraphicsItem.__init__(self, parent)

        self.positionX = 0
        self.positionY = 0
        self.width = 0
        self.height = 0
        self.paintPen = QPen(Qt.GlobalColor.lightGray)
        self.paintPen.setWidth(5)

        self.backColor = Qt.GlobalColor.lightGray
        self.backImageStr = None
예제 #11
0
    def __init__(self, parent: 'ActionPipelineGraphics'):
        """
		Constructs a ConnectionIndicator class
		
		:param parent: The ActionPipelineGraphics class that the indicator belongs to.
		:type parent: ActionPipelineGraphics
		"""
        QGraphicsItem.__init__(self, parent)
        self._srcPoint = QPointF(0, 0)
        self._destPoint = QPointF(0, 0)
        self.setZValue(100)  # stack on top of all siblings
        self.color = ConnectionIndicator.BASE_COLOR
예제 #12
0
    def hoverEnterEvent(self, event):
        if self.parent_port_instance.type_ == 'data' and self.parent_port_instance.direction == 'output':
            self.setToolTip(
                shorten(str(self.parent_port_instance.val),
                        1000,
                        line_break=True))

        # hover all connections
        self.parent_node_instance.flow.hovered_port_inst_gate = self
        self.parent_node_instance.flow.update()

        QGraphicsItem.hoverEnterEvent(self, event)
예제 #13
0
 def itemChange(self, change, value):
     if change == self.ItemPositionChange:
         scene_pos = self.scenePos()
         main_window = self.parent().parent().parent()
         main_window.item_pos.setText(f"({round(scene_pos.x(), 1)},"
                                      f" {round(scene_pos.y(), 1)})")
         return value
     if change == self.ItemSelectedHasChanged:
         if value:
             if len(self.scene().selectedItems()) == 1:
                 self.parent().init_font_settings(self)
                 scene_pos = self.scenePos()
                 main_window = self.parent().parent().parent()
                 main_window.item_pos.setText(
                     f"({round(scene_pos.x(), 1)}, "
                     f"{round(scene_pos.y(), 1)})")
             else:
                 self.parent().layout.setCurrentWidget(self.parent().tabs)
         else:
             cursor = self.textCursor()
             cursor.clearSelection()
             self.setTextCursor(cursor)
             self.parent().layout.setCurrentWidget(self.parent().tabs)
             self.setTextInteractionFlags(Qt.NoTextInteraction)
             self.setFlags(QGraphicsTextItem.ItemIsSelectable
                           | QGraphicsTextItem.ItemIsMovable
                           | QGraphicsTextItem.ItemSendsScenePositionChanges
                           | QGraphicsTextItem.ItemIsFocusable)
             main_window = self.parent().parent().parent()
             main_window.item_pos.setText("")
     return QGraphicsItem.itemChange(self, change, value)
    def itemChange(self, change: QGraphicsItem.GraphicsItemChange, value: typing.Any) -> typing.Any:
        if change is QGraphicsItem.ItemPositionHasChanged:
            for bezierEdge in self.__bezierEdgeList:
                for edge in bezierEdge.keys():
                    edge.adjust()

        return QGraphicsItem.itemChange(self, change, value)
예제 #15
0
 def itemChange(self,
                change: PySide2.QtWidgets.QGraphicsItem.GraphicsItemChange,
                value: typing.Any) -> typing.Any:
     if change is QGraphicsItem.ItemPositionHasChanged:
         for edge in self.egdes:
             edge.adjust()
     return QGraphicsItem.itemChange(self, change, value)
예제 #16
0
 def mouseReleaseEvent(self, event):
     """Used for Moving-Commands in Flow - may be replaced later with a nicer determination of a move action."""
     if self.movement_state == MovementEnum.position_changed:
         self.flow.selected_components_moved(self.pos() -
                                             self.movement_pos_from)
     self.movement_state = None
     return QGraphicsItem.mouseReleaseEvent(self, event)
예제 #17
0
    def itemChange(self, change, value):
        if change == QGraphicsItem.ItemPositionChange:
            self.flow.viewport().update()
            if self.movement_state == MovementEnum.mouse_clicked:
                self.movement_state = MovementEnum.position_changed

        return QGraphicsItem.itemChange(self, change, value)
예제 #18
0
    def shape(self) -> QPainterPath:
        """
		Defines the shape of the action icon.
		
		:return: Returns the shape of the action icon.
		:rtype: QPainterPath
		"""
        return QGraphicsItem.shape(self)
예제 #19
0
    def __init__(self,
                 port: 'Port',
                 parent: QGraphicsItem = None,
                 menuEnabled: bool = True):
        """
		Constructs a portGraphics object for the given Port object.
		
		:param port: The port for which this graphics item represents.
		:type port: Port
		:param parent: A QGraphicsItem (probably an actionGraphics object)
		:type parent: QGraphicsItem
		:param menuEnabled: If true, a context menu will be shown on right-click.
		:type menuEnabled: bool
		"""
        QGraphicsItem.__init__(self, parent)
        self.setAcceptDrops(True)
        self.setFlag(QGraphicsItem.ItemIsSelectable)
        self._port = port
        self._menuEnabled = menuEnabled
        self.menu = PortMenu()

        # If port is required and it's an input, make the border thicker
        if not self._port.isOptional() and self._port in self._port.getAction(
        ).getInputPorts():
            self.borderWidth = PortGraphics.REQUIRED_PEN_WIDTH
        else:
            self.borderWidth = PortGraphics.OPTIONAL_PEN_WIDTH

        # show port name and type
        if self._menuEnabled:
            fm = QFontMetricsF(PortGraphics.NAME_FONT)
            name = fm.elidedText(self._port.getName(), Qt.ElideRight,
                                 PortGraphics.SIDE_HEIGHT)
            self.nameItem = QGraphicsTextItem(name, self)
            self.nameItem.setFont(PortGraphics.NAME_FONT)
            self.nameItem.setRotation(90)
            self.nameItem.setPos(PortGraphics.WIDTH / 2 + 5,
                                 -PortGraphics.TOTAL_HEIGHT / 2)

            fm = QFontMetricsF(PortGraphics.TYPE_FONT)
            t = fm.elidedText(self._port.getDataType().__name__, Qt.ElideRight,
                              PortGraphics.SIDE_HEIGHT)
            self.typeItem = QGraphicsTextItem(t, self)
            self.typeItem.setFont(PortGraphics.TYPE_FONT)
            self.typeItem.setRotation(90)
            self.typeItem.setPos(5, -PortGraphics.TOTAL_HEIGHT / 2)
예제 #20
0
    def update_design(self):
        """Loads the shadow effect option and causes redraw with active theme."""

        if Design.node_instance_shadows_shown:
            self.shadow_effect = QGraphicsDropShadowEffect()
            self.shadow_effect.setXOffset(12)
            self.shadow_effect.setYOffset(12)
            self.shadow_effect.setBlurRadius(20)
            self.shadow_effect.setColor(QColor('#2b2b2b'))
            self.setGraphicsEffect(self.shadow_effect)
        else:
            self.setGraphicsEffect(None)

        self.title_label.update_design()
        # print(self.title_label.color)
        self.animator.reload_values()

        QGraphicsItem.update(self)
예제 #21
0
    def __init__(self, direction, parent=None) -> 'ActionGraphics':
        """
		Constructs an move button with either an up or down arrow

		:param direction: The direction to draw the button (up or down)
		:type direction: MoveButton.Direction
		:param parent: None
		:type parent: NoneType
		:return: The graphics for the button.
		:rtype: ActionGraphics
		"""
        QObject.__init__(self)
        QGraphicsItem.__init__(self, parent)
        self.setAcceptHoverEvents(True)

        self.direction = direction
        self.bgColor = MoveButton.BG_COLOR
        self.lineColor = MoveButton.LINE_COLOR
예제 #22
0
    def contextMenuEvent(self, event: QGraphicsSceneContextMenuEvent) -> None:
        """
		Opens a context menu (right click menu) for the component.

		:param event: The event that was generated when the user right-clicked on this item.
		:type event: QGraphicsSceneContextMenuEvent
		:return: None
		:rtype: NoneType
		"""
        return QGraphicsItem.contextMenuEvent(event)
예제 #23
0
    def itemChange(self, change, value):
        """This method ensures that all connections, selection borders etc. that get drawn in the Flow are constantly
        redrawn during a NI drag. Should get disabled when running in performance mode - not implemented yet."""

        if change == QGraphicsItem.ItemPositionChange:
            # self.flow.viewport().update()
            if self.movement_state == MovementEnum.mouse_clicked:
                self.movement_state = MovementEnum.position_changed

        return QGraphicsItem.itemChange(self, change, value)
예제 #24
0
    def updateGraphics(self) -> None:
        """
		Updates all graphics and sub-graphics for this action.

		:return: None
		:rtype: NoneType
		"""
        self.prepareGeometryChange()
        self.updatePortGraphics()
        return QGraphicsItem.update(self)
예제 #25
0
파일: lib.py 프로젝트: edart76/tree
def allGraphicsChildItems(item: QtWidgets.QGraphicsItem,
                          includeSelf=True) -> T.List[QtWidgets.QGraphicsItem]:
    """return all child items of given item"""
    items = [item] if includeSelf else []
    items += item.childItems()
    for newItem in tuple(items):
        items.extend([
            i for i in allGraphicsChildItems(newItem, includeSelf=False)
            if not i in items
        ])
    return items
    def itemChange(self, change: 'GraphicsItemChange', value):
        """
		Overrides the default itemChange function by adding one extra conditional, otherwise normal behavior of the
		function is returned. This function is what prevents top-level components from colliding

		:param change: the type of state change
		:type change: GraphicsItemChange
		:param value: information about the change
		:return: None or Unknown (typeof(value))
		:rtype: NoneType
		"""
        if change == QGraphicsItem.ItemPositionChange and self.scene():
            delX = value.x() - self.x()
            delY = value.y() - self.y()

            if delX == 0 and delY == 0:
                return value

            translateX = copy.deepcopy(self.boundingRect())
            translateX.translate(dx=delX, dy=0)
            translateY = copy.deepcopy(self.boundingRect())
            translateY.translate(dx=0, dy=delY)

            xOkay = True
            yOkay = True

            # Checking if there's a collision in x or y direction
            for sibling in self._dataComponent.getSiblings():
                sib = self.scene().getGraphics(sibling)
                if sib == self:
                    continue

                if translateX.intersects(sib.boundingRect()):
                    xOkay = False
                if translateY.intersects(sib.boundingRect()):
                    yOkay = False

            # Decides where to place component based on collision detection
            if xOkay and yOkay:
                return
            elif xOkay:
                self.pos().setX(value.x())
            elif yOkay:
                self.pos().setY(value.y())

        # try:
        # 	self.triggerSceneUpdate()
        # except:
        # 	pass

        return QGraphicsItem.itemChange(self, change, value)
예제 #27
0
 def itemChange(self, change, value):
     if change == self.ItemPositionChange:
         scene_pos = self.scenePos()
         main_window = self.parent.parent().parent()
         main_window.item_pos.setText(f"({round(scene_pos.x(), 0)},"
                                      f" {round(scene_pos.y(), 0)})")
         return value
     if change == self.ItemSelectedHasChanged:
         if value:
             if len(self.scene().selectedItems()) == 1:
                 scene_pos = self.scenePos()
                 main_window = self.parent.parent().parent()
                 main_window.item_pos.setText(
                     f"({round(scene_pos.x(), 1)}, "
                     f"{round(scene_pos.y(), 1)})")
                 self.parent.init_image_settings(self)
             else:
                 self.parent.layout.setCurrentWidget(self.parent.tabs)
         else:
             main_window = self.parent.parent().parent()
             main_window.item_pos.setText("")
             self.parent.layout.setCurrentWidget(self.parent.tabs)
     return QGraphicsItem.itemChange(self, change, value)
예제 #28
0
 def _is_on_screen(self, item: QtWidgets.QGraphicsItem) -> bool:
     screen_rect = self.mapToScene(
         self.viewport().geometry()).boundingRect()
     tl = screen_rect.topLeft()
     br = screen_rect.bottomRight()
     return tl.x() <= item.x() <= br.x() and tl.y() <= item.y() <= br.y()
예제 #29
0
 def __init__(self, size, price_model):
     QGraphicsItem.__init__(self)
     self.size = size
     self.price_model = PriceModel()
     self.data = self.price_model.data
예제 #30
0
 def mousePressEvent(self, event):
     """Used for Moving-Commands in Flow - may be replaced later with a nicer determination of a move action."""
     self.movement_state = MovementEnum.mouse_clicked
     self.movement_pos_from = self.pos()
     return QGraphicsItem.mousePressEvent(self, event)
예제 #31
0
 def hoverLeaveEvent(self, event):
     self.title_label.set_NI_hover_state(hovering=False)
     QGraphicsItem.hoverLeaveEvent(self, event)