def mousePressEvent(self, ev: QMouseEvent): if ev.button() == Qt.LeftButton: self.d.drag_state = DragState.floating_widget self.d.floating_widget.start_dragging( ev.pos(), self.d.floating_widget.size(), self) return super().mousePressEvent(ev)
def __cloneMouseEvent(self, e: QMouseEvent): event_type = e.type() local_pos = e.localPos() button = e.button() buttons = e.buttons() modifiers = e.modifiers() clone = QMouseEvent(event_type, local_pos, button, buttons, modifiers) clone.ignore() return clone
def mouseReleaseEvent(self, ev: QtGui.QMouseEvent) -> None: if ev.button() == QtCore.Qt.LeftButton and self.current and self.tracingActive: if len(self.current.points) > 1: self.mouseDoubleClickEvent(QtCore.QEvent(QtCore.QEvent.MouseButtonDblClick)) self.tracingActive = False if ev.button() == QtCore.Qt.RightButton: menu = self.menus[len(self.selectedShapesCopy) > 0] self.restoreCursor() if ( not menu.exec_(self.mapToGlobal(ev.pos())) and self.selectedShapesCopy ): # Cancel the move by deleting the shadow copy. self.selectedShapesCopy = [] self.repaint() elif ev.button() == QtCore.Qt.LeftButton and self.selectedShapes: self.overrideCursor(CURSOR_GRAB) if ( self.editing() and int(ev.modifiers()) == QtCore.Qt.ShiftModifier ): # Add point to line if: left-click + SHIFT on a line segment self.addPointToEdge() elif ev.button() == QtCore.Qt.LeftButton and self.selectedVertex(): if ( self.editing() and int(ev.modifiers()) == QtCore.Qt.ShiftModifier ): # Delete point if: left-click + SHIFT on a point self.removeSelectedPoint() if self.movingShape and self.hShape: index = self.shapes.index(self.hShape) if ( self.shapesBackups[-1][index].points != self.shapes[index].points ): self.storeShapes() self.shapeMoved.emit() self.movingShape = False
def mousePressEvent(self, event: QMouseEvent): """ mousePressEvent Parameters ---------- event : QMouseEvent """ super().mousePressEvent(event) if event.button() == Qt.LeftButton: self._click_pos = self.mapToScene(event.pos())
def mouseReleaseEvent(self, event: QMouseEvent): ''' Mousereleaseevent Parameters ---------- event : QMouseEvent ''' super().mouseReleaseEvent(event) if event.button() != Qt.LeftButton: return self.clicked.emit()
def mousePressEvent(self, ev: QMouseEvent): ''' Stores mouse position to detect dragging Parameters ---------- ev : QMouseEvent ''' if ev.button() == Qt.LeftButton: ev.accept() self.d.drag_start_mouse_pos = ev.pos() return super().mousePressEvent(ev)
def mouseReleaseEvent(self, ev: QMouseEvent): ''' Stores mouse position to detect dragging Parameters ---------- ev : QMouseEvent ''' if ev.button() != Qt.LeftButton: return super().mouseReleaseEvent(ev) logger.debug('DockAreaTabBar.mouseReleaseEvent') ev.accept() self.d.floating_widget = None self.d.drag_start_mouse_pos = QPoint()
def mousePressEvent(self, ev: QMouseEvent): ''' Mousepressevent Parameters ---------- ev : QMouseEvent ''' if ev.button() == Qt.LeftButton: ev.accept() self.d.drag_start_mouse_position = ev.pos() self.d.drag_state = DragState.mouse_pressed self.clicked.emit() return super().mousePressEvent(ev)
def from_mouse_event(qe: QtGui.QMouseEvent) -> 'Optional[EventID]': if qe.type() == QtCore.QEvent.MouseButtonRelease: if qe.button() == Qt.LeftButton: return EventID.Mouse_B1 elif qe.button() == Qt.RightButton: return EventID.Mouse_B2 elif qe.button() == Qt.MidButton: return EventID.Mouse_B3 elif qe.type() == QtCore.QEvent.MouseButtonPress: if qe.button() == Qt.LeftButton: return EventID.Mouse_B1_DragStart elif qe.button() == Qt.RightButton: return EventID.Mouse_B2_DragStart elif qe.button() == Qt.MidButton: return EventID.Mouse_B3_DragStart return None
def mousePressEvent(self, event: QtGui.QMouseEvent): if event.button() == QtCore.Qt.LeftButton: self.dragStartPos = event.pos()
def mousePressEvent(self, event: QtGui.QMouseEvent): super().mousePressEvent(event) if event.button() == Qt.LeftButton: self.clicked.emit()
def mouseMoveEvent(self, event: QMouseEvent) -> None: if event.button() == Qt.NoButton: self.setCursor(Qt.ClosedHandCursor) super().mouseMoveEvent(event)
def mousePressEvent(self, event: QMouseEvent): super(ContextMenuTabBar, self).mousePressEvent(event) self._rightclickedtab = self.tabAt(event.pos()) if self._rightclickedtab != -1: if event.button() == Qt.RightButton: self.contextMenu.popup(self.mapToGlobal(event.pos()))
def mousePressEvent(self, event: QMouseEvent): if event.button() == Qt.MouseButton.LeftButton: self.image_next() elif event.button() == Qt.MouseButton.RightButton: self.image_previous()
def mousePressEvent(self, event: QtGui.QMouseEvent): """ The following only has effect if the main track is selected in the track table view on the right Annotation mode: **LeftMouseButton** places a new fiducial. By default it is the first fiducial as set in the annotationConfig, unless before that a keyboard button was pressed corresponding to another fiducial or "sticky fiducial" mode is on. **RightMouseButton** removes the nearest fiducial (default), unless "sticky fiducial" mode is on. Keyboard has no effect Partition mode: **CTRL + LeftMouseButton** creates a new partition which takes 2% of the whole track duration or less to avoid overlapping partiotions; **CTRL + RightMouseButton** removes partition under the click **SHIFT + LeftMouseButton** to drag partition borders or move the partition. Repositioning is possible within the limits of neighboring partition. Moving the partition fully inside another one or reducing its size to 1 sample deletes the partition. #NOTE: creating partition of desired size directly by click and drag might not be that convenient and harder to implement Epoch mode: # NB: when adding\removing mouse click operations also adapt self.mouseReleaseEvent() and self.mouseMoveEvent() """ def which_fiducial_to_add(last_keypress_event_key): from gui.viewer import Viewer # first check if 'sticky' fiducial option is enabled for one of the fiducials sticky_fiducial = [ item.isChecked() for item in Viewer.get().annotation_menu.sticky_fiducial_menu.actions() ] if any(sticky_fiducial): idx = np.argwhere(sticky_fiducial)[0] return AnnotationConfig.get().find_idx_by_name( Viewer.get().annotation_menu.sticky_fiducial_menu.actions( )[idx[0]].text()) # if 'sticky' fiducial option is off, check what key was pressed the last default_fiducial_idx = 0 # default: first fiducial if last_keypress_event_key is not None: qInfo('Last pressed: ' + str(last_keypress_event_key[1])) for fiducial_idx, f in enumerate( AnnotationConfig.get().fiducials): if f.key.lower() == last_keypress_event_key[1].lower(): return fiducial_idx return default_fiducial_idx else: return default_fiducial_idx def which_fiducial_to_delete(click_x): from gui.viewer import Viewer # first check if 'sticky' fiducial option is enabled for one of the fiducials sticky_fiducial = [ item.isChecked() for item in Viewer.get().annotation_menu.sticky_fiducial_menu.actions() ] if any(sticky_fiducial): idx = np.argwhere(sticky_fiducial)[0] return AnnotationConfig.get().find_idx_by_name( Viewer.get().annotation_menu.sticky_fiducial_menu.actions( )[idx[0]].text()) dist = np.inf fiducial_name, fiducial_idx = None, None for f_idx, f in enumerate(AnnotationConfig.get().fiducials): if f.annotation.x.size > 0: closest_idx, _, _ = find_closest(f.annotation.x, np.array([click_x])) dist_new = abs(click_x - f.annotation.x[closest_idx]) if dist_new < dist: dist = dist_new fiducial_name, fiducial_idx = f.name, f_idx if not dist == np.inf: return fiducial_idx try: from gui.viewer import Viewer Viewer.get().selectFrame(self.display_panel.parent( )) # first select the frame where the click was made if Mode.is_epoch_mode(): EpochModeConfig.get().process_mouseclick(event) return vb = self.vbs[self.selected_view()] click_x = vb.mapSceneToView(event.pos()).x() if self.selected_view().track.label is Database.get( ).main_track_label: # TODO: do this check properly and uniformly everywhere if Mode.is_annotation_mode(): if AnnotationConfig.get().is_valid(): if event.button( ) == QtCore.Qt.LeftButton: # Left click to mark fiducial_idx = which_fiducial_to_add( self.last_keypress_event_key) AnnotationConfig.get().fiducials[ fiducial_idx].annotation.signal_annotate.emit( click_x) elif event.button( ) == pg.QtCore.Qt.RightButton: # right click to delete fiducial_idx = which_fiducial_to_delete(click_x) if fiducial_idx is not None: AnnotationConfig.get().fiducials[ fiducial_idx].annotation.signal_delete_annotation.emit( click_x) else: qInfo('No annotation found to be deleted') self.last_keypress_event_key = None # need to press extra key every time to annotate secondary fiducial elif Mode.is_partition_mode(): if event.button() == QtCore.Qt.LeftButton: if event.modifiers() == QtCore.Qt.ControlModifier: self.create_new_partition(event) else: super().mousePressEvent(event) qInfo( 'CTRL+Left: create region; SHIFT+Left: move region' ) # event.accept() elif event.button() == QtCore.Qt.RightButton: if event.modifiers() == QtCore.Qt.ControlModifier: p = Partitions.find_partition_by_point(click_x) if p is not None: p.region_deleted() # event.accept() elif event.modifiers() == QtCore.Qt.ShiftModifier: p = Partitions.find_partition_by_point(click_x) if p is not None: self.partition_context_menu(event) else: qInfo( 'No partition found...CTRL+Right: delete region; SHIFT+Right: region context menu' ) else: super().mousePressEvent(event) qInfo( 'CTRL+Right: delete region; SHIFT+Right: region context menu' ) else: super().mousePressEvent(event) elif Mode.mode == Modes.browse: super().mousePressEvent(event) else: if not self.is_main_view_in_current_panel( ): # click on a panel, without the main track Dialog().warningMessage( 'Selected display panel does not contain the main track ({}).\r\n' .format(Database.get().main_track_label) + 'Try clicking on another display panel') else: # click on a correct panel, but the main track is not selected Dialog().warningMessage( 'Selected signal is not the main one.\r\n' 'Click on the ' '{}' ' track in the control area on the right.'.format( Database.get().main_track_label)) return except Exception as e: Dialog().warningMessage('Mouse click processing failed\r\n' 'What unusual did you do?\r\n' + str(e)) return
def mousePressEvent(self, event: QtGui.QMouseEvent): if event.button() == 2: self.reset() pass
def ConvertMouseEventToShortcut(event: QG.QMouseEvent): key = None shortcut_press_type = SHORTCUT_PRESS_TYPE_PRESS if event.type() == QC.QEvent.MouseButtonPress: for (qt_button, hydrus_button ) in qt_mouse_buttons_to_hydrus_mouse_buttons.items(): if event.buttons() & qt_button: key = hydrus_button break elif event.type() in (QC.QEvent.MouseButtonDblClick, QC.QEvent.MouseButtonRelease): if event.type() == QC.QEvent.MouseButtonRelease: shortcut_press_type = SHORTCUT_PRESS_TYPE_RELEASE elif event.type() == QC.QEvent.MouseButtonDblClick: shortcut_press_type = SHORTCUT_PRESS_TYPE_DOUBLE_CLICK for (qt_button, hydrus_button ) in qt_mouse_buttons_to_hydrus_mouse_buttons.items(): if event.button() == qt_button: key = hydrus_button break elif event.type() == QC.QEvent.Wheel: if event.angleDelta().y() > 0: key = SHORTCUT_MOUSE_SCROLL_UP elif event.angleDelta().y() < 0: key = SHORTCUT_MOUSE_SCROLL_DOWN if key is not None: modifiers = [] if event.modifiers() & QC.Qt.AltModifier: modifiers.append(SHORTCUT_MODIFIER_ALT) if event.modifiers() & QC.Qt.ControlModifier: modifiers.append(SHORTCUT_MODIFIER_CTRL) if event.modifiers() & QC.Qt.ShiftModifier: modifiers.append(SHORTCUT_MODIFIER_SHIFT) if event.modifiers() & QC.Qt.GroupSwitchModifier: modifiers.append(SHORTCUT_MODIFIER_GROUP_SWITCH) if event.modifiers() & QC.Qt.KeypadModifier: modifiers.append(SHORTCUT_MODIFIER_KEYPAD) shortcut = Shortcut(SHORTCUT_TYPE_MOUSE, key, shortcut_press_type, modifiers) if HG.gui_report_mode: HydrusData.ShowText('mouse event caught: ' + repr(shortcut)) return shortcut return None