Esempio n. 1
0
 def mousePressEvent(self, event: QMouseEvent) -> None:
     if self._chartIsSet and self._panEnabled and event.button(
     ) == Qt.MiddleButton:
         self._mousePressEventPos = event.pos()
         self._panOn = True
         QApplication.setOverrideCursor(QCursor(Qt.ClosedHandCursor))
     super().mousePressEvent(event)
Esempio n. 2
0
    def mousePressEvent(self, event: QMouseEvent):
        state = self._get_state_cb()

        for node_id, node in state.items():
            if intersect_node(node, event.pos()):
                self._clicked_node_id = node_id
                self._last_click_pos = event.pos()
    def mouseMoveEvent(self, event: QMouseEvent) -> None:
        count: int = self.__listValue.__len__()
        if count <= 1: return

        pos: int = event.pos().x() if self.__horizontal else event.pos().y()
        target: int = self.width() if self.__horizontal else self.height()
        index: int = self.__listValue.index(self.__currentValue)

        if self.__pressed:
            # 数值到边界时,阻止继续往对应方向移动
            if index is 0 and pos >= self.__pressedPos or index is count - 1 and pos <= self.__pressedPos:
                return

            self.__offset = pos - self.__pressedPos

            # 若移动速度过快时进行限制
            if self.__offset > target // self.__percent:
                self.__offset = target // self.__percent
            elif self.__offset < -target // self.__percent:
                self.__offset = -target // self.__percent

            if self.__oldIndex != index:
                self.currentIndexChanged.emit(index)
                self.currentValueChanged.emit(self.__listValue[index])
                self.__oldIndex = index

            self.update()
 def mouseMoveEvent(self, e: QMouseEvent):
     if e.buttons() & (Qt.RightButton | Qt.LeftButton):
         qDebug("mouseMoveEvent in Item...")
         self.__m_lastMouseMove = self.__cloneMouseEvent(e)
         self.__m_lastMouseMove.ignore()
         e.accept()
         self.update()
Esempio n. 5
0
 def mouseReleaseEvent(self, event_data: QMouseEvent):
     if self._ignoring_mouse_events:
         return
     if 0 <= event_data.x() <= self.width() and 0 <= event_data.y(
     ) <= self.height():
         event_data.accept()
         self.set_checked(not self.is_checked)
Esempio n. 6
0
 def mouseMoveEvent(self, event: QtGui.QMouseEvent) -> None:
     if self._pressed:
         option = QtWidgets.QStyleOptionSlider()
         self.initStyleOption(option)
         groove = self.style().subControlRect(
             QtWidgets.QStyle.CC_Slider,
             option,
             QtWidgets.QStyle.SC_SliderGroove,
             self,
         )
         handle = self.style().subControlRect(
             QtWidgets.QStyle.CC_Slider,
             option,
             QtWidgets.QStyle.SC_SliderHandle,
             self,
         )
         value = self.style().sliderValueFromPosition(
             self.minimum(), self.maximum(), event.pos().x(), groove.width()
         )
         handle.moveCenter(event.pos())
         handle = handle.marginsAdded(
             QtCore.QMargins(
                 handle.width(), handle.width(), handle.width(), handle.width()
             )
         )
         if self.hasTracking():
             self.setValue2(value)
             self.repaint(handle)
     else:
         super().mouseMoveEvent(event)
    def __init__(self):
        logging.debug('FboItem::__init__')
        super().__init__()
        self.__m_vtkFboRenderer = None
        self.__m_processingEngine: ProcessingEngine = None

        self.__m_commandsQueue: queue.Queue = queue.Queue()  # CommandModel
        self.__m_commandsQueueMutex = threading.Lock()

        self.__m_modelsRepresentationOption: int = 2
        self.__m_modelsOpacity: float = 1.0
        self.__m_gouraudInterpolation: bool = False
        self.__m_modelColorR: int = 3
        self.__m_modelColorG: int = 169
        self.__m_modelColorB: int = 244

        self.__m_lastMouseLeftButton: QMouseEvent = QMouseEvent(
            QEvent.Type.None_, QPointF(0, 0), Qt.NoButton, Qt.NoButton,
            Qt.NoModifier)
        self.__m_lastMouseButton: QMouseEvent = QMouseEvent(
            QEvent.Type.None_, QPointF(0, 0), Qt.NoButton, Qt.NoButton,
            Qt.NoModifier)
        self.__m_lastMouseMove: QMouseEvent = QMouseEvent(
            QEvent.Type.None_, QPointF(0, 0), Qt.NoButton, Qt.NoButton,
            Qt.NoModifier)
        self.__m_lastMouseWheel: QWheelEvent = None

        self.setMirrorVertically(
            True)  # QtQuick and OpenGL have opposite Y-Axis directions
        self.setAcceptedMouseButtons(Qt.AllButtons)
Esempio n. 8
0
 def mousePressEvent(self, ev: QtGui.QMouseEvent):
     if self._mimetype == "GIF" and ev.button() == QtCore.Qt.LeftButton:
         ev.accept()
         self._toggle_movie_play()
     else:
         # If it's a right click or otherwise, pass it on
         ev.ignore()
Esempio n. 9
0
    def test_mouse_and_key_handlers(self):
        handler = Mock()
        control_handler = Mock()

        self.main_widget.controls.on_keydown = control_handler
        self.main_widget.controls.on_keyup = control_handler
        self.main_widget.controls.on_mouseclick = control_handler
        self.main_widget.controls.on_mousedrag = control_handler

        self.frame.set_keyup_handler(handler)
        self.frame.set_keydown_handler(handler)
        self.frame.set_mouseclick_handler(handler)
        self.frame.set_mousedrag_handler(handler)
        self.frame.start()

        key_press = QKeyEvent(QKeyEvent.KeyPress, Qt.Key_L, Qt.NoModifier)
        key_release = QKeyEvent(QKeyEvent.KeyRelease, Qt.Key_L, Qt.NoModifier)
        mouse_release = QMouseEvent(QMouseEvent.MouseButtonRelease, QPoint(75, 75),
                                    Qt.MiddleButton, Qt.NoButton, Qt.NoModifier)
        mouse_move = QMouseEvent(QMouseEvent.MouseMove, QPoint(100, 75),
                                    Qt.MiddleButton, Qt.NoButton, Qt.NoModifier)
        calls = [
            call((75, 75)),
            call((100, 75)),
            call(int(Qt.Key_L)),
            call(int(Qt.Key_L))
        ]

        self.main_widget.canvas.mouseReleaseEvent(mouse_release)
        self.main_widget.canvas.mouseMoveEvent(mouse_move)
        self.main_widget.canvas.keyPressEvent(key_press)
        self.main_widget.canvas.keyReleaseEvent(key_release)

        handler.assert_has_calls(calls)
        control_handler.assert_has_calls(calls)
 def mousePressEvent(self, e: QMouseEvent):
     if e.buttons() & (Qt.RightButton | Qt.LeftButton):
         print("mousePressEvent in Item...")
         self.__m_lastMouseButton = self.__cloneMouseEvent(e)
         self.__m_lastMouseButton.ignore()
         e.accept()
         self.update()
Esempio n. 11
0
    def eventFilter(self, watched, event: QtGui.QMouseEvent) -> bool:
        if isinstance(watched, CellWidget):
            if event.type() == QtCore.QEvent.MouseButtonPress:
                if event.buttons() == QtCore.Qt.LeftButton:
                    # start drag if it is possible
                    if self.dragAndDrop and watched.getPiece() \
                            and watched.getPiece().color == self.board.turn:
                        self._dragWidget = _DragWidget(self)
                        self._dragWidget.setAutoFillBackground(True)
                        self._dragWidget.setFixedSize(watched.size())
                        self._dragWidget.setScaledContents(True)
                        self._dragWidget.setStyleSheet(
                            "background: transparent;")
                        self._dragWidget.setPixmap(
                            QtGui.QPixmap(
                                f":/images/{'_'.join(watched.objectName().split('_')[1:])}.png"
                            ))

                        rect = self._dragWidget.geometry()
                        rect.moveCenter(QtGui.QCursor.pos())
                        self._dragWidget.setGeometry(rect)

                        watched.setChecked(not watched.isChecked())
                        return True

                elif event.buttons() == QtCore.Qt.RightButton:
                    # mark cell if it is possible
                    if self.accessibleSides != NO_SIDE:
                        watched.setMarked(not watched.marked)

        return watched.event(event)
Esempio n. 12
0
    def mouseMoveEvent(self, event: QMouseEvent):
        if self.mouse_mode == MODE_DRAG:
            self.setCursor(Qt.ClosedHandCursor)
            self._dragging(event)

        elif self.mouse_mode in RESIZE_MODES:
            previously_selected_objects = self.level_ref.selected_objects

            self._resizing(event)

            self.level_ref.selected_objects = previously_selected_objects

        elif self.selection_square.active:
            self._set_selection_end(event.pos())

        elif SETTINGS["resize_mode"] == RESIZE_LEFT_CLICK:
            self._set_cursor_for_position(event)

        x, y = event.pos().toTuple()

        object_under_cursor = self.object_at(x, y)

        if SETTINGS[
                "object_tooltip_enabled"] and object_under_cursor is not None:
            self.setToolTip(str(object_under_cursor))
        else:
            self.setToolTip("")
            QToolTip.hideText()

        return super(LevelView, self).mouseMoveEvent(event)
Esempio n. 13
0
    def _set_cursor_for_position(self, event: QMouseEvent):
        level_object = self.object_at(*event.pos().toTuple())

        if level_object is not None:
            is_resizable = not level_object.is_single_block

            edges = self._cursor_on_edge_of_object(level_object, event.pos())

            if is_resizable and edges:
                if edges == Qt.RightEdge and level_object.expands(
                ) & EXPANDS_HORIZ:
                    cursor = Qt.SizeHorCursor
                elif edges == Qt.BottomEdge and level_object.expands(
                ) & EXPANDS_VERT:
                    cursor = Qt.SizeVerCursor
                elif (level_object.expands() & EXPANDS_BOTH) == EXPANDS_BOTH:
                    cursor = Qt.SizeFDiagCursor
                else:
                    return

                if self.mouse_mode not in RESIZE_MODES:
                    self.setCursor(cursor)

                return

        if self.mouse_mode not in RESIZE_MODES:
            self.setCursor(Qt.ArrowCursor)
Esempio n. 14
0
    def mouseReleaseEvent(self, event):
        """

        :param QMouseEvent event:
        :return:
        """

        if event.button() == Qt.LeftButton:
            if self._is_dragging:
                self.viewport().setCursor(Qt.ArrowCursor)
                event.accept()

        if not event.isAccepted():
            # create a new event and dispatch it to the scene
            pressy = QMouseEvent(QEvent.MouseButtonPress, event.pos(),
                                 event.globalPos(), event.button(),
                                 event.buttons(), event.modifiers())

            press_event = self.dispatchMouseEventToScene(pressy)

            releasy = QMouseEvent(QEvent.MouseButtonRelease, event.pos(),
                                  event.globalPos(), event.buton(),
                                  event.buttons(), event.modifiers())
            release_event = self.dispatchMouseEventToScene(releasy)

            if not release_event.isAccepted():
                self.on_background_click()
                release_event.accept()
            self._is_mouse_pressed = False
            self._is_dragging = False

        super().mouseReleaseEvent(event)
Esempio n. 15
0
 def mouseReleaseEvent(self, event: QMouseEvent):
     self.logger.debug(event.pos())
     self.bottomright = (event.pos().x(), event.pos().y())
     self.isDragging = False
     if not self.validClipRect(self.topleft, self.bottomright):
         msg = f"不正な選択範囲:選択範囲は左上から右下へ選択してください"
         self.logger.warning(msg)
         self.parent_window.wakeup(msg, "")
         self.hide()
         return
     cropped = self.img.crop((self.topleft[0], self.topleft[1],
                              self.bottomright[0], self.bottomright[1]))
     try:
         ocr = OCRfromPILImage(cropped)
     except Exception as ex:
         import traceback
         traceback.print_exc()
         ocr = "OCR ERROR!!"
     #設定で有効であればクリップボードコピー
     if Config.config["copy_to_clipboard"] is True:
         pyperclip.copy(ocr)
     try:
         ja = Translate(ocr)
     except Exception as ex:
         ja = "TRANSLATE ERROR!!"
     self.parent_window.wakeup(ocr, ja)
     self.hide()
Esempio n. 16
0
    def mouseReleaseEvent(self, event: QtGui.QMouseEvent) -> None:
        if self._pressed:
            self._pressed = False
            option = QtWidgets.QStyleOptionSlider()
            self.initStyleOption(option)
            groove = self.style().subControlRect(
                QtWidgets.QStyle.CC_Slider,
                option,
                QtWidgets.QStyle.SC_SliderGroove,
                self,
            )
            handle = self.style().subControlRect(
                QtWidgets.QStyle.CC_Slider,
                option,
                QtWidgets.QStyle.SC_SliderHandle,
                self,
            )
            value = self.style().sliderValueFromPosition(
                self.minimum(), self.maximum(), event.pos().x(), groove.width()
            )
            handle.moveCenter(event.pos())
            handle = handle.marginsAdded(
                QtCore.QMargins(
                    handle.width(), handle.width(), handle.width(), handle.width()
                )
            )
            value = self.style().sliderValueFromPosition(
                self.minimum(), self.maximum(), event.pos().x(), groove.width()
            )
            self.setSliderDown(False)
            self.setValue2(value)
            self.update()

        super().mouseReleaseEvent(event)
Esempio n. 17
0
    def mouseMoveEvent(self,
                       event: QtGui.QMouseEvent) -> None:  # pragma: no cover
        if (not event.buttons() & QtCore.Qt.LeftButton
                or (event.pos() - self.drag_start_pos).manhattanLength() <
                QtWidgets.QApplication.startDragDistance()):
            return super().mouseMoveEvent(event)
        index = self.tabAt(event.pos())
        if index == -1:
            return super().mouseMoveEvent(event)

        rect = self.tabRect(index)
        pixmap = QtGui.QPixmap(rect.size())
        self.render(pixmap, QtCore.QPoint(), QtGui.QRegion(rect))

        mime_data = QtCore.QMimeData()
        mime_data.setData("application/x-pew2tabbar",
                          QtCore.QByteArray().number(index))

        drag = QtGui.QDrag(self)
        drag.setMimeData(mime_data)
        drag.setPixmap(pixmap)
        drag.setDragCursor(
            QtGui.QCursor(QtCore.Qt.DragMoveCursor).pixmap(),
            QtCore.Qt.MoveAction)
        drag.exec_(QtCore.Qt.MoveAction)
Esempio n. 18
0
 def mousePressEvent(self, event: QtGui.QMouseEvent):
     if event.button() == QtCore.Qt.RightButton:
         entry = self.actionAt(event.pos())
         if entry is not None:
             plugin_name = entry.text()
             options = []
             escape = False
             new_screen = self.pyUbiForge.right_click_plugins.get_screen_options(
                 plugin_name, options)
             while new_screen is not None and not escape:
                 # show screen
                 screen = PluginOptionsScreen(self.pyUbiForge, plugin_name,
                                              new_screen)
                 escape = screen.escape
                 if not escape:
                     # pull options from screen
                     options.append(screen.options)
                     new_screen = self.pyUbiForge.right_click_plugins.get_screen_options(
                         plugin_name, options)
             if not escape:
                 entry.trigger()
         else:
             QtWidgets.QMenu.mousePressEvent(self, event)
     elif event.button() == QtCore.Qt.LeftButton:
         QtWidgets.QMenu.mousePressEvent(self, event)
Esempio n. 19
0
 def mouseReleaseEvent(self, event: QtGui.QMouseEvent) -> None:
     if event.button() == QtCore.Qt.MouseButton.LeftButton:
         newReplaceable = self._calcReplaceable(event.pos())
         if self._replaceable is None or self._replaceable != newReplaceable:
             self._setReplaceable(newReplaceable)
         else:
             self._setReplaceable(None)
 def mousePressEvent(self, event: QMouseEvent):
     if event.button() == Qt.LeftButton:
         self.dragPosition = event.globalPos() - self.frameGeometry(
         ).topLeft()
         self.cursor = QCursor()
         self.cursor.setShape(Qt.SizeAllCursor)
         self.setCursor(self.cursor)
Esempio n. 21
0
    def mousePressEvent(self, event: QtGui.QMouseEvent):
        pos_real = self.convert_to_real((event.x(), event.y()))

        draw_image = ImageDraw.ImageDraw(self._working_image)
        draw_image.point(pos_real, (255, 0, 0, 255))
        print('Mouse press %s:%s' % pos_real)

        self.update()
Esempio n. 22
0
 def mouseMoveEvent(self, event: QMouseEvent):
     """
     Handle mouse move, moving the target view port to cursor position in target scene when mouse is pressed.
     """
     if self._is_mouse_pressed:
         self._target_view.centerOn(
             self.map_event_pos_to_target_scene_pos(event.pos()))
         event.accept()
Esempio n. 23
0
 def mouseReleaseEvent(self, event: QMouseEvent):
     """
     Handle mouse release, ending viewport drag.
     """
     if event.button() == Qt.LeftButton:
         self.setCursor(Qt.ArrowCursor)
         event.accept()
     self._is_mouse_pressed = False
 def selectModel(self, screenX: int, screenY: int):
     self.__m_lastMouseLeftButton = QMouseEvent(QEvent.Type.None_,
                                                QPointF(screenX, screenY),
                                                Qt.LeftButton,
                                                Qt.LeftButton,
                                                Qt.NoModifier)
     self.__m_lastMouseLeftButton.ignore()
     self.update()
Esempio n. 25
0
 def mouseMoveEvent(self, event: QtGui.QMouseEvent) -> None:
     if self.nav_pos is not None and self.allow_navigation:
         pos = event.pos()
         offset = self.nav_pos - pos
         self.chart().scroll(offset.x(), -offset.y())
         self.nav_pos = event.pos()
     else:
         super().mouseMoveEvent(event)
Esempio n. 26
0
 def mousePressEvent(self, event: QMouseEvent):
     if event.button() == Qt.LeftButton:
         self.logger.debug(self.topleft)
         self.topleft = (event.pos().x(), event.pos().y())
         self.isDragging = True
     elif event.button() == Qt.RightButton:
         self.parent_window.wakeup("", "")
         self.hide()
 def resetModelSelection(self):
     self.__m_lastMouseLeftButton = QMouseEvent(QEvent.None_,
                                                QPointF(-1,
                                                        -1), Qt.LeftButton,
                                                Qt.LeftButton,
                                                Qt.NoModifier)
     self.__m_lastMouseLeftButton.ignore()
     self.update()
Esempio n. 28
0
 def mouseMoveEvent(self, event: QtGui.QMouseEvent) -> None:
     if self.last_pos is not None:
         pos = event.pos()
         offset = self.last_pos - pos
         self.chart().scroll(offset.x(), 0)
         self.last_pos = event.pos()
     else:
         super().mouseMoveEvent(event)
Esempio n. 29
0
    def mousePressEvent(self, event: QtGui.QMouseEvent):

        self.opt.sliderPosition = self.first_position
        self._first_sc = self.style().hitTestComplexControl(
            QtWidgets.QStyle.CC_Slider, self.opt, event.pos(), self)

        self.opt.sliderPosition = self.second_position
        self._second_sc = self.style().hitTestComplexControl(
            QtWidgets.QStyle.CC_Slider, self.opt, event.pos(), self)
Esempio n. 30
0
    def mouseMoveEvent(self, event: QMouseEvent):
        if self.is_dragged():
            pos: QPoint = event.pos()
            delta: QPoint = self.last_drag_pos - pos
            self.last_drag_pos = pos

            self.camera.translate(-delta)
            self.camera.transformed.emit()
            event.accept()
Esempio n. 31
0
    def mousePressEvent(self, mouseEvent: QMouseEvent):
        closestNode = self.playerNode.closest(mouseEvent.pos() - self.paintOffset)
        direction = closestNode.row - self.playerNode.row, closestNode.column - self.playerNode.column
        crawlNode = self.playerNode.crawl(direction)

        self.animation = QPropertyAnimation(self, b"player", self)
        if len(crawlNode.links) > 2:
            self.animation.setEasingCurve(QEasingCurve.OutBack);
        else:
            self.animation.setEasingCurve(QEasingCurve.OutBounce);
        self.animation.setStartValue(self.player)
        self.animation.setEndValue(crawlNode.point)
        self.animation.setDuration(400)
        self.animation.start()

        self.playerNode = crawlNode
        if self.playerNode == self.finishNode:
            QMessageBox.information(self, self.tr("Victory!"), self.tr("You won :)"), QMessageBox.Ok)
            self.initMaze()