Exemple #1
0
    def mouseReleaseEvent(self, event: QGraphicsSceneMouseEvent):
        if event.button() == Qt.LeftButton:
            trans = self.parent().transform()

            item = self.itemAt(event.scenePos(), trans)
            if isinstance(item, NamedArrow) and \
                self._source_y is not None and \
                    self._accepts_hover:

                interval = np.unique(
                    self._hot_str.loc[:, [STFCFM.TIN.name, STFCFM.TOUT.
                                          name]].values)

                source_inter = self._px_to_interval(self._source_y, interval)
                dest_inter = self._px_to_interval(event.scenePos().y(),
                                                  interval)

                if source_inter == dest_inter:
                    # if the intervals of the clicks are the same, prompt user
                    summary = self._setup.summary
                    pinch = self._setup.pinch
                    if self._des_type == 'abv':
                        summary_indexer = summary[SFM.TOUT.name] >= pinch
                    else:
                        summary_indexer = summary[SFM.TIN.name] <= pinch
                    summary = summary.loc[summary_indexer, :].reset_index(
                        drop=True)
                    inter = summary.at[source_inter, SFM.INTERVAL.name]
                    dialog = ExchangerInputDialog('process', self._des_type,
                                                  inter, self._source_item,
                                                  item.name, self._setup)
                    dialog.exec_()

        return super().mouseReleaseEvent(event)
Exemple #2
0
 def mouseMoveEvent(self, event: QGraphicsSceneMouseEvent):
     if event.modifiers() and Qt.ShiftModifier:
         print(event.pos())
         self.stuff.append(event.pos())
         self.update()
         return
     super().mouseMoveEvent(event)
Exemple #3
0
    def mouseReleaseEvent(self, event: qt.QGraphicsSceneMouseEvent):
        if self.state is EditorState.INSERT_AUGMENT_ITEM:
            if self._item:
                self._item.drawing = False
                dlg = ImageDlg()
                if dlg.exec():
                    name = dlg.name
                    images = dlg.images
                    self._item.setName(name)
                    self._item.setImages(images)
                else:
                    self._selected = self._item
                    self.delete_point_of_interest()

                    return
                self.augments.add(self._item)
                self._item_start_point = None
                self._item = None
                self.update()
        elif self.state is EditorState.NONE:
            if self._dragging:
                self._dragging.dragging = False
                self._dragging = None
                self.update()

        event.accept()
    def selectOrSnap(self,  part_item: SliceNucleicAcidPartItemT,
                            target_item: SliceVirtualHelixItem,
                            event: QGraphicsSceneMouseEvent):
        """
        Args:
            part_item:
            target_item: Description
            event: Description

        Deleted Parameters:
            snap_to_item (SliceVirtualHelixItem or GridEvent): Item to snap
                selection to
        """
        self.setPartItem(part_item)
        if (self.snap_origin_item is not None and event.modifiers() == Qt.AltModifier):
            self.doSnap(part_item, target_item)
            self.individual_pick = False
        else:  # just do a selection
            if event.modifiers() != Qt.ShiftModifier:
                self.modelClear()   # deselect if shift isn't held

            if isinstance(target_item, SliceVirtualHelixItem):
                # NOTE: individual_pick seems not needed.
                # it's supposed to allow for single item picking
                # self.individual_pick = True

                if self.snap_origin_item is not None:
                    self.snap_origin_item.setSnapOrigin(False)
                    self.snap_origin_item = None

                doc = self.manager.document
                part = part_item.part()
                doc.addVirtualHelicesToSelection(part, [target_item.idNum()])
Exemple #5
0
    def selectOrSnap(self, part_item: GridNucleicAcidPartItemT,
                     target_item: Union[GridVirtualHelixItem, GridEvent],
                     event: QGraphicsSceneMouseEvent):
        """
        Args:
            part_item: the part item
            target_item: Item to snap
            event: mosue event
        """
        self.setPartItem(part_item)
        if (self.snap_origin_item is not None
                and event.modifiers() == Qt.AltModifier):
            self.doSnap(part_item, target_item)
            self.individual_pick = False
        else:  # just do a selection
            if event.modifiers() != Qt.ShiftModifier:
                self.modelClearSelected()  # deselect if shift isn't held

            if isinstance(target_item, GridVirtualHelixItem):
                # NOTE: individual_pick seems not needed.
                # it's supposed to allow for single item picking
                # self.individual_pick = True

                if self.snap_origin_item is not None:
                    self.snap_origin_item.setSnapOrigin(False)
                    self.snap_origin_item = None

                doc = self.manager.document
                part = part_item.part()
                doc.addVirtualHelicesToSelection(part, [target_item.idNum()])
Exemple #6
0
 def mousePressEvent(self, event: QGraphicsSceneMouseEvent) -> None:
     if event.button() == 1:
         item = self.itemAt(event.scenePos(), QTransform())
         if isinstance(item, Region):
             self.rebuild_sprite_signal.emit(item.region_id)
             self.current_item = item
             self.pressed = True
Exemple #7
0
 def mousePressEvent(self, evt: QGraphicsSceneMouseEvent):
     if evt.button() == Qt.LeftButton:
         pos = (evt.scenePos().x(), evt.scenePos().y())
         self.relative_pos = (pos[0] - self.x(), pos[1] - self.y())
         self.port_clicked.emit(self)
     elif evt.button() == Qt.RightButton:
         pass
     elif evt.button() == Qt.MidButton:
         pass
 def mousePressEvent(self, event: QtWidgets.QGraphicsSceneMouseEvent):
     if event.button() == Qt.MidButton:
         self.clear()
     elif event.button() == Qt.LeftButton:
         self.addEllipse(event.scenePos().x() - self.LINE_RADIUS_PX, event.scenePos().y() - self.LINE_RADIUS_PX,
                         self.LINE_RADIUS_PX * 2, self.LINE_RADIUS_PX * 2,
                         QPen(Qt.NoPen),
                         QBrush(Qt.black))
         self.previousPoint = event.scenePos()
Exemple #9
0
    def mouse_press_callback(self, event: QtWidgets.QGraphicsSceneMouseEvent):

        self.input_x = round((event.pos().x() * self.resolution), 2)
        self.input_y = round((event.pos().y() * (-1) * self.resolution), 2)

        self.set_label_xy_show()
        self.set_line_zero_show()
        self.add_point()
        self.last_points.append((int(event.pos().x()), int(event.pos().y())))
Exemple #10
0
 def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
     """ Only accept mouse press events (i.e. ROI selection) if the mouse is near to the boundary.
         Prevents selection based on larger bounding rectangle.
         Overrides QGraphicsItem::mousePressEvent.
     @param event: mouse press event
     """
     if self.distance_to_boundary(event.pos(), increment=0.005) < 4:
         event.accept()
     else:
         event.ignore()
Exemple #11
0
 def mouseMoveEvent(self, event: QGraphicsSceneMouseEvent):
     if event.buttons() == Qt.MiddleButton:
         delta: QPointF = event.pos() - self._pan_last_pos
         new_x = self.horizontalScrollBar().value() - delta.x()
         new_y = self.verticalScrollBar().value() - delta.y()
         self.horizontalScrollBar().setValue(new_x)
         self.verticalScrollBar().setValue(new_y)
         self._pan_last_pos = event.pos()
         event.accept()
     else:
         super().mouseMoveEvent(event)
Exemple #12
0
    def mouseMoveEvent(self, event: QGraphicsSceneMouseEvent) -> None:
        scene = self.scene()
        if scene and self._orig_point is not None:
            # Edit line or arrow
            if self._mode in (MODE_LINE, MODE_ARROW) \
                    or (self._mode is None and isinstance(self._item_to_draw, QGraphicsLineItem)):
                pos = self.mapToScene(event.pos())
                x = pos.x() - self._orig_point.x()
                y = pos.y() - self._orig_point.y()
                if self._item_to_draw and self._orig_point == self._item_to_draw.line(
                ).p2() + self._item_to_draw.pos():
                    # Moving line around head
                    line = QLineF(0, 0, -x, -y)
                    point = pos
                else:
                    line = QLineF(0, 0, x, y)
                    point = None

                if self._item_to_draw is None:
                    if self._mode == MODE_LINE:
                        self._item_to_draw = self.addAnnotationLine(
                            line, self._orig_point)
                    elif self._mode == MODE_ARROW:
                        self._item_to_draw = self.addAnnotationArrow(
                            line, self._orig_point)
                else:
                    self._item_to_draw.setLine(line)
                    if point is not None:
                        self._item_to_draw.setPos(point)
                return

            # Edit rect or circle
            elif self._mode in (MODE_RECT, MODE_ELLIPSE) \
                    or (self._mode is None and isinstance(self._item_to_draw, (RectItem, EllipseItem))):
                pos = self.mapToScene(event.pos())
                width = pos.x() - self._orig_point.x()
                height = pos.y() - self._orig_point.y()
                dx = 0 if width >= 0 else width
                dy = 0 if height >= 0 else height
                rect = QRectF(0, 0, abs(width), abs(height))
                point = self._orig_point + QPointF(dx, dy)
                if self._item_to_draw is None:
                    if self._mode == MODE_RECT:
                        self._item_to_draw = self.addAnnotationRect(
                            rect, point)
                    elif self._mode == MODE_ELLIPSE:
                        self._item_to_draw = self.addAnnotationEllipse(
                            rect, point)
                else:
                    self._item_to_draw.setRect(rect)
                    self._item_to_draw.setPos(point)
                return

        super().mouseMoveEvent(event)
Exemple #13
0
 def mouseMoveEvent(self, event: QGraphicsSceneMouseEvent):
     """Parses a :meth:`mouseMoveEvent`, calling the appropriate tool
     method as necessary. Updates ``_move_idx`` if it changed.
     """
     tool_method_name = self._getActiveTool().methodPrefix() + "MouseMove"
     if hasattr(self, tool_method_name):  # if the tool method exists
         idx = int(floor((self.x() + event.pos().x()) / _BASE_WIDTH))
         if idx != self._move_idx:  # did we actually move?
             modifiers = event.modifiers()
             self._move_idx = idx
             getattr(self, tool_method_name)(modifiers, idx)
Exemple #14
0
 def mouseMoveEvent(self, event: QGraphicsSceneMouseEvent):
     """Parses a :meth:`mouseMoveEvent`, calling the appropriate tool
     method as necessary. Updates ``_move_idx`` if it changed.
     """
     tool_method_name = self._getActiveTool().methodPrefix() + "MouseMove"
     if hasattr(self, tool_method_name):  # if the tool method exists
         idx = int(floor((self.x() + event.pos().x()) / _BASE_WIDTH))
         if idx != self._move_idx:  # did we actually move?
             modifiers = event.modifiers()
             self._move_idx = idx
             getattr(self, tool_method_name)(modifiers, idx)
Exemple #15
0
    def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
        """Handler for user mouse press.

        Args:
            event: Contains item, scene, and screen coordinates of the
                event, and previous event.
        """
        # print("GridSelectionGroup mousePress")
        tool = self.tool
        if event.button() != Qt.LeftButton:
            """ do context menu?
            """
            # slice_graphics_view = self.tool.slice_graphics_view
            # print(slice_graphics_view)
            # tool.getCustomContextMenu(event.screenPos())
            tool.individual_pick = False
            return QGraphicsItemGroup.mousePressEvent(self, event)
        else:
            # print("the right event")
            modifiers = event.modifiers()
            is_shift = modifiers == Qt.ShiftModifier
            # print("Is_shift is %s" % is_shift)
            # check to see if we are clicking on a previously selected item
            if tool.is_selection_active:
                # print("clicking the box")
                pos = event.scenePos()
                for item in tool.slice_graphics_view.scene().items(pos):
                    if isinstance(item, GridVirtualHelixItem):
                        doc = tool.manager.document
                        part = item.part()
                        if is_shift:
                            id_num = item.idNum()
                            if doc.isVirtualHelixSelected(
                                    part,
                                    id_num):  # maybe should ask the model?
                                doc.removeVirtualHelicesFromSelection(
                                    part, [id_num])
                        else:
                            origin_id_num = item.idNum()
                            is_alt = modifiers == Qt.AltModifier
                            if (doc.isVirtualHelixSelected(
                                    part, origin_id_num) and not is_alt):
                                # print("origin", origin_id_num)
                                if tool.snap_origin_item is not None:
                                    tool.snap_origin_item.setSnapOrigin(False)
                                tool.snap_origin_item = item
                                item.setSnapOrigin(True)
                                break
                            else:
                                item.mousePressEvent(event)
            self.drag_start_position = sp = self.pos()
            self.drag_last_position = sp

            return QGraphicsItemGroup.mousePressEvent(self, event)
Exemple #16
0
 def mouseMoveEvent(self, event: QGraphicsSceneMouseEvent):
     if self.hovered_handle is None:
         return
     if self.hovered_handle == self.top_handle:
         self.line.setP1((event.pos() + self.handle_mouse_offset).toPoint())
     elif self.hovered_handle == self.bottom_handle:
         self.line.setP2((event.pos() + self.handle_mouse_offset).toPoint())
     else:
         displacement = event.pos() - event.lastPos()
         self.setPos(self.pos() + displacement)
     self.adjust_handles()
     self.adjust_stick()
     self.scene().update()
Exemple #17
0
    def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
        """Handler for user mouse press.

        Args:
            event: Contains item, scene, and screen coordinates of the
                event, and previous event.
        """
        # print("GridSelectionGroup mousePress")
        tool = self.tool
        if event.button() != Qt.LeftButton:
            """ do context menu?
            """
            # slice_graphics_view = self.tool.slice_graphics_view
            # print(slice_graphics_view)
            # tool.getCustomContextMenu(event.screenPos())
            tool.individual_pick = False
            return QGraphicsItemGroup.mousePressEvent(self, event)
        else:
            # print("the right event")
            modifiers = event.modifiers()
            is_shift = modifiers == Qt.ShiftModifier
            # print("Is_shift is %s" % is_shift)
            # check to see if we are clicking on a previously selected item
            if tool.is_selection_active:
                # print("clicking the box")
                pos = event.scenePos()
                for item in tool.slice_graphics_view.scene().items(pos):
                    if isinstance(item, GridVirtualHelixItem):
                        doc = tool.manager.document
                        part = item.part()
                        if is_shift:
                            id_num = item.idNum()
                            if doc.isVirtualHelixSelected(part, id_num):    # maybe should ask the model?
                                doc.removeVirtualHelicesFromSelection(part, [id_num])
                        else:
                            origin_id_num = item.idNum()
                            is_alt = modifiers == Qt.AltModifier
                            if (doc.isVirtualHelixSelected(part, origin_id_num) and
                                    not is_alt):
                                # print("origin", origin_id_num)
                                if tool.snap_origin_item is not None:
                                    tool.snap_origin_item.setSnapOrigin(False)
                                tool.snap_origin_item = item
                                item.setSnapOrigin(True)
                                break
                            else:
                                item.mousePressEvent(event)
            self.drag_start_position = sp = self.pos()
            self.drag_last_position = sp

            return QGraphicsItemGroup.mousePressEvent(self, event)
Exemple #18
0
 def mouseReleaseEvent(self, event: qw.QGraphicsSceneMouseEvent) -> None:
     """Start drawing arena"""
     logging.debug(f'Number of items {len(self.items())}')
     if event.button() == qc.Qt.RightButton:
         self.points = []
         self._clearIncomplete()
         return
     pos = event.scenePos().toPoint()
     pos = np.array((pos.x(), pos.y()), dtype=int)
     if self.geom == DrawingGeom.rectangle:
         if len(self.points) > 0:
             rect = util.points2rect(self.points[0], pos)                
             rect = qg.QPolygonF([qc.QPointF(*p) for p in rect])
             self.points = []
             if self.geom == DrawingGeom.arena:
                 self.setArena(rect)
             else:
                 # logging.debug('DDDD %r', len(self.items()))
                 self._clearIncomplete()
                 # logging.debug('EEEE %r', len(self.items()))
                 self._addItem(rect)
                 # logging.debug('FFFF %r', len(self.items()))
         else:
             self.points = [pos]
             logging.debug(f'XXXX Number of items {len(self.items())}\n'
                           f'pos: {pos}')
             return
     elif self.geom == DrawingGeom.polygon or \
             self.geom == DrawingGeom.arena:
         if len(self.points) > 0:
             dvec = pos - self.points[0]
             if max(abs(dvec)) < self.snap_dist and \
                     len(self.points) > 2:
                 if self.geom == DrawingGeom.polygon:
                     self._addItem(np.array(self.points))
                 elif self.geom == DrawingGeom.arena:
                     poly = qg.QPolygonF([qc.QPointF(*p) for p in self.points])
                     self.setArena(poly)
                 self._clearIncomplete()
                 self.points = []
                 logging.debug(f'YYYY Number of items {len(self.items())}')
                 return
         self.points.append(pos)
         path = qg.QPainterPath(qc.QPointF(*self.points[0]))
         for point in self.points[1:]:
             path.lineTo(qc.QPointF(*point))
         self.addIncompletePath(path)
     else:
         raise NotImplementedError(
             f'Drawing geometry {self.geom} not implemented')
     logging.debug(f'ZZZZ Number of items {len(self.items())}')
Exemple #19
0
 def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
     """Parses a mousePressEvent. Stores _move_idx and _offset_idx for
     future comparison.
     """
     self._high_drag_bound = self._model_part.getProperty('max_vhelix_length') - self.width()
     if event.modifiers() & Qt.ShiftModifier or self._moving_via_handle:
         self.setCursor(Qt.ClosedHandCursor)
         self._start_idx_low = self._idx_low
         self._start_idx_high = self._idx_high
         self._delta = 0
         self._move_idx = int(floor((self.x()+event.pos().x()) / BASE_WIDTH))
         self._offset_idx = int(floor(event.pos().x()) / BASE_WIDTH)
     else:
         return QGraphicsItem.mousePressEvent(self, event)
Exemple #20
0
 def mousePressEvent(self, event: QGraphicsSceneMouseEvent
                     ):  # отслеживание нажатия кнопки мыши
     if self.i != 0 and self.j != 0 and self.i != self.a - 1 and self.j != self.b - 1:
         self.X0 = event.screenPos().x()
         self.Y0 = event.screenPos().y()
         if event.button() == 2:  # отслеживание нажатия правой кнопки мыши
             if not self.clicked:
                 self.color = QtGui.QColor(150, 0, 0)
                 self.clicked = True
             else:
                 self.color = QtGui.QColor(0, 0, 0)
                 self.clicked = False
             self.setBrush(
                 QtGui.QBrush(self.color, style=QtCore.Qt.SolidPattern))
Exemple #21
0
    def mousePressEvent(self,
                        event: QtWidgets.QGraphicsSceneMouseEvent) -> None:
        if event.buttons() == Qt.LeftButton:
            if self.window.choose_seed.isChecked():
                self.window.update_seed(event.scenePos())
            else:
                posx = event.scenePos().x()
                posy = event.scenePos().y()

                if event.modifiers() == Qt.KeyboardModifier.ShiftModifier:
                    if posy != self.last_y:
                        der = (posx - self.last_x) / (posy - self.last_y)
                    else:
                        der = 2
                    if abs(der) <= 1:
                        posx = self.last_x
                    else:
                        posy = self.last_y

                self.window.addPoint(posx, posy)

                self.last_x = posx
                self.last_y = posy
        elif event.buttons() == Qt.RightButton:
            self.window.closePoly()
        elif event.buttons() == Qt.MidButton:
            self.window.update_seed(
                QPoint(int(event.scenePos().x()), int(event.scenePos().y())))
Exemple #22
0
    def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
        if event.button() == Qt.LeftButton:
            trans = self.parent().transform()

            item = self.itemAt(event.scenePos(), trans)
            if isinstance(item, LiveArrowItem):
                self._source_item = item.name
                self._source_y = event.scenePos().y()
                self._accepts_hover = True
            else:
                self._source_item = None
                self._source_y = None
                self._accepts_hover = False

        return super().mousePressEvent(event)
    def _handle_mouse_move_draw_mode(self, event: QGraphicsSceneMouseEvent):
        point2 = event.scenePos()
        self._restrict_to_scene_space(point2)
        if self.new_selection_origin is None:
            scene_logger.warning("Move event: Selection origin is None!")
            event.accept()
            return

        rectangle = QRectF(
            QPointF(min(self.new_selection_origin.x(), point2.x()),
                    min(self.new_selection_origin.y(), point2.y())),
            QPointF(max(self.new_selection_origin.x(), point2.x()),
                    max(self.new_selection_origin.y(), point2.y())))
        self.new_selection_view.setRect(rectangle)
        event.accept()
 def _handle_mouse_press_draw_mode(self, event: QGraphicsSceneMouseEvent):
     if event.button() == Qt.LeftButton and self.new_selection_view is None:
         self.new_selection_origin = event.scenePos()
         self._restrict_to_scene_space(self.new_selection_origin)
         scene_logger.info(
             f"Beginning to draw a new selection: "
             f"X={self.new_selection_origin.x()}, Y={self.new_selection_origin.y()}"
         )
         self.new_selection_view = QGraphicsRectItem(
             self.new_selection_origin.x(), self.new_selection_origin.y(),
             0, 0)
         self.new_selection_view.setPen(self.default_border_pen)
         self.new_selection_view.setBrush(self.default_fill_brush)
         self.addItem(self.new_selection_view)
         event.accept()
Exemple #25
0
 def mouseReleaseEvent(self, ev: QGraphicsSceneMouseEvent):
     if self._parentState._sNormal and not self._wasMoving:
         it = self.itemAt(ev.scenePos(), QTransform())
         if int(ev.modifiers()) & Qt.ShiftModifier == 0:
             self.clearSelection()
         if it is not None:
             it.setSelected(True)
         itList = self.selectedItems()
         if len(itList) == 1:
             self._page._net.fillProperties(itList[0].propertiesTable())
         if len(itList) == 0:
             self._page._net.fillProperties(self._page.propertiesTable())
         self.update()
     self._wasMoving = False
     QGraphicsScene.mouseReleaseEvent(self, ev)
    def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
        """Event handler for when the mouse button is pressed inside
        this item. If a tool-specific mouse press method is defined, it will be
        called for the currently active tool. Otherwise, the default
        QGraphicsItem.mousePressEvent will be called.

        Note:
            Only applies the event if the clicked item is in the part
            item's active filter set.

        Args:
            event (QMouseEvent): contains parameters that describe the mouse event.
        """
        if self.FILTER_NAME not in self._part_item.getFilterSet():
            self._doc_controller.showFilterHints(True,
                                                 filter_name=self.FILTER_NAME)
            return
        if event.button() == Qt.RightButton:
            return
        part_item = self._part_item
        tool = part_item._getActiveTool()
        tool_method_name = tool.methodPrefix() + "MousePress"
        if hasattr(self, tool_method_name):
            getattr(self, tool_method_name)(tool, part_item, event)
        else:
            QGraphicsItem.mousePressEvent(self, event)
 def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
     """Parses a mousePressEvent. Stores _move_idx and _offset_idx for
     future comparison.
     """
     self._high_drag_bound = self._model_part.getProperty(
         'max_vhelix_length') - self.width()
     if event.modifiers() & Qt.ShiftModifier or self._moving_via_handle:
         self.setCursor(Qt.ClosedHandCursor)
         self._start_idx_low = self._idx_low
         self._start_idx_high = self._idx_high
         self._delta = 0
         self._move_idx = int(
             floor((self.x() + event.pos().x()) / BASE_WIDTH))
         self._offset_idx = int(floor(event.pos().x()) / BASE_WIDTH)
     else:
         return QGraphicsItem.mousePressEvent(self, event)
Exemple #28
0
    def mouseMoveEvent(self, event: QGraphicsSceneMouseEvent):
        """All mouseMoveEvents are passed to the group if it's in a group

        Args:
            event: Description
        """
        MOVE_THRESHOLD = 0.01   # ignore small moves
        selection_group = self.group()
        if selection_group is not None:
            selection_group.mousePressEvent(event)
        elif self._right_mouse_move:
            new_pos = event.scenePos()
            delta = new_pos - self.drag_last_position
            dx = int(floor(delta.x() / _BASE_WIDTH))*_BASE_WIDTH
            x = self.handle_start.x() + dx
            if abs(dx) > MOVE_THRESHOLD or dx == 0.0:
                old_x = self.x()
                self.setX(x)
                self._virtual_helix_item.setX(x + _VH_XOFFSET)
                self._part_item.updateXoverItems(self._virtual_helix_item)
                dz = self._part_item.convertToModelZ(x - old_x)
                self._model_part.translateVirtualHelices([self.idNum()],
                                                         0, 0, dz, False,
                                                         use_undostack=False)
        else:
            QGraphicsItem.mouseMoveEvent(self, event)
Exemple #29
0
    def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
        """Handler for user mouse press.

        Args:
            event: Contains item, scene, and screen
            coordinates of the the event, and previous event.
        """
        # self.show()
        if event.button() != Qt.LeftButton:
            return QGraphicsItemGroup.mousePressEvent(self, event)
        else:
            self._drag_enable = True

            # required to get the itemChanged event to work
            # correctly for this
            self.setSelected(True)

            # self.selectionbox.resetTransform()
            self.selectionbox.resetPosition()
            self.selectionbox.refreshPath()

            # self.selectionbox.resetTransform()
            self.selectionbox.resetPosition()
            self.selectionbox.show()

            # for some reason we need to skip the first mouseMoveEvent
            self._dragged = False

            if self._added_to_press_list is False:
                self._added_to_press_list = True
                self.scene().views()[0].addToPressList(self)
            return QGraphicsItemGroup.mousePressEvent(self, event)
Exemple #30
0
    def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
        """Parses a :class:`QGraphicsSceneMouseEvent` to extract base index,
        forwarding them to approproate tool method as necessary.

        Args:
            event:
        """
        active_tool_str = self._getActiveTool().methodPrefix()
        self.scene().views()[0].addToPressList(self)
        idx = int(floor((event.pos().x()) / _BASE_WIDTH))
        self._virtual_helix_item.setActive(self.is_forward, idx)
        tool_method_name = active_tool_str + "MousePress"
        if hasattr(self, tool_method_name):
            getattr(self, tool_method_name)(event, idx)
        else:
            event.setAccepted(False)
Exemple #31
0
    def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
        """Handler for user mouse press.

        Args:
            event: Contains item, scene, and screen
            coordinates of the the event, and previous event.
        """
        # self.show()
        if event.button() != Qt.LeftButton:
            return QGraphicsItemGroup.mousePressEvent(self, event)
        else:
            self._drag_enable = True

            # required to get the itemChanged event to work
            # correctly for this
            self.setSelected(True)

            # self.selectionbox.resetTransform()
            self.selectionbox.resetPosition()
            self.selectionbox.refreshPath()

            # self.selectionbox.resetTransform()
            self.selectionbox.resetPosition()
            self.selectionbox.show()

            # for some reason we need to skip the first mouseMoveEvent
            self._dragged = False

            if self._added_to_press_list is False:
                self._added_to_press_list = True
                self.scene().views()[0].addToPressList(self)
            return QGraphicsItemGroup.mousePressEvent(self, event)
    def startLine(self, event: QGraphicsSceneMouseEvent):
        """ Start drawing a line

            When the mouse button is pressed and we are in single character
            dialog this method is activated to start drowning a line in the
            character

            Args:
               event (QGraphicsSceneMouseEvent) : the event description
        """
        # There are 2 modes for the presentation:
        # Original mode where the character is it's original size
        # After setting mode when the set was done and the character fullfill all
        # the item's space
        # Drawing can be done only in original mode
        if self.wasSetted:
            QMessageBox.critical(None, "Char identifier window", "The shape was already setted use revert setting")
            return

        # If this is the first start of a line - generate the QPainterPath and QGraphicsPathItem
        if self.charPath is None:
            self.initCharPath()

        # Move to the mouse position
        point = event.scenePos()
        path = self.charPath.path()
        path.moveTo(point)
        self.charPath.setPath(path)
        self.dirty = True
    def startLine(self, event: QGraphicsSceneMouseEvent):
        """ Start drawing a line

            When the mouse button is pressed and we are in single character
            dialog this method is activated to start drowning a line in the
            character

            Args:
               event (QGraphicsSceneMouseEvent) : the event description
        """
        # There are 2 modes for the presentation:
        # Original mode where the character is it's original size
        # After setting mode when the set was done and the character fullfill all
        # the item's space
        # Drawing can be done only in original mode
        if self.wasSetted:
            QMessageBox.critical(
                None, "Char identifier window",
                "The shape was already setted use revert setting")
            return

        # If this is the first start of a line - generate the QPainterPath and QGraphicsPathItem
        if self.charPath is None:
            self.initCharPath()

        # Move to the mouse position
        point = event.scenePos()
        path = self.charPath.path()
        path.moveTo(point)
        self.charPath.setPath(path)
        self.dirty = True
Exemple #34
0
    def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
        """Parses a :class:`QGraphicsSceneMouseEvent` to extract base index,
        forwarding them to approproate tool method as necessary.

        Args:
            event:
        """
        active_tool_str = self._getActiveTool().methodPrefix()
        self.scene().views()[0].addToPressList(self)
        idx = int(floor((event.pos().x()) / _BASE_WIDTH))
        self._virtual_helix_item.setActive(self.is_forward, idx)
        tool_method_name = active_tool_str + "MousePress"
        if hasattr(self, tool_method_name):
            getattr(self, tool_method_name)(event, idx)
        else:
            event.setAccepted(False)
Exemple #35
0
 def mouseMoveEvent(self, ev: QGraphicsSceneMouseEvent):
     if ev.buttons() == Qt.NoButton:
         return
     pos = ev.scenePos()
     if self._lastItemClicked is None or not self._lastItemClicked.isSelected(
     ):
         return
     itList = self.selectedItems()
     if len(itList) > 0:
         self._wasMoving = True
         x = pos.x() - self._lastPos.x()
         y = pos.y() - self._lastPos.y()
         x = PFSUndoMouseMove(itList, x, y)
         self._page._net.undoStack.push(x)
         self._lastPos = pos
         self.update()
Exemple #36
0
    def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
        """All mousePressEvents are passed to the group if it's in a group

        Args:
            event: Description
        """
        selection_group = self.group()
        if selection_group is not None:
            selection_group.mousePressEvent(event)
        elif event.button() == Qt.RightButton:
            current_filter_set = self._viewroot.selectionFilterSet()
            if self.FILTER_NAME in current_filter_set and self.part().isZEditable():
                self._right_mouse_move = True
                self.drag_last_position = event.scenePos()
                self.handle_start = self.pos()
        else:
            QGraphicsItem.mousePressEvent(self, event)
    def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
        """Special case for xovers and select tool, for now

        Args:
            event: Description
        """
        if self._getActiveTool().methodPrefix() == "selectTool":
            event.setAccepted(False)
            s_i = self._strand_item
            viewroot = s_i.viewroot()
            current_filter_set = viewroot.selectionFilterSet()
            if (all(f in current_filter_set for f in s_i.strandFilter())
                    and self.FILTER_NAME in current_filter_set):
                print("Accepter xoveritem")
                event.setAccepted(True)
                selection_group = viewroot.strandItemSelectionGroup()
                mod = Qt.MetaModifier
                if not (event.modifiers() & mod):
                    selection_group.clearSelection(False)
                selection_group.setSelectionLock(selection_group)
                # self.setSelectedColor(True)
                selection_group.pendToAdd(self)
                selection_group.processPendingToAddList()
                return selection_group.mousePressEvent(event)
        else:
            event.setAccepted(False)
Exemple #38
0
    def mouseMoveEvent(self, event: QGraphicsSceneMouseEvent):
        """Parses a :class:`QGraphicsSceneMouseEvent` to extract base index,
        forwarding them to approproate tool method as necessary.

        Args:
            event:
        """
        tool_method_name = self._getActiveTool().methodPrefix() + "MouseMove"
        if hasattr(self, tool_method_name):
            idx = int(floor((event.pos().x()) / _BASE_WIDTH))
            getattr(self, tool_method_name)(idx)
Exemple #39
0
 def paintToolMousePress(self, event: QGraphicsSceneMouseEvent, idx: int):
     """Add an insert to the strand if possible.
     Called by XoverItem.paintToolMousePress with event as None
     """
     m_strand = self._model_strand
     if event is None:
         color = m_strand.oligo().getColor()
     elif event.modifiers() & Qt.ShiftModifier:
         color = self.window().path_color_panel.shiftColorName()
     else:
         color = self.window().path_color_panel.colorName()
     m_strand.oligo().applyColor(color)
Exemple #40
0
 def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
     """Parses a :meth:`mousePressEvent`, calling the appropriate tool
     method as necessary. Stores ``_move_idx`` for future comparison.
     """
     self.scene().views()[0].addToPressList(self)
     idx = self._strand_item.setActiveEndpoint(self.cap_type)
     self._move_idx = idx
     active_tool_str = self._getActiveTool().methodPrefix()
     tool_method_name = active_tool_str + "MousePress"
     if hasattr(self, tool_method_name):  # if the tool method exists
         modifiers = event.modifiers()
         getattr(self, tool_method_name)(modifiers, event, self.idx())
    def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
        """Parses a :meth:`mousePressEvent` to extract strand_set and base index,
        forwarding them to approproate tool method as necessary.

        Args:
            event: Description
        """
        # 1. Check if we are doing a Z translation
        if event.button() == Qt.RightButton:
            viewroot = self._viewroot
            current_filter_set = viewroot.selectionFilterSet()
            if self.FILTER_NAME in current_filter_set and self.part().isZEditable():
                self._right_mouse_move = True
                self.drag_last_position = event.scenePos()
                self.handle_start = self.pos()
            return

        self.scene().views()[0].addToPressList(self)
        strand_set, idx = self.baseAtPoint(event.pos())
        self._model_part.setActiveVirtualHelix(self._id_num, strand_set.isForward(), idx)
        tool = self._getActiveTool()
        tool_method_name = tool.methodPrefix() + "MousePress"

        if hasattr(self, tool_method_name):
            self._last_strand_set, self._last_idx = strand_set, idx
            getattr(self, tool_method_name)(strand_set, idx, event.modifiers())
        else:
            event.setAccepted(False)
Exemple #42
0
    def selectToolMousePress(self, event: QGraphicsSceneMouseEvent, idx: int):
        """Mouse press over the strand for select tool

        Args:
            event (:obj:`PyQt5.QtGui.QMouseEvent`):
            idx (int):
        """
        event.setAccepted(False)
        current_filter_set = self._viewroot.selectionFilterSet()
        if ( all(f in current_filter_set for f in self.strandFilter()) and
            self.FILTER_NAME in current_filter_set):
            selection_group = self._viewroot.strandItemSelectionGroup()
            mod = Qt.MetaModifier
            if not (event.modifiers() & mod):
                selection_group.clearSelection(False)
            selection_group.setSelectionLock(selection_group)
            selection_group.pendToAdd(self)
            selection_group.pendToAdd(self._low_cap)
            selection_group.pendToAdd(self._high_cap)
            selection_group.processPendingToAddList()
            event.setAccepted(True)
            return selection_group.mousePressEvent(event)
    def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
        """Handler for user mouse press.

        Args:
            event: Contains item, scene, and screen
            coordinates of the the event, and previous event.
        """
        if event.button() == Qt.RightButton:
            return
        part = self._model_part
        part.setSelected(True)
        if self.isMovable():
            return QGraphicsItem.mousePressEvent(self, event)
        tool = self._getActiveTool()
        if tool.FILTER_NAME not in part.document().filter_set:
            return
        tool_method_name = tool.methodPrefix() + "MousePress"
        if hasattr(self, tool_method_name):
            getattr(self, tool_method_name)(tool, event)
        else:
            event.setAccepted(False)
            QGraphicsItem.mousePressEvent(self, event)
    def createToolMousePress(self, tool: AbstractGridToolT,
                                event: QGraphicsSceneMouseEvent,
                                alt_event=None):
        """Summary

        Args:
            tool: Description
            event: Description
            alt_event (None, optional): Description
        """
        # 1. get point in model coordinates:
        part = self._model_part
        if alt_event is None:
            pt = tool.eventToPosition(self, event)
        else:
            pt = alt_event.pos()

        if pt is None:
            tool.deactivate()
            return QGraphicsItem.mousePressEvent(self, event)

        part_pt_tuple: Vec3T = self.getModelPos(pt)

        mod = Qt.MetaModifier
        if not (event.modifiers() & mod):
            pass

        # don't create a new VirtualHelix if the click overlaps with existing
        # VirtualHelix
        current_id_num = tool.idNum()
        check = part.isVirtualHelixNearPoint(part_pt_tuple, current_id_num)
        # print("current_id_num", current_id_num, check)
        # print(part_pt_tuple)
        tool.setPartItem(self)
        if check:
            id_num = part.getVirtualHelixAtPoint(part_pt_tuple)
            # print("got a check", id_num)
            if id_num >= 0:
                # print("restart", id_num)
                vhi = self._virtual_helix_item_hash[id_num]
                tool.setVirtualHelixItem(vhi)
                tool.startCreation()
        else:
            # print("creating", part_pt_tuple)
            part.createVirtualHelix(*part_pt_tuple)
            id_num = part.getVirtualHelixAtPoint(part_pt_tuple)
            vhi = self._virtual_helix_item_hash[id_num]
            tool.setVirtualHelixItem(vhi)
            tool.startCreation()
Exemple #45
0
 def mouseMoveEvent(self, event: QGraphicsSceneMouseEvent):
     """Converts event coords into an idx delta and updates if changed.
     """
     delta = int(floor((self.x()+event.pos().x()) / BASE_WIDTH)) - self._offset_idx
     delta = util.clamp(delta,
                        self._low_drag_bound-self._start_idx_low,
                        self._high_drag_bound-self._start_idx_high+self.width())
     if self._delta != delta:
         self._idx_low = int(self._start_idx_low + delta)
         self._idx_high = int(self._start_idx_high + delta)
         self._delta = delta
         self.reconfigureRect((), ())
         self.resize_handle_group.updateText(HandleEnum.LEFT, self._idx_low)
         self.resize_handle_group.updateText(HandleEnum.RIGHT, self._idx_high)
     return QGraphicsItem.mouseMoveEvent(self, event)
Exemple #46
0
 def mouseReleaseEvent(self, event: QGraphicsSceneMouseEvent):
     """Repeates mouseMove calculation in case any new movement.
     """
     self.setCursor(Qt.ArrowCursor)
     delta = int(floor((self.x()+event.pos().x()) / BASE_WIDTH)) - self._offset_idx
     delta = util.clamp(delta,
                        self._low_drag_bound-self._start_idx_low,
                        self._high_drag_bound-self._start_idx_high+self.width())
     if self._delta != delta:
         self._idx_low = int(self._start_idx_low + delta)
         self._idx_high = int(self._start_idx_high + delta)
         self._delta = delta
         self.reconfigureRect((), ())
     self._high_drag_bound = self._model_part.getProperty('max_vhelix_length')  # reset for handles
     return QGraphicsItem.mouseReleaseEvent(self, event)
 def mouseReleaseEvent(self, event: QGraphicsSceneMouseEvent):
     """
     Args:
         event: Description
     """
     MOVE_THRESHOLD = 0.01   # ignore small moves
     if self._right_mouse_move and event.button() == Qt.RightButton:
         self._right_mouse_move = False
         delta = self.pos() - self.handle_start
         dz = delta.x()
         if abs(dz) > MOVE_THRESHOLD:
             dz = self._part_item.convertToModelZ(dz)
             self._model_part.translateVirtualHelices([self.idNum()],
                                                      0, 0, dz, True,
                                                      use_undostack=True)
    def mouseMoveEvent(self, event: QGraphicsSceneMouseEvent):
        """Parses a :meth:`mouseMoveEvent` to extract strand_set and base index,
        forwarding them to approproate tool method as necessary.

        Args:
            event: Description
        """
        # 1. Check if we are doing a Z translation
        if self._right_mouse_move:
            MOVE_THRESHOLD = 0.01   # ignore small moves
            new_pos = event.scenePos()
            delta = new_pos - self.drag_last_position
            dx = int(floor(delta.x() / _BASE_WIDTH))*_BASE_WIDTH
            x = self.handle_start.x() + dx
            if abs(dx) > MOVE_THRESHOLD or dx == 0.0:
                old_x = self.x()
                self.setX(x)
                vhi_h = self._handle
                vhi_h.tempReparent()
                vhi_h.setX(x - _VH_XOFFSET)
                self._part_item.updateXoverItems(self)
                dz = self._part_item.convertToModelZ(x - old_x)
                self._model_part.translateVirtualHelices([self.idNum()],
                                                         0, 0, dz, False,
                                                         use_undostack=False)
                return
        # 2. Forward event to tool
        tool = self._getActiveTool()
        tool_method_name = tool.methodPrefix() + "MouseMove"
        if hasattr(self, tool_method_name):
            strand_set, idx = self.baseAtPoint(event.pos())
            if self._last_strand_set != strand_set or self._last_idx != idx:
                self._last_strand_set, self._last_idx = strand_set, idx
                getattr(self, tool_method_name)(strand_set, idx)
        else:
            event.setAccepted(False)
Exemple #49
0
    def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
        """
        Parses a mousePressEvent, calling the approproate tool method as
        necessary. Stores _move_idx for future comparison.

        Args:
            event: Description
        """
        self.scene().views()[0].addToPressList(self)
        self._strand_item.setActiveEndpoint(self.cap_type)
        self._move_idx = self.idx()
        active_tool_str = self._getActiveTool().methodPrefix()
        if active_tool_str == 'createTool':
            return self._strand_item.createToolMousePress(self.idx())
        tool_method_name = active_tool_str + "MousePress"
        if hasattr(self, tool_method_name):  # if the tool method exists
            modifiers = event.modifiers()
            getattr(self, tool_method_name)(modifiers)  # call tool method
Exemple #50
0
    def mouseReleaseEvent(self, event: QGraphicsSceneMouseEvent):
        """because :class:`GridSelectionGroup` has the flag
        ``QGraphicsItem.ItemIsMovable`` we need only get the position of the
        item to figure out what to submit to the model

        Args:
            event: the mouse event
        """
        MOVE_THRESHOLD = 0.01   # ignore small moves
        # print("mouse mouseReleaseEvent", self.tool.individual_pick)
        if not self.tool.individual_pick and event.button() == Qt.LeftButton:
            delta = self.pos() - self.drag_start_position
            dx, dy = delta.x(), delta.y()
            # print(abs(dx), abs(dy))
            if abs(dx) > MOVE_THRESHOLD or abs(dy) > MOVE_THRESHOLD:
                # print("finalizling", dx, dy)
                self.tool.moveSelection(dx, dy, True)
        self.tool.individual_pick = False
        return QGraphicsItemGroup.mouseReleaseEvent(self, event)
Exemple #51
0
    def mouseMoveEvent(self, event: QGraphicsSceneMouseEvent):
        """because :class:`GridSelectionGroup` has the flag
        ``QGraphicsItem.ItemIsMovable`` we need only get the position of the
        item to figure out what to submit to the model

        Args:
            event: the mouse evenet
        """
        # 1. call this super class method first to get the item position updated
        res = QGraphicsItemGroup.mouseMoveEvent(self, event)
        # watch out for bugs here?  everything seems OK for now, but
        # could be weird window switching edge cases
        if not self.tool.individual_pick and event.buttons() == Qt.LeftButton:
            new_pos = self.pos()
            delta = new_pos - self.drag_last_position
            self.drag_last_position = new_pos
            dx, dy = delta.x(), delta.y()
            self.tool.moveSelection(dx, dy, False, use_undostack=False)
        return res
    def mouseMoveEvent(self, event: QGraphicsSceneMouseEvent):
        """ Mouse move event : continue draw a line

            This event is activated when the mouse is pressed and moves

            The methods draws the line in 2 conditions:
            -# The item is not part of multi character presentation
            -# A character path was initiated (using the mouse press event)

            Args:
               event (QGraphicsSceneMouseEvent) : the event description
        """
        if self.viewIndex == -1:
            if self.charPath is not None:
                point = event.scenePos()
                path = self.charPath.path()
                path.lineTo(point)
                self.charPath.setPath(path)
                self.update()
Exemple #53
0
 def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
     """
     Args:
         event: Description
     """
     if event.pos().y() < 10:
         new_color = self.colordialog.getColor(self._shift_color)
         if new_color.isValid() and new_color.name() != self._shift_color.name():
             self._shift_color = new_color
             self._shift_brush = QBrush(new_color)
             if new_color not in self._shift_colors:
                 self._shift_colors.insert(self._shift_color_index, new_color)
             self.update()
     else:
         new_color = self.colordialog.getColor(self._color)
         if new_color.isValid() and new_color.name() != self._color.name():
             self._color = new_color
             self._brush = QBrush(new_color)
             if new_color not in self._colors:
                 self._colors.insert(self._color_index, new_color)
             self.update()
    def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
        """Event handler for when the mouse button is pressed inside
        this item. If a tool-specific mouse press method is defined, it will be
        called for the currently active tool. Otherwise, the default
        :meth:`QGraphicsItem.mousePressEvent` will be called.

        Note:
            Only applies the event if the clicked item is in the part
            item's active filter set.

        Args:
            event: contains parameters that describe the mouse event.
        """
        if self.FILTER_NAME not in self._part_item.getFilterSet():
            return
        if event.button() == Qt.RightButton:
            return
        part_item = self._part_item
        tool = part_item._getActiveTool()
        tool_method_name = tool.methodPrefix() + "MousePress"
        if hasattr(self, tool_method_name):
            getattr(self, tool_method_name)(tool, part_item, event)
        else:
            QGraphicsItem.mousePressEvent(self, event)
Exemple #55
0
    def mouseMoveEvent(self, event: QGraphicsSceneMouseEvent):
        """
        Args:
            event: Description
        """
        if self._drag_enable is True:

            # map the item to the scene coordinates
            # to help keep coordinates uniform
            rf = self.getR(self.mapFromScene(QPointF(event.scenePos())))
            # for some reason we need to skip the first mouseMoveEvent
            if self._dragged is False:
                self._dragged = True
                self._r0 = rf
            # end if
            else:
                delta = self.selectionbox.delta(rf, self._r0)
                self.translateR(delta)
                # logger.debug('mouse move path selectionbox', delta, rf, self._r0)
            # end else
            self._r = rf
        # end if
        else:
            QGraphicsItemGroup.mouseMoveEvent(self, event)