Beispiel #1
0
    def __init__(self, *args):
        self.__boundingRect = None
        QGraphicsObject.__init__(self, *args)
        self.setFlag(QGraphicsItem.ItemHasNoContents, True)
        self.setAcceptedMouseButtons(Qt.RightButton | Qt.LeftButton)
        self.setAcceptHoverEvents(True)

        self.setZValue(self.Z_VALUE)

        self.sourceItem = None
        self.sourceAnchor = None
        self.sinkItem = None
        self.sinkAnchor = None

        self.curveItem = LinkCurveItem(self)

        self.sourceIndicator = LinkAnchorIndicator(self)
        self.sinkIndicator = LinkAnchorIndicator(self)
        self.sourceIndicator.hide()
        self.sinkIndicator.hide()

        self.linkTextItem = QGraphicsTextItem(self)

        self.__sourceName = ""
        self.__sinkName = ""

        self.__dynamic = False
        self.__dynamicEnabled = False

        self.hover = False

        self.prepareGeometryChange()
        self.__boundingRect = None
Beispiel #2
0
    def __init__(self, parent=None, **kwargs):
        QGraphicsObject.__init__(self, parent, **kwargs)
        self.setFlag(QGraphicsObject.ItemSendsGeometryChanges)

        self.__path = QPainterPath()
        self.__brush = QBrush(Qt.NoBrush)
        self.__pen = QPen()
        self.__boundingRect = None
Beispiel #3
0
    def __init__(self, parent=None, **kwargs):
        QGraphicsObject.__init__(self, parent, **kwargs)
        self.setFlag(QGraphicsObject.ItemHasNoContents)

        self.__layoutPending = False
        self.__isActive = False
        self.__invalidatedAnchors = []
        self.__enabled = True
Beispiel #4
0
    def __init__(self, parent: Optional[QGraphicsItem] = None):
        QGraphicsObject.__init__(self, parent)
        self.mode = 'view'  # 'sync'
        self.widget_width: int = 0
        self.title_btn = Button('btn_title', '', parent=self)
        self.title_btn.setFlag(QGraphicsItem.ItemIgnoresTransformations, False)
        self.title_btn.setZValue(5)
        self.title_btn.setVisible(True)
        self.title_btn.set_mode(ButtonMode.Label)

        self.first_photo_btn = Button('btn_first_photo',
                                      'First photo',
                                      parent=self)
        self.first_photo_btn.setFlag(QGraphicsItem.ItemIgnoresTransformations,
                                     False)
        self.prev_photo_btn = Button('btn_prev_photo', '<', parent=self)
        self.prev_photo_btn.setFlag(QGraphicsItem.ItemIgnoresTransformations,
                                    False)
        self.enter_photo_num_btn = Button('btn_enter_photo_num',
                                          'Manual',
                                          parent=self)
        self.enter_photo_num_btn.setFlag(
            QGraphicsItem.ItemIgnoresTransformations, False)
        self.enter_photo_num_btn.set_is_check_button(True)
        self.enter_photo_num_btn.setVisible(False)

        self.accept_btn = Button('btn_accept_sync', 'Confirm', parent=self)
        self.accept_btn.set_base_color([ButtonColor.GREEN])
        self.cancel_btn = Button('btn_cancel_sync', 'Cancel', parent=self)
        self.cancel_btn.set_base_color([ButtonColor.RED])

        self.next_photo_btn = Button('btn_next_photo', '>', parent=self)
        self.next_photo_btn.setFlag(QGraphicsItem.ItemIgnoresTransformations,
                                    False)
        self.synchronize_btn = Button('btn_synchronize',
                                      'Synchronize',
                                      parent=self)
        self.synchronize_btn.setFlag(QGraphicsItem.ItemIgnoresTransformations,
                                     False)

        self.sync_mode_btns = [
            self.prev_photo_btn, self.accept_btn, self.first_photo_btn,
            self.cancel_btn, self.next_photo_btn
        ]
        self.view_mode_btns = [
            self.prev_photo_btn, self.title_btn, self.synchronize_btn,
            self.next_photo_btn
        ]

        for btn in self.sync_mode_btns:
            btn.setFlag(QGraphicsItem.ItemIgnoresTransformations, False)
        for btn in self.view_mode_btns:
            btn.setFlag(QGraphicsItem.ItemIgnoresTransformations, False)

        self.set_font_height(12)

        self._layout()
Beispiel #5
0
 def __init__(self):
     QGraphicsObject.__init__(self)
     self._size = 10
     self._x = 0
     self._y = 0
     self._pen = None
     self._brush = None
     self._color = None
     self.setColor(QColor(255, 0, 0, 255))
Beispiel #6
0
    def __init__(self, view: CamGraphicsView, parent: QGraphicsItem = None):
        QGraphicsObject.__init__(self, parent)

        self.view = view
        self.view.view_changed.connect(self.handle_cam_view_changed)
        self.setZValue(43)
        self.setAcceptHoverEvents(False)
        self.setAcceptedMouseButtons(Qt.AllButtons)
        self.top_menu = ButtonMenu(1.0, self)

        self.exclude_include_menu = ButtonMenu(1.0, self)
        self.exclude_include_menu.setVisible(False)

        self.process_menu = ButtonMenu(1.0, self)
        self.process_menu.setVisible(False)

        self.mouse_zoom_pic = QPixmap()
        self.mouse_pan_pic = QPixmap()
        self.icons_rect = QRectF(0, 0, 0, 0)
        self.setFlag(QGraphicsItem.ItemIgnoresTransformations, True)
        self.process_photo_popup = ButtonMenu(1.0, self)
        self.process_photo_popup.set_layout_direction('vertical')
        self.sticks_length_input = TextInputWidget(mode='number',
                                                   label='Sticks length(cm):',
                                                   parent=self)
        self.sticks_length_input.setFlag(
            QGraphicsItem.ItemIgnoresTransformations, True)
        self.sticks_length_input.setVisible(False)
        self.sticks_length_input.adjust_layout()
        self.sticks_length_input.setZValue(2)

        self.stick_length_input = TextInputWidget(mode='number',
                                                  label='Sticks length(cmi):',
                                                  parent=self)
        self.stick_length_input.setFlag(
            QGraphicsItem.ItemIgnoresTransformations, True)
        self.stick_length_input.setVisible(False)
        self.stick_length_input.adjust_layout()
        self.stick_length_input.setZValue(2)

        self.stick_label_input = TextInputWidget(mode='text',
                                                 label='Label:',
                                                 parent=self)
        self.stick_label_input.setVisible(False)
        self.stick_label_input.adjust_layout()
        self.stick_label_input.setZValue(2)

        self.stick_widget_menu = ButtonMenu(1.0, self)
        self.stick_widget_menu.show_close_button(True)
        self.stick_widget_menu.setVisible(False)

        self.submenus: List[ButtonMenu] = [
            self.process_menu, self.exclude_include_menu
        ]
Beispiel #7
0
 def __init__(self, mooseObject, parent=None):
     QGraphicsObject.__init__(self, parent)
     self.mobj = mooseObject
     self.gobj = None
     self.pressed = False
     self.setFlag(QGraphicsItem.ItemIsSelectable, True)
     self.setFlag(QGraphicsItem.ItemIsMovable, True)
     self.setAcceptHoverEvents(True)
     self.setFocusPolicy(QtCore.Qt.StrongFocus)
     if QtCore.QT_VERSION >= 0x040600:
         self.setFlag(QGraphicsItem.ItemSendsGeometryChanges, 1)
     self.setFlag(QGraphicsItem.ItemIgnoresTransformations, False)
Beispiel #8
0
    def __init__(self, widget_description=None, parent=None, **kwargs):
        self.__boundingRect = None

        QGraphicsObject.__init__(self, parent, **kwargs)

        self.setFlag(QGraphicsItem.ItemSendsGeometryChanges, True)
        self.setFlag(QGraphicsItem.ItemHasNoContents, True)
        self.setFlag(QGraphicsItem.ItemIsSelectable, True)
        self.setFlag(QGraphicsItem.ItemIsMovable, True)
        self.setFlag(QGraphicsItem.ItemIsFocusable, True)

        # central body shape item
        self.shapeItem = None

        # in/output anchor items
        self.inputAnchorItem = None
        self.outputAnchorItem = None

        # title text item
        self.captionTextItem = None

        # error, warning, info items
        self.errorItem = None
        self.warningItem = None
        self.infoItem = None

        # background when selected
        self.backgroundItem = None

        self.__title = ""
        self.__processingState = 0
        self.__progress = -1
        self.__statusMessage = ""

        self.__error = None
        self.__warning = None
        self.__info = None

        self.__anchorLayout = None
        self.__animationEnabled = False

        self.setZValue(self.Z_VALUE)
        self.setupGraphics()
        self.setWidgetDescription(widget_description)
Beispiel #9
0
 def __init__(self,
              mode: str = 'number',
              label: str = '',
              getter=None,
              setter=None,
              parser=str,
              validator=None,
              parent: Optional[QGraphicsItem] = None):
     QGraphicsObject.__init__(self, parent)
     self.getter: Callable[[], str] = getter
     self.setter: Callable[[str], None] = setter
     self.parser: Callable[[str], Any] = parser
     self.validator: Callable[[Any], bool] = validator
     self.accept_button = Button("btn_accept", "Accept", parent=self)
     self.accept_button.set_base_color([ButtonColor.GREEN])
     self.accept_button.clicked.connect(self.handle_input_accepted)
     self.cancel_button = Button("btn_cancel", "Cancel", parent=self)
     self.cancel_button.set_base_color([ButtonColor.RED])
     self.cancel_button.clicked.connect(
         lambda: self.input_cancelled.emit(self.text_field.toPlainText()))
     self.accept_button.set_height(12)
     self.cancel_button.set_height(12)
     self.hor_padding = 2
     self.background_rect = QGraphicsRectItem(parent=self)
     self.background_rect.setBrush(QBrush(QColor(50, 50, 50, 200)))
     self.text_field = NumberInputItem(self)
     self.text_field.setFont(self.font)
     self.text_field.setTextInteractionFlags(Qt.TextEditable)
     self.text_field.setDefaultTextColor(Qt.white)
     self.text_field.text_changed.connect(self.adjust_layout)
     self.text_field.set_is_number_mode(mode == 'number')
     if self.getter is not None:
         self.text_field.setPlainText(str(self.getter()))
         self.adjust_layout()
     self.text_field.accepted.connect(
         lambda: self.accept_button.click_button(artificial_emit=True))
     self.text_field.cancelled.connect(
         lambda: self.cancel_button.click_button(artificial_emit=True))
     self.text_label = QGraphicsTextItem(self)
     self.text_label.setFont(self.font)
     self.text_label.setPlainText(label)
     self.text_label.setDefaultTextColor(Qt.white)
     self.setVisible(False)
Beispiel #10
0
    def __init__(self, parent=None, **kwargs):
        QGraphicsObject.__init__(self, parent, **kwargs)
        self.setFlag(QGraphicsItem.ItemHasNoContents)
        self.setFlag(QGraphicsItem.ItemIsFocusable)

        self.__line = QLineF()
        self.__points = \
            [ControlPoint(self, ControlPoint.TopLeft),  # TopLeft is line start
             ControlPoint(self, ControlPoint.BottomRight)  # line end
             ]

        self.__activeControl = None

        if self.scene():
            self.__installFilter()

        for p in self.__points:
            p.setFlag(QGraphicsItem.ItemIsFocusable)
            p.setFocusProxy(self)
Beispiel #11
0
    def __init__(self, parent=None, rect=None, constraints=0, **kwargs):
        QGraphicsObject.__init__(self, parent, **kwargs)
        self.setFlag(QGraphicsItem.ItemHasNoContents)
        self.setFlag(QGraphicsItem.ItemIsFocusable)

        self.__rect = rect if rect is not None else QRectF()
        self.__margins = QMargins()
        points = \
            [ControlPoint(self, ControlPoint.Left),
             ControlPoint(self, ControlPoint.Top),
             ControlPoint(self, ControlPoint.TopLeft),
             ControlPoint(self, ControlPoint.Right),
             ControlPoint(self, ControlPoint.TopRight),
             ControlPoint(self, ControlPoint.Bottom),
             ControlPoint(self, ControlPoint.BottomLeft),
             ControlPoint(self, ControlPoint.BottomRight)
             ]
        assert (points == sorted(points, key=lambda p: p.anchor()))

        self.__points = dict((p.anchor(), p) for p in points)

        if self.scene():
            self.__installFilter()

        for p in points:
            p.setFlag(QGraphicsItem.ItemIsFocusable)
            p.setFocusProxy(self)

        self.controlPoint(ControlPoint.Top).setConstraint(Qt.Vertical)
        self.controlPoint(ControlPoint.Bottom).setConstraint(Qt.Vertical)
        self.controlPoint(ControlPoint.Left).setConstraint(Qt.Horizontal)
        self.controlPoint(ControlPoint.Right).setConstraint(Qt.Horizontal)

        self.__constraints = constraints
        self.__activeControl = None

        self.__pointsLayout()
Beispiel #12
0
    def __init__(self, group_id, group_name, icon, parent=None):
        QGraphicsObject.__init__(self)
        self.setParentItem(parent)

        # Save Variables, useful for later
        self.m_group_id = group_id
        self.m_group_name = group_name

        # plugin Id, < 0 if invalid
        self.m_plugin_id = -1
        self.m_plugin_ui = False
        self.m_plugin_inline = self.INLINE_DISPLAY_DISABLED

        # Base Variables
        self.p_width = 50
        self.p_width_in = 0
        self.p_width_out = 0
        self.p_height = canvas.theme.box_header_height + canvas.theme.box_header_spacing + 1

        self.m_last_pos = QPointF()
        self.m_split = False
        self.m_split_mode = PORT_MODE_NULL

        self.m_cursor_moving = False
        self.m_forced_split = False
        self.m_mouse_down = False
        self.m_inline_image = None
        self.m_inline_scaling = 1.0
        self.m_inline_first = True
        self.m_will_signal_pos_change = False

        self.m_port_list_ids = []
        self.m_connection_lines = []

        # Set Font
        self.m_font_name = QFont()
        self.m_font_name.setFamily(canvas.theme.box_font_name)
        self.m_font_name.setPixelSize(canvas.theme.box_font_size)
        self.m_font_name.setWeight(canvas.theme.box_font_state)

        self.m_font_port = QFont()
        self.m_font_port.setFamily(canvas.theme.port_font_name)
        self.m_font_port.setPixelSize(canvas.theme.port_font_size)
        self.m_font_port.setWeight(canvas.theme.port_font_state)

        # Icon
        if canvas.theme.box_use_icon:
            self.icon_svg = CanvasIcon(icon, self.m_group_name, self)
        else:
            self.icon_svg = None

        # Shadow
        if options.eyecandy and QT_VERSION >= 0x50c00:
            self.shadow = CanvasBoxShadow(self.toGraphicsObject())
            self.shadow.setFakeParent(self)
            self.setGraphicsEffect(self.shadow)
        else:
            self.shadow = None

        # Final touches
        self.setFlags(QGraphicsItem.ItemIsFocusable
                      | QGraphicsItem.ItemIsMovable
                      | QGraphicsItem.ItemIsSelectable)

        # Wait for at least 1 port
        if options.auto_hide_groups:
            self.setVisible(False)

        if options.auto_select_items:
            self.setAcceptHoverEvents(True)

        self.updatePositions()

        self.visibleChanged.connect(self.slot_signalPositionChangedLater)
        self.xChanged.connect(self.slot_signalPositionChangedLater)
        self.yChanged.connect(self.slot_signalPositionChangedLater)

        canvas.scene.addItem(self)
        QTimer.singleShot(0, self.fixPos)
Beispiel #13
0
    def __init__(self, stick: Stick, camera: Camera, parent: Optional[QGraphicsItem] = None):
        QGraphicsObject.__init__(self, parent)
        self.camera = camera
        self.stick = stick
        self.line = QLineF()
        self.gline = QGraphicsLineItem(self.line)

        self.stick_label_text = QGraphicsSimpleTextItem("0", self)
        self.stick_label_text.setFont(StickWidget.font)
        self.stick_label_text.setPos(self.line.p1() - QPoint(0, 24))
        self.stick_label_text.setBrush(QBrush(QColor(0, 255, 0)))
        self.stick_label_text.hide()
        self.setZValue(10)

        self.mode = StickMode.Display

        self.btn_delete = Button("delete", "x", parent=self)
        self.btn_delete.setFlag(QGraphicsItem.ItemIgnoresTransformations, True)
        self.btn_delete.set_base_color([ButtonColor.RED])
        self.btn_delete.setVisible(False)
        btn_size = max(int(np.linalg.norm(self.stick.top - self.stick.bottom) / 5.0), 15)
        self.btn_delete.set_height(12)
        self.btn_delete.clicked.connect(self.handle_btn_delete_clicked)
        self.btn_delete.setPos(self.line.p1() - QPointF(0.5 * self.btn_delete.boundingRect().width(), 1.1 * self.btn_delete.boundingRect().height()))
        self.btn_delete.set_opacity(0.7)

        self.top_handle = QGraphicsEllipseItem(0, 0, self.handle_size, self.handle_size, self)
        self.mid_handle = QGraphicsEllipseItem(0, 0, self.handle_size, self.handle_size, self)
        self.bottom_handle = QGraphicsEllipseItem(0, 0, self.handle_size, self.handle_size, self)

        self.top_handle.setAcceptedMouseButtons(Qt.NoButton)
        self.mid_handle.setAcceptedMouseButtons(Qt.NoButton)
        self.bottom_handle.setAcceptedMouseButtons(Qt.NoButton)
        self.top_handle.setBrush(self.handle_idle_brush)
        self.top_handle.setPen(self.handle_idle_pen)
        self.mid_handle.setBrush(self.handle_idle_brush)
        self.mid_handle.setPen(self.handle_idle_pen)
        self.bottom_handle.setBrush(self.handle_idle_brush)
        self.bottom_handle.setPen(self.handle_idle_pen)

        self.hovered_handle: Optional[QGraphicsRectItem] = None
        self.handles = [self.top_handle, self.mid_handle, self.bottom_handle]

        self.link_button = Button("link", "Link to...", parent=self)
        self.link_button.set_base_color([ButtonColor.GREEN])
        self.link_button.set_height(12)
        self.link_button.set_label("Link", direction="vertical")
        self.link_button.fit_to_contents()
        self.link_button.clicked.connect(lambda: self.link_initiated.emit(self))
        self.link_button.setVisible(False)
        self.link_button.setFlag(QGraphicsObject.ItemIgnoresTransformations, False)

        self.adjust_line()

        self.setAcceptHoverEvents(True)
        self.top_handle.setZValue(4)
        self.bottom_handle.setZValue(4)
        self.mid_handle.setZValue(4)

        self.top_handle.hide()
        self.mid_handle.hide()
        self.bottom_handle.hide()

        self.handle_mouse_offset = QPointF(0, 0)
        self.available_for_linking = False
        self.link_source = False
        self.current_highlight_color: QColor = StickWidget.normal_color
        self.highlighted = False
        self.frame_color: Optional[None] = self.normal_color
        self.is_linked = False

        self.is_master = True
        self.selected = False

        self.measured_height: int = -1
        self.current_color = self.normal_color

        self.show_label = False
        self.highlight_animation = QPropertyAnimation(self, b"highlight_color")
        self.highlight_animation.valueChanged.connect(self.handle_highlight_animation_value_changed)
        self.deleting = False
        self.update_tooltip()
        self.show_measurements: bool = False
        self.proposed_snow_height: int = -1

        self.zero_btn = Button("zero_btn", "0", parent=self)
        self.zero_btn.setFlag(QGraphicsItem.ItemIgnoresTransformations, True)
        self.zero_btn.setVisible(False)
        self.zero_btn.setPos(self.boundingRect().center() + QPointF(self.zero_btn.boundingRect().width() * -0.5,
                                                                    self.boundingRect().height() * 0.5))
        self.zero_btn.clicked.connect(self.handle_zero)
Beispiel #14
0
    def __init__(self, var):
        QGraphicsObject.__init__(self)
        QTreeWidgetItem.__init__(self, [var.getName()])

        self.cyvar = var
        self.diagrammRep = None
Beispiel #15
0
    def __init__(self, scale: float, parent: Optional[QGraphicsItem] = None):
        QGraphicsObject.__init__(self, parent)
        self.current_highlight_color = QColor(0, 0, 0, 0)
        self.current_timer = -1
        self.scaling = scale
        self.pixmap = QGraphicsPixmapItem(self)
        self.stick_widgets: List[StickWidget] = []
        self.link_cam_text = QGraphicsSimpleTextItem("Link camera...", self)
        self.link_cam_text.setZValue(40)
        self.link_cam_text.setVisible(False)
        self.link_cam_text.setFont(CameraView.font)
        self.link_cam_text.setPos(0, 0)
        self.link_cam_text.setPen(QPen(QColor(255, 255, 255, 255)))
        self.link_cam_text.setBrush(QBrush(QColor(255, 255, 255, 255)))

        self.show_add_buttons = False
        self.camera = None

        self.setFlag(QGraphicsItem.ItemSendsGeometryChanges, True)
        self.show_stick_widgets = False
        self.setAcceptHoverEvents(True)
        self.stick_edit_mode = False

        self.original_pixmap = self.pixmap.pixmap()

        self.hovered = False

        self.mode = 0  # TODO make enum Mode
        self.click_handler = None
        self.double_click_handler: Callable[[int, int], None] = None

        self.stick_widget_mode = StickMode.Display

        self.highlight_animation = QPropertyAnimation(self, b"highlight_color")
        self.highlight_animation.setEasingCurve(QEasingCurve.Linear)
        self.highlight_animation.valueChanged.connect(
            self.handle_highlight_color_changed)
        self.highlight_rect = QGraphicsRectItem(self)
        self.highlight_rect.setZValue(4)
        self.highlight_rect.setPen(QPen(QColor(0, 0, 0, 0)))
        self.title_btn = Button('btn_title', '', parent=self)
        self.title_btn.setFlag(QGraphicsItem.ItemIgnoresTransformations, False)
        self.title_btn.setZValue(5)
        self.title_btn.setVisible(False)

        self.sticks_without_width: List[Stick] = []
        self.current_image_name: str = ''
        self.control_widget = ControlWidget(parent=self)
        self.control_widget.setFlag(QGraphicsItem.ItemIgnoresTransformations,
                                    False)
        self.control_widget.setVisible(True)
        self._connect_control_buttons()
        self.image_available = True
        self.blur_eff = QGraphicsBlurEffect()
        self.blur_eff.setBlurRadius(5.0)
        self.blur_eff.setEnabled(False)
        self.pixmap.setGraphicsEffect(self.blur_eff)
        self.overlay_message = QGraphicsSimpleTextItem('not available',
                                                       parent=self)
        font = self.title_btn.font
        font.setPointSize(48)
        self.overlay_message.setFont(font)
        self.overlay_message.setBrush(QBrush(QColor(200, 200, 200, 200)))
        self.overlay_message.setPen(QPen(QColor(0, 0, 0, 200), 2.0))
        self.overlay_message.setVisible(False)
        self.overlay_message.setZValue(6)

        self.stick_box = QGraphicsRectItem(parent=self)
        self.stick_box.setFlag(QGraphicsItem.ItemIsMovable, True)
        self.stick_box.setVisible(False)
        self.stick_box_start_pos = QPoint()
Beispiel #16
0
    def __init__(self, *args):
        QGraphicsObject.__init__(self, *args)
        self.setFlag(QGraphicsItem.ItemSendsScenePositionChanges, True)
        self.setFlag(QGraphicsItem.ItemHasNoContents, True)

        self.__direction = QPointF()