Python PyQt5.QtGui.QMouseEvent() Examples

The following are code examples for showing how to use PyQt5.QtGui.QMouseEvent(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: CvStudio   Author: haruiz   File: image_graphics_view.py    MIT License 6 votes vote down vote up
def mouseReleaseEvent(self, evt: QtGui.QMouseEvent) -> None:
        if evt.button() == QtCore.Qt.LeftButton:
            if self.selection_mode == SELECTION_MODE.BOX:
                roi: QRect=self._box_picker.geometry()
                roi: QRectF=self.mapToScene(roi).boundingRect()
                pixmap_rect = self._pixmap.boundingRect()
                self._box_picker.hide()
                if pixmap_rect == roi.united(pixmap_rect):
                    rect=EditableBox(roi)
                    rect.label=self.current_label
                    self._scene.addItem(rect)
                    self.selection_mode=SELECTION_MODE.NONE
                    self.setDragMode(QGraphicsView.ScrollHandDrag)

            elif self.selection_mode == SELECTION_MODE.FREE and self._current_free_path:
                # create polygon
                self._current_free_path: QGraphicsPathItem
                path_rect = self._current_free_path.boundingRect()
                pixmap_rect=self._pixmap.boundingRect()
                if pixmap_rect == path_rect.united(pixmap_rect):
                    path=self._current_free_path.path()
                    path_polygon=EditablePolygon()
                    path_polygon.label = self.current_label
                    self._scene.addItem(path_polygon)
                    for i in range(0,path.elementCount(),10):
                        x,y=path.elementAt(i).x,path.elementAt(i).y
                        path_polygon.addPoint(QPointF(x,y))
                self._scene.removeItem(self._current_free_path)
                self.selection_mode=SELECTION_MODE.NONE
                self.setDragMode(QGraphicsView.ScrollHandDrag)


        super(ImageViewer, self).mouseReleaseEvent(evt) 
Example 2
Project: base   Author: JdeRobot   File: hsvWidget.py    GNU General Public License v3.0 6 votes vote down vote up
def mousePressEvent(self, event):
	    
	    if event.button() == QtCore.Qt.LeftButton and self.draggin_idx == -1:
	        point = self._get_point(event)
	        #print(point)
	        event = QMouseEvent(QtCore.QEvent.MouseButtonPress, event.pos(), QtCore.Qt.LeftButton, QtCore.Qt.LeftButton, QtCore.Qt.NoModifier)
	        self.center = event.pos()
	        dist = self.points - point
	        #print('dist=',dist)
	        dist = dist[:,0]**2 + dist[:,1]**2
	        dist[dist>self.DELTA] = np.inf #obviate the distances above DELTA
	        if dist.min() < np.inf:
	            self.draggin_idx = dist.argmin()
	        #print(self.center.x(),self.center.y())

	        self.update() 
Example 3
Project: schmereo   Author: cmbruns   File: image_widget.py    GNU General Public License v2.0 6 votes vote down vote up
def mousePressEvent(self, event: QtGui.QMouseEvent):
        if not event.buttons() & Qt.LeftButton:
            return
        # drag detection
        self.drag_mode = self.latent_drag_mode
        if self.drag_mode == DragMode.CLIP_BOX:
            self.clip_box.press_state = self.clip_box.state
        wp = WindowPos.from_QPoint(event.pos())
        self.previous_mouse = wp
        # click detection
        self.maybe_clicking = True
        self.mouse_press_pos = QtCore.QPoint(event.pos().x(), event.pos().y())
        self.mouse_press_time = datetime.datetime.now()
        # cursor shape
        if self.drag_cursor != self.hover_cursor:
            self.setCursor(self.drag_cursor)
            self.update() 
Example 4
Project: nanovna-saver   Author: mihtjel   File: Chart.py    GNU General Public License v3.0 6 votes vote down vote up
def mousePressEvent(self, event: QtGui.QMouseEvent) -> None:
        if event.buttons() == QtCore.Qt.RightButton:
            event.ignore()
            return
        elif event.buttons() == QtCore.Qt.MiddleButton:
            # Drag event
            event.accept()
            self.moveStartX = event.x()
            self.moveStartY = event.y()
            return
        if event.modifiers() == QtCore.Qt.ShiftModifier:
            self.draggedMarker = self.getNearestMarker(event.x(), event.y())
        elif event.modifiers() == QtCore.Qt.ControlModifier:
            event.accept()
            self.draggedBox = True
            self.draggedBoxStart = (event.x(), event.y())
            return
        self.mouseMoveEvent(event) 
Example 5
Project: PyQt-multifunctional-uart-helper   Author: IronSublimate   File: widgetpainter.py    MIT License 5 votes vote down vote up
def mouseMoveEvent(self, a0: QtGui.QMouseEvent):
        # print("mousemove")
        # self.setStatusTip("123")
        x = int(a0.x() / self.width() * self.imgWidth)
        y = int(a0.y() / self.height() * self.imgHeight)
        s = "鼠标位置 x:{:4d},y:{:4d}".format(x, y)
        self.label_position.setText(s) 
Example 6
Project: pdash   Author: CPChain   File: login.py    GNU General Public License v3.0 5 votes vote down vote up
def mouseMoveEvent(self, e: QMouseEvent):
        self._endPos = e.pos() - self._startPos
        self.move(self.pos() + self._endPos) 
Example 7
Project: pdash   Author: CPChain   File: login.py    GNU General Public License v3.0 5 votes vote down vote up
def mousePressEvent(self, e: QMouseEvent):
        if e.button() == Qt.LeftButton:
            self._isTracking = True
            self._startPos = QPoint(e.x(), e.y()) 
Example 8
Project: pdash   Author: CPChain   File: login.py    GNU General Public License v3.0 5 votes vote down vote up
def mouseReleaseEvent(self, e: QMouseEvent):
        if e.button() == Qt.LeftButton:
            self._isTracking = False
            self._startPos = None
            self._endPos = None 
Example 9
Project: kawaii-player   Author: kanishka-linux   File: kawaii_player.py    GNU General Public License v3.0 5 votes vote down vote up
def send_fake_event(self, val):
        self.fake_mousemove_event = ("libmpv", True)
        pos = self.tab_5.cursor().pos()
        if not self.pointer_moved:
            new_point = QtCore.QPoint(pos.x() + 1, pos.y())
            self.pointer_moved = True
        else:
            new_point = QtCore.QPoint(pos.x() - 1, pos.y())
            self.pointer_moved = False
        self.tab_5.cursor().setPos(new_point)
        if val == "mouse_release":
            event = QtGui.QMouseEvent(
                        QtCore.QEvent.MouseButtonRelease,
                        new_point,
                        QtCore.Qt.LeftButton,
                        QtCore.Qt.LeftButton,
                        QtCore.Qt.NoModifier,
                    )
        elif val == "mouse_move":
            event = QtGui.QMouseEvent(
                        QtCore.QEvent.MouseMove,
                        new_point,
                        QtCore.Qt.NoButton,
                        QtCore.Qt.NoButton,
                        QtCore.Qt.NoModifier,
                    )
        self.gui_signals.mouse_move_method((self.tab_5, event)) 
Example 10
Project: kawaii-player   Author: kanishka-linux   File: mpv_opengl.py    GNU General Public License v3.0 5 votes vote down vote up
def send_fake_event(self, val):
        self.fake_mousemove_event = ("libmpv", True)
        pos = self.cursor().pos()
        if not self.pointer_moved:
            new_point = QtCore.QPoint(pos.x() + 1, pos.y())
            self.pointer_moved = True
        else:
            new_point = QtCore.QPoint(pos.x() - 1, pos.y())
            self.pointer_moved = False
        self.cursor().setPos(new_point)
        if val == "mouse_release":
            event = QtGui.QMouseEvent(
                        QtCore.QEvent.MouseButtonRelease,
                        new_point,
                        QtCore.Qt.LeftButton,
                        QtCore.Qt.LeftButton,
                        QtCore.Qt.NoModifier,
                    )
        elif val == "mouse_move":
            event = QtGui.QMouseEvent(
                        QtCore.QEvent.MouseMove,
                        new_point,
                        QtCore.Qt.NoButton,
                        QtCore.Qt.NoButton,
                        QtCore.Qt.NoModifier,
                    )
        self.ui.gui_signals.mouse_move_method((self, event)) 
Example 11
Project: GeoMop   Author: GeoMop   File: mouse.py    GNU General Public License v3.0 5 votes vote down vote up
def event_swap_buttons(event, event_type):
    """
    Create copy of mouse 'event' with swapped buttons.
    :param event: QMouseEvent
    :param even_type: QEvent.MouseButtonPress, QEvent.MouseButtonRelease, QEvent.MouseMove
    :return: QMouseEvent with swaped buttons parameters.
    """
    button = event.button()
    if event.button() == Event.Right:
        button = Event.Left
    elif event.button() == Event.Left:
        button = Event.Right
    left_flag = bool( event.buttons() & Event.Left)
    right_flag = bool( event.buttons() & Event.Right)

    new_buttons = event.buttons()
    # set the swapped flags
    new_buttons = (new_buttons & ~Event.Left) | Event.Left * right_flag
    new_buttons = (new_buttons & ~Event.Right) | Event.Right * left_flag
    new_event = QtGui.QMouseEvent(event_type, event.localPos(), button, new_buttons, event.modifiers())
    return new_event 
Example 12
Project: vimiv-qt   Author: karlch   File: eventhandler.py    GNU General Public License v3.0 5 votes vote down vote up
def mousePressEvent(self, event: QMouseEvent):
        """Handle mouse press event for the widget."""
        api.status.clear("MousePressEvent")
        if not self._process_event(mouseevent_to_sequence(event)):
            super().mousePressEvent(event)  # type: ignore 
Example 13
Project: vimiv-qt   Author: karlch   File: eventhandler.py    GNU General Public License v3.0 5 votes vote down vote up
def mouseDoubleClickEvent(self, event: QMouseEvent):
        """Handle mouse press event for the widget."""
        api.status.clear("MouseDoubleClickEvent")
        if not self._process_event(
            mouseevent_to_sequence(event, prefix="double-button")
        ):
            super().mouseDoubleClickEvent(event)  # type: ignore 
Example 14
Project: vimiv-qt   Author: karlch   File: eventhandler.py    GNU General Public License v3.0 5 votes vote down vote up
def mouseevent_to_sequence(event: QMouseEvent, prefix: str = "button") -> SequenceT:
    """Convert QMouseEvent to meaningful string sequence."""
    button_names = {
        Qt.LeftButton: "left",
        Qt.MiddleButton: "middle",
        Qt.RightButton: "right",
        Qt.BackButton: "back",
        Qt.ForwardButton: "forward",
    }
    button = event.button()
    button_name = button_names[button] if button in button_names else str(button)
    return (*_get_modifier_names(event), f"<{prefix}-{button_name}>") 
Example 15
Project: vimiv-qt   Author: karlch   File: eventhandler.py    GNU General Public License v3.0 5 votes vote down vote up
def _get_modifier_names(event: Union[QKeyEvent, QMouseEvent]) -> List[str]:
    """Return the names of all modifiers pressed in the event."""
    modmask2str = {
        Qt.ControlModifier: "<ctrl>",
        Qt.AltModifier: "<alt>",
        Qt.MetaModifier: "<meta>",
    }
    modifiers = event.modifiers()
    return [
        mod_name
        for mask, mod_name in modmask2str.items()
        if modifiers & mask  # type: ignore
    ] 
Example 16
Project: vimiv-qt   Author: karlch   File: test_eventhandler.py    GNU General Public License v3.0 5 votes vote down vote up
def _create_mouse_event(button, modifier=Qt.NoModifier):
    return QMouseEvent(
        QEvent.MouseButtonPress, QPoint(0, 0), QPoint(0, 0), button, button, modifier
    ) 
Example 17
Project: vidcutter   Author: ozmartian   File: widgets.py    GNU General Public License v3.0 5 votes vote down vote up
def mousePressEvent(self, event: QMouseEvent) -> None:
            if event.button() == Qt.LeftButton:
                self.triggered.emit()
            super(VCFilterMenuAction.VCFilterMenuWidget, self).mousePressEvent(event) 
Example 18
Project: vidcutter   Author: ozmartian   File: mpvwidget.py    GNU General Public License v3.0 5 votes vote down vote up
def mousePressEvent(self, event: QMouseEvent) -> None:
        event.accept()
        if event.button() == Qt.LeftButton:
            if self.parent is None:
                self.originalParent.playMedia()
            else:
                self.parent.playMedia() 
Example 19
Project: vidcutter   Author: ozmartian   File: mpvwidget.py    GNU General Public License v3.0 5 votes vote down vote up
def mouseDoubleClickEvent(self, event: QMouseEvent) -> None:
        event.accept()
        if self.parent is None:
            self.originalParent.toggleFullscreen()
        else:
            self.parent.toggleFullscreen() 
Example 20
Project: vidcutter   Author: ozmartian   File: notifications.py    GNU General Public License v3.0 5 votes vote down vote up
def mousePressEvent(self, event: QMouseEvent):
        if event.button() == Qt.LeftButton:
            self.close() 
Example 21
Project: vidcutter   Author: ozmartian   File: videoslider.py    GNU General Public License v3.0 5 votes vote down vote up
def keyPressEvent(self, event: QKeyEvent) -> None:
        qApp.sendEvent(self.parent, event)

    # def mouseMoveEvent(self, event: QMouseEvent) -> None:
    #     opt = QStyleOptionSlider()
    #     self.initStyleOption(opt)
    #     handle = self.style().subControlRect(QStyle.CC_Slider, opt, QStyle.SC_SliderHandle, self)
    #     if handle.x() <= event.pos().x() <= (handle.x() + handle.width()):
    #         self.setCursor(Qt.PointingHandCursor)
    #         self._handleHover = True
    #     else:
    #         self.unsetCursor()
    #         self._handleHover = False
    #     self.initStyle()
    #     super(VideoSlider, self).mouseMoveEvent(event) 
Example 22
Project: vidcutter   Author: ozmartian   File: mediastream.py    GNU General Public License v3.0 5 votes vote down vote up
def mousePressEvent(self, event: QMouseEvent) -> None:
        if event.button() == Qt.LeftButton and self.checkbox is not None:
            self.checkbox.toggle()
        super(StreamSelectorLabel, self).mousePressEvent(event) 
Example 23
Project: vidcutter   Author: ozmartian   File: videolist.py    GNU General Public License v3.0 5 votes vote down vote up
def mouseMoveEvent(self, event: QMouseEvent) -> None:
        if self.count() > 0:
            if self.indexAt(event.pos()).isValid():
                self.setCursor(Qt.PointingHandCursor)
            else:
                self.setCursor(Qt.ArrowCursor)
        super(VideoList, self).mouseMoveEvent(event) 
Example 24
Project: PyQt5   Author: andresnino   File: barraTitulo.py    MIT License 5 votes vote down vote up
def mouseReleaseEvent(self, QMouseEvent):
        self.pressing = False 
Example 25
Project: PyQt5   Author: andresnino   File: barraTitulo.py    MIT License 5 votes vote down vote up
def mouseReleaseEvent(self, QMouseEvent):
        self.pressing = False 
Example 26
Project: CNNArt   Author: thomaskuestner   File: gridTable.py    Apache License 2.0 5 votes vote down vote up
def mouseReleaseEvent(self, event: QMouseEvent):
        event.accept()
        if event.button() == 1:
            self.released.emit(event) 
Example 27
Project: thegame   Author: afq984   File: view.py    MIT License 5 votes vote down vote up
def mouseMoveEvent(self, event: QMouseEvent):
        self.scene().mousePos = event.pos() 
Example 28
Project: Hydra   Author: CountryTk   File: foldArea.py    GNU General Public License v3.0 5 votes vote down vote up
def mousePressEvent(self, event: QMouseEvent):

        pattern = re.compile(FOLDING_PATTERN)
        blockedClickedOn: QTextBlock = self.getBlockUnderCursor(event)

        if pattern.match(blockedClickedOn.text()):

            if blockedClickedOn.userState() == 0:  # block and its contents are unfolded

                self.fold(blockedClickedOn)

            else:

                self.unfold(blockedClickedOn) 
Example 29
Project: Hydra   Author: CountryTk   File: foldArea.py    GNU General Public License v3.0 5 votes vote down vote up
def getBlockUnderCursor(self, event: QMouseEvent) -> QTextBlock:

        height = self.editor.fontMetrics().height()
        y = event.pos().y()

        for array in self.editor.currentlyVisibleBlocks:

            if array[0] < y < height + array[0]:

                return array[1] 
Example 30
Project: Hydra   Author: CountryTk   File: foldArea.py    GNU General Public License v3.0 5 votes vote down vote up
def mouseMoveEvent(self, event: QMouseEvent) -> None:

        pattern = re.compile(FOLDING_PATTERN)
        block: QTextBlock = self.editor.getBlockUnderCursor(event)

        if pattern.match(block.text()):

            cursor: QCursor = QCursor(Qt.PointingHandCursor)
            QApplication.setOverrideCursor(cursor)
            QApplication.changeOverrideCursor(cursor)

        else:

            self.returnCursorToNormal() 
Example 31
Project: Hydra   Author: CountryTk   File: numberBar.py    GNU General Public License v3.0 5 votes vote down vote up
def mousePressEvent(self, event: QMouseEvent):
        pass 
Example 32
Project: Hydra   Author: CountryTk   File: numberBar.py    GNU General Public License v3.0 5 votes vote down vote up
def getBlockUnderCursor(self, event: QMouseEvent) -> QTextBlock:
        height = self.editor.fontMetrics().height()
        y = event.pos().y()
        for array in self.editor.currentlyVisibleBlocks:
            print(array[0], y, height+array[0])
            if array[0] < y < height + array[0]:

                return array[1] 
Example 33
Project: programming_with_python   Author: royqh1979   File: main_graphicsview.py    MIT License 5 votes vote down vote up
def mouseMoveEvent(self, event: QtGui.QMouseEvent) -> None:
        event.ignore() 
Example 34
Project: programming_with_python   Author: royqh1979   File: 打冰雹游戏.py    MIT License 5 votes vote down vote up
def mouseMoveEvent(self, e: QtGui.QMouseEvent) -> None:
        p=QtCore.QPoint(e.x(),e.y())
        p=self.mapToGlobal(p)
        x,y=p.x(),p.y()
        p=QtCore.QPoint(self._ui.point_frame.width()/2,self._ui.point_frame.height()/2)
        p=self._ui.point_frame.mapToGlobal(p)
        x1,y1=p.x(),p.y()
        a=math.atan2(y1-y,x-x1)*180/math.pi
        self._ui.point_frame._angle=a
        self._ui.point_frame.update() 
Example 35
Project: CvStudio   Author: haruiz   File: card.py    MIT License 5 votes vote down vote up
def mouseDoubleClickEvent(self, evt: QtGui.QMouseEvent) -> None:
        if self.childAt(evt.pos()) == self.thumbnail.widget():
            self.doubleClicked.emit(self) 
Example 36
Project: CvStudio   Author: haruiz   File: card.py    MIT License 5 votes vote down vote up
def mousePressEvent(self, evt: QtGui.QMouseEvent) -> None:
        if evt.button() == QtCore.Qt.LeftButton:
            if self.childAt(evt.pos()) == self.thumbnail.widget():
                self.is_selected=not self.is_selected 
Example 37
Project: CvStudio   Author: haruiz   File: image_dialog.py    MIT License 5 votes vote down vote up
def mouseMoveEvent(self, event: QMouseEvent) -> None:
        # print('mouseMoveEvent: x=%d, y=%d' % (event.x(), event.y()))
        if not self.rect().contains(event.pos()):
            self.close() 
Example 38
Project: CvStudio   Author: haruiz   File: video_dialog.py    MIT License 5 votes vote down vote up
def mouseMoveEvent(self, event: QMouseEvent) -> None:
        # print('mouseMoveEvent: x=%d, y=%d' % (event.x(), event.y()))
        if not self.rect().contains(event.pos()):
            self.close() 
Example 39
Project: CvStudio   Author: haruiz   File: image_graphics_view.py    MIT License 5 votes vote down vote up
def mouseMoveEvent(self, evt: QtGui.QMouseEvent) -> None:
        if self.selection_mode == SELECTION_MODE.BOX:
            if not self._box_origin.isNull():
                self._box_picker.setGeometry(QRect(self._box_origin,evt.pos()).normalized())
        elif self.selection_mode == SELECTION_MODE.POLYGON:
            if self._current_polygon:
                if self._current_polygon.count > 0:
                    last_point: QPointF=self._current_polygon.last_point
                    self._polygon_guide_line.setZValue(1)
                    self._polygon_guide_line.show()
                    mouse_pos=self.mapToScene(evt.pos())
                    self._polygon_guide_line.setLine(last_point.x(),last_point.y(),mouse_pos.x(),mouse_pos.y())
            else:
                self._polygon_guide_line.hide()

        elif self.selection_mode == SELECTION_MODE.FREE and evt.buttons() and QtCore.Qt.LeftButton:
            if self._current_free_path:
                painter: QPainterPath=self._current_free_path.path()
                self._last_point_drawn=self.mapToScene(evt.pos())
                painter.lineTo(self._last_point_drawn)
                self._current_free_path.setPath(painter)

        super(ImageViewer, self).mouseMoveEvent(evt) 
Example 40
Project: CvStudio   Author: haruiz   File: image_button.py    MIT License 5 votes vote down vote up
def mouseDoubleClickEvent(self, evt: QtGui.QMouseEvent) -> None:
        self.doubleClicked.emit(evt) 
Example 41
Project: CvStudio   Author: haruiz   File: top_bar.py    MIT License 5 votes vote down vote up
def mousePressEvent(self, evt: QtGui.QMouseEvent) -> None:
        if evt.buttons() == QtCore.Qt.LeftButton:
            self.dragPos=evt.globalPos()
            evt.accept() 
Example 42
Project: CvStudio   Author: haruiz   File: top_bar.py    MIT License 5 votes vote down vote up
def mouseDoubleClickEvent(self, a0: QtGui.QMouseEvent) -> None:
        if self.window().windowState() == QtCore.Qt.WindowMaximized:
            self.window().showNormal()
        else:
            self.window().showMaximized() 
Example 43
Project: CvStudio   Author: haruiz   File: top_bar.py    MIT License 5 votes vote down vote up
def mouseMoveEvent(self, evt: QtGui.QMouseEvent) -> None:
        if evt.buttons() == QtCore.Qt.LeftButton:
            self.window().move(self.window().pos() + evt.globalPos()-self.dragPos)
            self.dragPos=evt.globalPos() 
Example 44
Project: sane-subfeed   Author: BluABK   File: subfeed_grid_view_tile.py    GNU Affero General Public License v3.0 5 votes vote down vote up
def mousePressEvent(self, event: QMouseEvent):
        """
        Override mousePressEvent to support mouse button actions
        :param event:
        :return:
        """
        if self.video.kind == VIDEO_KIND_VOD:
            if event.button() == Qt.LeftButton and QApplication.keyboardModifiers() == Qt.ControlModifier:
                self.logger.error("Not Implemented: Select video")
            elif event.button() == Qt.LeftButton:
                left_button_rebind = read_config('SubFeed', 'left_mouse_action', literal_eval=False)

                if left_button_rebind == MOUSE_PRESS_OPEN_URL:
                    self.open_in_browser()
                elif left_button_rebind == MOUSE_PRESS_COPY_URL:
                    self.copy_url(mark_watched=True)
                elif left_button_rebind == MOUSE_PRESS_PLAY_URL:
                    url_player = self.str_to_list(read_config('Player', 'default_player', literal_eval=False))
                    self.open_in_player(self.video.url_video, url_player, isfile=False)
                elif left_button_rebind == MOUSE_PRESS_DOWNLOAD:
                    self.mark_downloaded()
                elif left_button_rebind == MOUSE_PRESS_DOWNLOAD_AND_COPY:
                    self.copy_url()
                    self.mark_downloaded()

            elif event.button() == Qt.MidButton and QApplication.keyboardModifiers() == Qt.ControlModifier:
                self.decrease_prio()
            elif event.button() == Qt.MidButton:
                self.mark_discarded()

        elif self.video.kind == VIDEO_KIND_LIVE or self.video.kind == VIDEO_KIND_LIVE_SCHEDULED \
                or self.video.kind == VIDEO_KIND_PREMIERE:
            if event.button() == Qt.MidButton:
                self.mark_discarded()
            elif event.button() == Qt.LeftButton:
                self.root.confirmation_dialog(VIDEO_IS_LIVE_MSG, self.mark_downloaded, title=VIDEO_IS_LIVE_TITLE,
                                              ok_text="Yes, stream it.",
                                              cancel_text="Abort, abort, ABORT!") 
Example 45
Project: sane-subfeed   Author: BluABK   File: playback_grid_view_tile.py    GNU Affero General Public License v3.0 5 votes vote down vote up
def mousePressEvent(self, event: QMouseEvent):  # FIXME: Make mouse hotkeys based on hotkeys.ini
        """
        Override mousePressEvent to support mouse button actions
        :param event:
        :return:
        """
        if event.button() == Qt.MidButton and QApplication.keyboardModifiers() == Qt.ControlModifier:
            self.decrease_prio()
        elif event.button() == Qt.MidButton:
            self.mark_discarded()
        if event.button() == Qt.LeftButton and QApplication.keyboardModifiers() == Qt.ShiftModifier:
            self.open_in_player(self.video.vid_path, mark_watched=False)
        elif event.button() == Qt.LeftButton:
            self.open_in_player(self.video.vid_path) 
Example 46
Project: schmereo   Author: cmbruns   File: image_widget.py    GNU General Public License v2.0 5 votes vote down vote up
def mouseClickEvent(self, event: QtGui.QMouseEvent) -> None:
        self.maybe_clicking = False
        if self._add_marker_mode and (event.button() == Qt.LeftButton):
            image_pos = self.image_from_window_qpoint(event.pos())
            self.undo_stack.push(AddMarkerCommand(self, image_pos)) 
Example 47
Project: schmereo   Author: cmbruns   File: image_widget.py    GNU General Public License v2.0 5 votes vote down vote up
def mouseReleaseEvent(self, event: QtGui.QMouseEvent):
        # cursor shape
        if self.drag_cursor != self.hover_cursor:
            self.setCursor(self.hover_cursor)
        # drag detection
        if self.drag_mode == DragMode.CLIP_BOX and self.clip_box.press_state is not None and self.clip_box.press_state != self.clip_box.state:
            old_state = self.clip_box.press_state
            new_state = self.clip_box.state
            self.undo_stack.push(AdjustClipBoxCommand(self.clip_box, old_state, new_state))
        self.clip_box.press_state = None
        self.drag_mode = DragMode.NONE
        self.previous_mouse = None
        # click detection
        d2 = 1000
        if self.mouse_press_pos:
            dp = event.pos() - self.mouse_press_pos
            d2 = QtCore.QPoint.dotProduct(dp, dp)  # squared distance in pixels
        if d2 > 10:  # TODO: calibrate
            self.maybe_clicking = False  # too far
        dt = datetime.datetime.now() - self.mouse_press_time
        ms = dt.total_seconds() * 1000.0  # milliseconds
        if ms > 800:
            self.maybe_clicking = False
        if ms <= 0:
            self.maybe_clicking = False
        if self.maybe_clicking:
            self.mouseClickEvent(event)
        self.maybe_clicking = False
        self.mouse_press_pos = None 
Example 48
Project: FRHEED   Author: ecyoung3   File: FRHEED 2.0.2 for webcams.py    GNU General Public License v3.0 5 votes vote down vote up
def mousePressEvent(self, event: QtGui.QMouseEvent):
        global x1, y1, x2, y2, a1, b1, a2, b2, c1, d1, c2, d2, red, blue, green, ic, jc, kc, xi1, xf1, xi2, xf2, xi3, xf3, l1i, l1f, i
        #### Set initial point for rectangles ####
        if self.drawCanvas.underMouse() and QtCore.Qt.LeftButton: # mouse must be over the camera frame; left mouse click to draw
            if red:
                x1, y1 = event.pos().x()-10, event.pos().y()-70
            if green:
                a1, b1 = event.pos().x()-10, event.pos().y()-70
            if blue:
                c1, d1 = event.pos().x()-10, event.pos().y()-70
        #### Update manual calculation for RHEED oscillations on newer data ####
        if self.plot1.underMouse():
            if ic:
                xi1 = self.x1
            if not ic:
                xf1 = self.x1
                dt1 = round(((xf1 - xi1) / float(self.numpeaksLive.value())), 3)
                df1 = round((1/dt1), 3)
                self.rheed1cal = str(str(dt1)+' s or '+str(df1)+' Hz')
            ic = not ic 
        if self.plot2.underMouse():
            if jc:
                xi2 = self.x2
            if not jc:
                xf2 = self.x2
                dt2 = round(((xf2 - xi2)/float(self.numpeaksNewer.value())), 3)
                df2 = round((1/dt2), 3)
                self.rheed2cal = str(str(dt2)+' s or '+str(df2)+' Hz')
            jc = not jc                
        if self.plot3.underMouse():
            if kc:
                xi3 = self.x3
            if not kc:
                xf3 = self.x3
                dt3 = round(((xf3 - xi3)/float(self.numpeaksOlder.value())), 3)
                df3 = round((1/dt3), 3)
                self.rheed3cal = str(str(dt3)+' s or '+str(df3)+' Hz')
            kc = not kc 
Example 49
Project: FRHEED   Author: ecyoung3   File: FRHEED 2.0.2 for webcams.py    GNU General Public License v3.0 5 votes vote down vote up
def mouseReleaseEvent(self, event: QtGui.QMouseEvent):
        global x1, y1, x2, y2, a1, b1, a2, b2, c1, d1, c2, d2, red, blue, green
        if self.drawCanvas.underMouse() and event.button == QtCore.Qt.LeftButton:
            if red:
                x2, y2 = event.pos().x()-10, event.pos().y()-70
            if green:
                a2, b2 = event.pos().x()-10, event.pos().y()-70
            if blue:
                c2, d2 = event.pos().x()-10, event.pos().y()-70
                
    #### Change which rectangle color you're editing #### 
Example 50
Project: FRHEED   Author: ecyoung3   File: FRHEED 2.0.0 backup.py    GNU General Public License v3.0 5 votes vote down vote up
def mousePressEvent(self, event: QtGui.QMouseEvent):
        global x1, y1, x2, y2, a1, b1, a2, b2, c1, d1, c2, d2, red, blue, yellow
        if self.drawCanvas.underMouse():
            if red:
                x1, y1 = event.pos().x()-10, event.pos().y()-70
            if green:
                a1, b1 = event.pos().x()-10, event.pos().y()-70
            if blue:
                c1, d1 = event.pos().x()-10, event.pos().y()-70
                
    #### Record position of mouse when you release the button #### 
Example 51
Project: FRHEED   Author: ecyoung3   File: FRHEED 2.0.0 backup.py    GNU General Public License v3.0 5 votes vote down vote up
def mouseReleaseEvent(self, event: QtGui.QMouseEvent):
        global x1, y1, x2, y2, a1, b1, a2, b2, c1, d1, c2, d2, red, blue, green
        if self.drawCanvas.underMouse():
            if red:
                x2, y2 = event.pos().x()-10, event.pos().y()-70
            if green:
                a2, b2 = event.pos().x()-10, event.pos().y()-70
            if blue:
                c2, d2 = event.pos().x()-10, event.pos().y()-70
                
    #### Change which rectangle color you're editing #### 
Example 52
Project: FRHEED   Author: ecyoung3   File: FRHEED 2.0.2 backup.py    GNU General Public License v3.0 5 votes vote down vote up
def mousePressEvent(self, event: QtGui.QMouseEvent):
        global x1, y1, x2, y2, a1, b1, a2, b2, c1, d1, c2, d2, red, blue, yellow, ic, jc, kc, xi1, xf1, xi2, xf2, xi3, xf3, l1i, l1f
        if self.drawCanvas.underMouse():
            if red:
                x1, y1 = event.pos().x()-10, event.pos().y()-70
            if green:
                a1, b1 = event.pos().x()-10, event.pos().y()-70
            if blue:
                c1, d1 = event.pos().x()-10, event.pos().y()-70
        #### Update manual calculation for RHEED oscillations on newer data ####
        if self.plot1.underMouse():
            if ic:
                xi1 = self.x1
            if not ic:
                xf1 = self.x1
                dt1 = round(((xf1 - xi1) / float(self.numpeaksLive.value())), 3)
                df1 = round((1/dt1), 3)
                self.rheed1cal = str(str(dt1)+' s or '+str(df1)+' Hz')
            ic = not ic 
        if self.plot2.underMouse():
            if jc:
                xi2 = self.x2
            if not jc:
                xf2 = self.x2
                dt2 = round(((xf2 - xi2)/float(self.numpeaksNewer.value())), 3)
                df2 = round((1/dt2), 3)
                self.rheed2cal = str(str(dt2)+' s or '+str(df2)+' Hz')
            jc = not jc                
        if self.plot3.underMouse():
            if kc:
                xi3 = self.x3
            if not kc:
                xf3 = self.x3
                dt3 = round(((xf3 - xi3)/float(self.numpeaksOlder.value())), 3)
                df3 = round((1/dt3), 3)
                self.rheed3cal = str(str(dt3)+' s or '+str(df3)+' Hz')
            kc = not kc

    #### Record position of mouse when you release the button #### 
Example 53
Project: FRHEED   Author: ecyoung3   File: FRHEED_2.0.0.py    GNU General Public License v3.0 5 votes vote down vote up
def mousePressEvent(self, event: QtGui.QMouseEvent):
        global x1, y1, x2, y2, a1, b1, a2, b2, c1, d1, c2, d2, red, blue, yellow
        if self.drawCanvas.underMouse():
            if red:
                x1, y1 = event.pos().x()-10, event.pos().y()-70
            if green:
                a1, b1 = event.pos().x()-10, event.pos().y()-70
            if blue:
                c1, d1 = event.pos().x()-10, event.pos().y()-70
                
    #### Record position of mouse when you release the button #### 
Example 54
Project: FRHEED   Author: ecyoung3   File: FRHEED_2.0.0.py    GNU General Public License v3.0 5 votes vote down vote up
def mouseReleaseEvent(self, event: QtGui.QMouseEvent):
        global x1, y1, x2, y2, a1, b1, a2, b2, c1, d1, c2, d2, red, blue, green
        if self.drawCanvas.underMouse():
            if red:
                x2, y2 = event.pos().x()-10, event.pos().y()-70
            if green:
                a2, b2 = event.pos().x()-10, event.pos().y()-70
            if blue:
                c2, d2 = event.pos().x()-10, event.pos().y()-70
                
    #### Change which rectangle color you're editing #### 
Example 55
Project: FRHEED   Author: ecyoung3   File: FRHEED 2.0.1.py    GNU General Public License v3.0 5 votes vote down vote up
def mousePressEvent(self, event: QtGui.QMouseEvent):
        global x1, y1, x2, y2, a1, b1, a2, b2, c1, d1, c2, d2, red, blue, yellow, ic, jc, kc, xi1, xf1, xi2, xf2, xi3, xf3, l1i, l1f
        if self.drawCanvas.underMouse():
            if red:
                x1, y1 = event.pos().x()-10, event.pos().y()-70
            if green:
                a1, b1 = event.pos().x()-10, event.pos().y()-70
            if blue:
                c1, d1 = event.pos().x()-10, event.pos().y()-70
        #### Update manual calculation for RHEED oscillations on newer data ####
        if self.plot1.underMouse():
            if ic:
                xi1 = self.x1
            if not ic:
                xf1 = self.x1
                dt1 = round(((xf1 - xi1) / float(self.numpeaksLive.value())), 3)
                df1 = round((1/dt1), 3)
                self.rheed1cal = str(str(dt1)+' s or '+str(df1)+' Hz')
            ic = not ic 
        if self.plot2.underMouse():
            if jc:
                xi2 = self.x2
            if not jc:
                xf2 = self.x2
                dt2 = round(((xf2 - xi2)/float(self.numpeaksNewer.value())), 3)
                df2 = round((1/dt2), 3)
                self.rheed2cal = str(str(dt2)+' s or '+str(df2)+' Hz')
            jc = not jc                
        if self.plot3.underMouse():
            if kc:
                xi3 = self.x3
            if not kc:
                xf3 = self.x3
                dt3 = round(((xf3 - xi3)/float(self.numpeaksOlder.value())), 3)
                df3 = round((1/dt3), 3)
                self.rheed3cal = str(str(dt3)+' s or '+str(df3)+' Hz')
            kc = not kc

    #### Record position of mouse when you release the button #### 
Example 56
Project: FRHEED   Author: ecyoung3   File: FRHEED 2.0.1.py    GNU General Public License v3.0 5 votes vote down vote up
def mouseReleaseEvent(self, event: QtGui.QMouseEvent):
        global x1, y1, x2, y2, a1, b1, a2, b2, c1, d1, c2, d2, red, blue, green
        if self.drawCanvas.underMouse():
            if red:
                x2, y2 = event.pos().x()-10, event.pos().y()-70
            if green:
                a2, b2 = event.pos().x()-10, event.pos().y()-70
            if blue:
                c2, d2 = event.pos().x()-10, event.pos().y()-70
                
    #### Change which rectangle color you're editing #### 
Example 57
Project: FRHEED   Author: ecyoung3   File: FRHEED_2.0.0 laptop.py    GNU General Public License v3.0 5 votes vote down vote up
def mouseReleaseEvent(self, event: QtGui.QMouseEvent):
        global x1, y1, x2, y2, a1, b1, a2, b2, c1, d1, c2, d2, red, blue, green
        if self.drawCanvas.underMouse():
            if red:
                x2, y2 = event.pos().x()-10, event.pos().y()-70
            if green:
                a2, b2 = event.pos().x()-10, event.pos().y()-70
            if blue:
                c2, d2 = event.pos().x()-10, event.pos().y()-70
                
    #### Change which rectangle color you're editing #### 
Example 58
Project: FRHEED   Author: ecyoung3   File: FRHEED 2.0.0.py    GNU General Public License v3.0 5 votes vote down vote up
def mousePressEvent(self, event: QtGui.QMouseEvent):
        global x1, y1, x2, y2, a1, b1, a2, b2, c1, d1, c2, d2, red, blue, yellow
        if self.drawCanvas.underMouse():
            if red:
                x1, y1 = event.pos().x()-10, event.pos().y()-70
            if green:
                a1, b1 = event.pos().x()-10, event.pos().y()-70
            if blue:
                c1, d1 = event.pos().x()-10, event.pos().y()-70
                
    #### Record position of mouse when you release the button #### 
Example 59
Project: FRHEED   Author: ecyoung3   File: FRHEED 2.0.0.py    GNU General Public License v3.0 5 votes vote down vote up
def mouseReleaseEvent(self, event: QtGui.QMouseEvent):
        global x1, y1, x2, y2, a1, b1, a2, b2, c1, d1, c2, d2, red, blue, green
        if self.drawCanvas.underMouse():
            if red:
                x2, y2 = event.pos().x()-10, event.pos().y()-70
            if green:
                a2, b2 = event.pos().x()-10, event.pos().y()-70
            if blue:
                c2, d2 = event.pos().x()-10, event.pos().y()-70
                
    #### Change which rectangle color you're editing #### 
Example 60
Project: FRHEED   Author: ecyoung3   File: FRHEED 2.0.0 mouse tracking.py    GNU General Public License v3.0 5 votes vote down vote up
def mousePressEvent(self, event: QtGui.QMouseEvent):
        global x1, y1, x2, y2, a1, b1, a2, b2, c1, d1, c2, d2, red, blue, yellow
        if self.drawCanvas.underMouse():
            if red:
                x1, y1 = event.pos().x()-10, event.pos().y()-70
            if green:
                a1, b1 = event.pos().x()-10, event.pos().y()-70
            if blue:
                c1, d1 = event.pos().x()-10, event.pos().y()-70
                
    #### Record position of mouse when you release the button #### 
Example 61
Project: FRHEED   Author: ecyoung3   File: FRHEED 2.0.2.py    GNU General Public License v3.0 5 votes vote down vote up
def mousePressEvent(self, event: QtGui.QMouseEvent):
        global x1, y1, x2, y2, a1, b1, a2, b2, c1, d1, c2, d2, red, blue, green, ic, jc, kc, xi1, xf1, xi2, xf2, xi3, xf3, l1i, l1f
        if self.drawCanvas.underMouse():
            if red:
                x1, y1 = event.pos().x()-10, event.pos().y()-70
            if green:
                a1, b1 = event.pos().x()-10, event.pos().y()-70
            if blue:
                c1, d1 = event.pos().x()-10, event.pos().y()-70
        #### Update manual calculation for RHEED oscillations on newer data ####
        if self.plot1.underMouse():
            if ic:
                xi1 = self.x1
            if not ic:
                xf1 = self.x1
                dt1 = round(((xf1 - xi1) / float(self.numpeaksLive.value())), 3)
                df1 = round((1/dt1), 3)
                self.rheed1cal = str(str(dt1)+' s or '+str(df1)+' Hz')
            ic = not ic 
        if self.plot2.underMouse():
            if jc:
                xi2 = self.x2
            if not jc:
                xf2 = self.x2
                dt2 = round(((xf2 - xi2)/float(self.numpeaksNewer.value())), 3)
                df2 = round((1/dt2), 3)
                self.rheed2cal = str(str(dt2)+' s or '+str(df2)+' Hz')
            jc = not jc                
        if self.plot3.underMouse():
            if kc:
                xi3 = self.x3
            if not kc:
                xf3 = self.x3
                dt3 = round(((xf3 - xi3)/float(self.numpeaksOlder.value())), 3)
                df3 = round((1/dt3), 3)
                self.rheed3cal = str(str(dt3)+' s or '+str(df3)+' Hz')
            kc = not kc

    #### Record position of mouse when you release the button #### 
Example 62
Project: FRHEED   Author: ecyoung3   File: FRHEED 2.0.2.py    GNU General Public License v3.0 5 votes vote down vote up
def mouseReleaseEvent(self, event: QtGui.QMouseEvent):
        global x1, y1, x2, y2, a1, b1, a2, b2, c1, d1, c2, d2, red, blue, green
        if self.drawCanvas.underMouse():
            if red:
                x2, y2 = event.pos().x()-10, event.pos().y()-70
            if green:
                a2, b2 = event.pos().x()-10, event.pos().y()-70
            if blue:
                c2, d2 = event.pos().x()-10, event.pos().y()-70
                
    #### Change which rectangle color you're editing #### 
Example 63
Project: nanovna-saver   Author: mihtjel   File: Chart.py    GNU General Public License v3.0 5 votes vote down vote up
def mouseReleaseEvent(self, a0: QtGui.QMouseEvent) -> None:
        self.draggedMarker = None
        if self.draggedBox:
            self.zoomTo(self.draggedBoxStart[0], self.draggedBoxStart[1], a0.x(), a0.y())
            self.draggedBox = False
            self.draggedBoxCurrent = (-1, -1)
            self.draggedBoxStart = (0, 0)
            self.update() 
Example 64
Project: nanovna-saver   Author: mihtjel   File: Chart.py    GNU General Public License v3.0 5 votes vote down vote up
def mouseMoveEvent(self, a0: QtGui.QMouseEvent) -> None:
        if a0.buttons() == QtCore.Qt.RightButton:
            a0.ignore()
            return
        if a0.buttons() == QtCore.Qt.MiddleButton:
            # Drag the display
            a0.accept()
            if self.moveStartX != -1 and self.moveStartY != -1:
                dx = self.moveStartX - a0.x()
                dy = self.moveStartY - a0.y()
                self.zoomTo(self.leftMargin + dx, self.topMargin + dy,
                            self.leftMargin + self.chartWidth + dx, self.topMargin + self.chartHeight + dy)

            self.moveStartX = a0.x()
            self.moveStartY = a0.y()
            return
        if a0.modifiers() == QtCore.Qt.ControlModifier:
            # Dragging a box
            if not self.draggedBox:
                self.draggedBoxStart = (a0.x(), a0.y())
            self.draggedBoxCurrent = (a0.x(), a0.y())
            self.update()
            a0.accept()
            return
        x = a0.x()
        f = self.frequencyAtPosition(x)
        if x == -1:
            a0.ignore()
            return
        else:
            a0.accept()
            m = self.getActiveMarker()
            if m is not None:
                m.setFrequency(str(f))
                m.frequencyInput.setText(str(f))
        return 
Example 65
Project: nanovna-saver   Author: mihtjel   File: Chart.py    GNU General Public License v3.0 5 votes vote down vote up
def mouseMoveEvent(self, a0: QtGui.QMouseEvent) -> None:
        if a0.buttons() == QtCore.Qt.RightButton:
            a0.ignore()
            return
        x = a0.x()
        y = a0.y()
        absx = x - (self.width() - self.chartWidth) / 2
        absy = y - (self.height() - self.chartHeight) / 2
        if absx < 0 or absx > self.chartWidth or absy < 0 or absy > self.chartHeight \
                or len(self.data) == len(self.reference) == 0:
            a0.ignore()
            return
        a0.accept()

        if len(self.data) > 0:
            target = self.data
        else:
            target = self.reference
        positions = []
        for d in target:
            thisx = self.width() / 2 + d.re * self.chartWidth / 2
            thisy = self.height() / 2 + d.im * -1 * self.chartHeight / 2
            positions.append(math.sqrt((x - thisx)**2 + (y - thisy)**2))

        minimum_position = positions.index(min(positions))
        m = self.getActiveMarker()
        if m is not None:
            m.setFrequency(str(round(target[minimum_position].freq)))
            m.frequencyInput.setText(str(round(target[minimum_position].freq)))
        return 
Example 66
Project: nanovna-saver   Author: mihtjel   File: Chart.py    GNU General Public License v3.0 5 votes vote down vote up
def mouseMoveEvent(self, a0: QtGui.QMouseEvent) -> None:
        if a0.buttons() == QtCore.Qt.RightButton:
            a0.ignore()
            return
        x = a0.x()
        y = a0.y()
        absx = x - (self.width() - self.chartWidth) / 2
        absy = y - (self.height() - self.chartHeight) / 2
        if absx < 0 or absx > self.chartWidth or absy < 0 or absy > self.chartHeight \
                or len(self.data) == len(self.reference) == 0:
            a0.ignore()
            return
        a0.accept()

        if len(self.data) > 0:
            target = self.data
        else:
            target = self.reference
        positions = []
        for d in target:
            thisx = self.width() / 2 + d.re * self.chartWidth / 2
            thisy = self.height() / 2 + d.im * -1 * self.chartHeight / 2
            positions.append(math.sqrt((x - thisx)**2 + (y - thisy)**2))

        minimum_position = positions.index(min(positions))
        m = self.getActiveMarker()
        if m is not None:
            m.setFrequency(str(round(target[minimum_position].freq)))
            m.frequencyInput.setText(str(round(target[minimum_position].freq)))
        return 
Example 67
Project: pypeds   Author: my-HenryS   File: panel.py    GNU General Public License v3.0 5 votes vote down vote up
def mousePressEvent(self, event: QtGui.QMouseEvent):
        self.move = True
        self.last_x, self.last_y = event.pos().x(), event.pos().y()
        print(self.translate(self.last_x, self.last_y)) 
Example 68
Project: pypeds   Author: my-HenryS   File: panel.py    GNU General Public License v3.0 5 votes vote down vote up
def mouseReleaseEvent(self, event: QtGui.QMouseEvent):
        self.move = False 
Example 69
Project: pypeds   Author: my-HenryS   File: panel.py    GNU General Public License v3.0 5 votes vote down vote up
def mouseMoveEvent(self, event: QtGui.QMouseEvent):
        if not self.move:
            return
        x, y = event.pos().x(), event.pos().y()
        self.offset_x += - (x - self.last_x) / self.zoom
        self.offset_y += - (y - self.last_y) / self.zoom
        self.last_x, self.last_y = event.pos().x(), event.pos().y() 
Example 70
Project: spyrit   Author: pvaret   File: SplittableTextView.py    GNU General Public License v2.0 5 votes vote down vote up
def remapMouseEvent( self, e ):

    if self.atbottom or not self.split_scrollback:
      return e

    if e.y() <= self.splitY():
      return e

    height  = self.viewport().height()

    y = e.y() + self.document().size().height() - height - self.scrollbar.value()

    e = QMouseEvent( e.type(), QPoint( e.x(), y ), e.globalPos(),
                           e.button(), e.buttons(), e.modifiers() )
    return e 
Example 71
Project: schmereo   Author: cmbruns   File: image_widget.py    GNU General Public License v2.0 4 votes vote down vote up
def mouseMoveEvent(self, event: QtGui.QMouseEvent):
        if self.drag_mode != DragMode.NONE and not event.buttons() & Qt.LeftButton:
            return
        wp = WindowPos.from_QPoint(event.pos())
        if self.drag_mode != DragMode.NONE and self.previous_mouse is None:
            self.previous_mouse = wp
            return
        cp = CanvasPos.from_WindowPos(wp, self.camera, self.size())
        if self.drag_mode != DragMode.NONE:
            dPosC = cp - CanvasPos.from_WindowPos(
                self.previous_mouse, self.camera, self.size()
            )
            self.previous_mouse = wp
            # TODO: marker drage takes top priority
            # TODO: clip box drag takes second priority
            if self.drag_mode == DragMode.CLIP_BOX:
                self.clip_box.adjust(self.clip_box_edge, dPosC)
                self.clip_box.notify()
            elif self.drag_mode == DragMode.PAN:
                self.camera.center -= dPosC
                self.camera.notify()  # update UI now
        else:  # just hovering, not dragging
            self.clip_box_edge = self.clip_box.check_hover(
                cp, tolerance=20.0 / (self.size().width() * self.camera.zoom)
            )
            if self.clip_box_edge == Edge.NONE:
                is_hovered = False
                self.setCursor(self.hover_cursor)
                self.latent_drag_mode = DragMode.PAN
            else:
                is_hovered = True
                self.latent_drag_mode = DragMode.CLIP_BOX
                if self.clip_box_edge in (Edge.TOP, Edge.BOTTOM):
                    self.setCursor(Qt.SizeVerCursor)
                elif self.clip_box_edge in (Edge.LEFT, Edge.RIGHT):
                    self.setCursor(Qt.SizeHorCursor)
                elif self.clip_box_edge in (Edge.TOP_LEFT, Edge.BOTTOM_RIGHT):
                    self.setCursor(Qt.SizeFDiagCursor)
                elif self.clip_box_edge in (Edge.TOP_RIGHT, Edge.BOTTOM_LEFT):
                    self.setCursor(Qt.SizeBDiagCursor)
            if self.clip_box_is_hovered != is_hovered:
                self.clip_box_is_hovered = is_hovered
                self.update()
            #
            ip = self.image_from_window_qpoint(event.pos())
            self.messageSent.emit(f"Pixel: {ip.x: 0.1f}, {ip.y: 0.1f}", 3000) 
Example 72
Project: FRHEED   Author: ecyoung3   File: FRHEED 2.0.3 converted for VG.py    GNU General Public License v3.0 4 votes vote down vote up
def mouseReleaseEvent(self, event: QtGui.QMouseEvent):
        global x1, y1, x2, y2, a1, b1, a2, b2, c1, d1, c2, d2, red, blue, green
        x, y = (event.pos().x() - 10), (event.pos().y() - 70)
        if event.button() == 1:
            if self.drawCanvas.underMouse() and 0 < x < self.scaled_w and 0 < y < self.scaled_h and self.drawingshapes and not self.editingshapes:
                if red:
                    x2, y2 = x, y
                if green:
                    a2, b2 = x, y
                if blue:
                    c2, d2 = x, y
        if event.button() == 2:
            if self.drawCanvas.underMouse() and 0 < x < self.scaled_w and 0 < y < self.scaled_h and not self.drawingshapes and self.editingshapes:
                if red:
                    if self.grow == 'left' and not (self.x1o - (self.startx - x)) >= self.x2o:
                        x1 = self.x1o - (self.startx - x)
                    if self.grow == 'right' and not (self.x2o + (x - self.startx)) <= self.x1o:
                        x2 = self.x2o + (x - self.startx)
                    if self.grow == 'up' and not (self.y1o - (self.starty - y)) >= self.y2o:
                        y1 = self.y1o - (self.starty - y)
                    if self.grow == 'down' and not (self.y2o + (y - self.starty)) <= self.y1o:
                        y2 = self.y2o + (y - self.starty)
                if green:
                    if self.grow == 'left' and not (self.a1o - (self.startx - x)) >= self.a2o:
                        a1 = self.a1o - (self.startx - x)
                    if self.grow == 'right' and not (self.a2o + (x - self.startx)) <= self.a1o:
                        a2 = self.a2o + (x - self.startx)
                    if self.grow == 'up' and not (self.b1o - (self.starty - y)) >= self.b2o:
                        b1 = self.b1o - (self.starty - y)
                    if self.grow == 'down' and not (self.b2o + (y - self.starty)) <= self.b1o:
                        b2 = self.b2o + (y - self.starty)
                if blue:
                    if self.grow == 'left' and not (self.c1o - (self.startx - x)) >= self.c2o:
                        c1 = self.c1o - (self.startx - x)
                    if self.grow == 'right' and not (self.c2o + (x - self.startx)) <= self.c1o:
                        c2 = self.c2o + (x - self.startx)
                    if self.grow == 'up' and not (self.d1o - (self.starty - y)) >= self.d2o:
                        d1 = self.d1o - (self.starty - y)
                    if self.grow == 'down' and not (self.d2o + (y - self.starty)) <= self.d1o:
                        d2 = self.d2o + (y - self.starty)
        self.grow = ''                
        self.drawingshapes = False
        self.editingshapes = False
        self.translation = False
        
    #### Change which rectangle color you're editing #### 
Example 73
Project: FRHEED   Author: ecyoung3   File: FRHEED_2_webcams.py    GNU General Public License v3.0 4 votes vote down vote up
def mouseReleaseEvent(self, event: QtGui.QMouseEvent):
        global x1, y1, x2, y2, a1, b1, a2, b2, c1, d1, c2, d2, red, blue, green
        x, y = (event.pos().x() - 10), (event.pos().y() - 70)
        if event.button() == 1:
            if self.drawCanvas.underMouse() and 0 < x < self.scaled_w and 0 < y < self.scaled_h and self.drawingshapes and not self.editingshapes:
                if red:
                    x2, y2 = x, y
                if green:
                    a2, b2 = x, y
                if blue:
                    c2, d2 = x, y
        if event.button() == 2:
            if self.drawCanvas.underMouse() and 0 < x < self.scaled_w and 0 < y < self.scaled_h and not self.drawingshapes and self.editingshapes:
                if red:
                    if self.grow == 'left' and not (self.x1o - (self.startx - x)) >= self.x2o:
                        x1 = self.x1o - (self.startx - x)
                    if self.grow == 'right' and not (self.x2o + (x - self.startx)) <= self.x1o:
                        x2 = self.x2o + (x - self.startx)
                    if self.grow == 'up' and not (self.y1o - (self.starty - y)) >= self.y2o:
                        y1 = self.y1o - (self.starty - y)
                    if self.grow == 'down' and not (self.y2o + (y - self.starty)) <= self.y1o:
                        y2 = self.y2o + (y - self.starty)
                if green:
                    if self.grow == 'left' and not (self.a1o - (self.startx - x)) >= self.a2o:
                        a1 = self.a1o - (self.startx - x)
                    if self.grow == 'right' and not (self.a2o + (x - self.startx)) <= self.a1o:
                        a2 = self.a2o + (x - self.startx)
                    if self.grow == 'up' and not (self.b1o - (self.starty - y)) >= self.b2o:
                        b1 = self.b1o - (self.starty - y)
                    if self.grow == 'down' and not (self.b2o + (y - self.starty)) <= self.b1o:
                        b2 = self.b2o + (y - self.starty)
                if blue:
                    if self.grow == 'left' and not (self.c1o - (self.startx - x)) >= self.c2o:
                        c1 = self.c1o - (self.startx - x)
                    if self.grow == 'right' and not (self.c2o + (x - self.startx)) <= self.c1o:
                        c2 = self.c2o + (x - self.startx)
                    if self.grow == 'up' and not (self.d1o - (self.starty - y)) >= self.d2o:
                        d1 = self.d1o - (self.starty - y)
                    if self.grow == 'down' and not (self.d2o + (y - self.starty)) <= self.d1o:
                        d2 = self.d2o + (y - self.starty)
        self.grow = ''                
        self.drawingshapes = False
        self.editingshapes = False
        self.translation = False
        
    #### Change which rectangle color you're editing ####