def send_click(view, pos, button=Qt.MouseButton.LeftButton, double_click=False): mods = QApplication.keyboardModifiers() if double_click: ev = QMouseEvent(QEvent.Type.MouseButtonDblClick, pos, button, button, mods) QApplication.postEvent(view.viewport(), ev) return ev = QMouseEvent(QEvent.Type.MouseButtonPress, pos, button, button, mods) QApplication.postEvent(view.viewport(), ev) ev = QMouseEvent(QEvent.Type.MouseButtonRelease, pos, button, button, mods) QApplication.postEvent(view.viewport(), ev)
def test_widget_notes_mark_event(qtbot): w = MainWindow() qtbot.addWidget(w) w.info.open_dataset(str(gui_file)) channel_make_group(w) w.channels.button_apply.click() w.channels.new_group(test_name='eog') w.notes.update_notes(annot_psg_path) w.traces.Y_wider() w.traces.Y_wider() w.traces.action['cross_chan_mrk'].setChecked(True) w.traces.go_to_epoch(test_text_str='23:34:45') w.notes.new_eventtype(test_type_str='spindle') w.notes.action['new_event'].setChecked(True) w.notes.add_event('spindle', (24293.01, 24294.65), 'EEG Pz-Oz (scalp)') screenshot(w, 'notes_14_mark_event.png') w.notes.add_event('spindle', (24288.01, 24288.90), 'EEG Fpz-Cz (scalp)') w.notes.add_event('spindle', (24297.5, 24298.00), 'EEG Fpz-Cz (scalp)') screenshot(w, 'notes_20_mark_short_event.png') pos = w.traces.mapFromScene(QPointF(24294, 75)) mouseclick = QMouseEvent(QEvent.MouseButtonPress, pos, Qt.LeftButton, Qt.NoButton, Qt.NoModifier) w.traces.mousePressEvent(mouseclick) screenshot(w, 'notes_15_highlight_event.png') w.notes.delete_eventtype(test_type_str='spindle') w.close()
def mousePressEvent(self, event): if event.button() == Qt.RightButton: # Rewrite the mouse event to a left button event so the cursor is # moved to the location of the pointer. event = QMouseEvent(QEvent.MouseButtonPress, event.pos(), Qt.LeftButton, Qt.LeftButton, Qt.NoModifier) QPlainTextEdit.mousePressEvent(self, event)
def handle_tap_hold(self, action, tp): etype = {'start':QEvent.MouseButtonPress, 'update':QEvent.MouseMove, 'end':QEvent.MouseButtonRelease}[action] ev = QMouseEvent(etype, self.current_position(tp), tp.current_screen_position.toPoint(), Qt.LeftButton, Qt.LeftButton, Qt.NoModifier) QApplication.sendEvent(self.parent(), ev) if action == 'end': ev = QContextMenuEvent(QContextMenuEvent.Other, self.current_position(tp), tp.current_screen_position.toPoint()) # We have to use post event otherwise the popup remains an alien widget and does not receive events QApplication.postEvent(self.parent(), ev)
def handle_tap(self, tp): if self.close_open_menu(): return view = self.parent() mf = view.document.mainFrame() r = mf.hitTestContent(self.current_position(tp)) if r.linkElement().isNull(): if view.document.tap_flips_pages: threshold = view.width() / 3.0 attr = 'previous' if self.current_position(tp).x() <= threshold else 'next' getattr(view, '%s_page'%attr)() else: for etype in (QEvent.MouseButtonPress, QEvent.MouseButtonRelease): ev = QMouseEvent(etype, self.current_position(tp), tp.current_screen_position.toPoint(), Qt.LeftButton, Qt.LeftButton, Qt.NoModifier) QApplication.sendEvent(view, ev)
def send_fake_focus_if_needed(self): if self.needs_fake_focus: # We force Qt to call Focus() on the web view by sending this # event, see RenderWidgetHostViewQt::forwardEvent() and # RenderWidgetHostViewQt::handleMouseEvent() in the qtwebengine # source code to check that this both causes Focus() to be called # and has no other side-effects. This work around is needed because # without it, tabs opened by middle-clicking start out without # keyboard focus and require a click in the web view to get it. # This workaround may not be necessary once # https://bugreports.qt.io/browse/QTBUG-58515 is fixed. QApplication.sendEvent( self.focusProxy(), QMouseEvent(QMouseEvent.MouseButtonPress, QPoint(), QPoint(), QPoint(), Qt.NoButton, Qt.NoButton, Qt.NoModifier, Qt.MouseEventSynthesizedBySystem)) self.needs_fake_focus = False
def mouseMoveEvent(self, event): ''' @param: event QMouseEvent ''' super().mouseMoveEvent(event) if gVar.app.plugins().processMouseMove(const.ON_TabBar, self, event): return if self.count() == 1 and gVar.app.windowCount() == 1: return if not self._dragStartPosition.isNull(): offset = 0 eventY = event.pos().y() if eventY < 0: offset = abs(eventY) elif eventY > self.height(): offset = eventY - self.height() if offset > QApplication.startDragDistance() * 3: global_ = self.mapToGlobal(self._dragStartPosition) w = QApplication.widgetAt(global_) if w: mouse = QMouseEvent(QEvent.MouseButtonRelease, w.mapFromGlobal(global_), Qt.LeftButton, Qt.LeftButton, event.modifiers()) QApplication.sendEvent(w, mouse) drag = QDrag(self) mime = QMimeData() mime.setData(self.MIMETYPE, b'') drag.setMimeData(mime) drag.setPixmap(self.tabPixmap(self.currentIndex())) if drag.exec_() == Qt.IgnoreAction: self._tabWidget.detachTabByIndex(self.currentIndex()) return
def m_event(_event, _pos): e = QMouseEvent(_event, QPoint(_pos), w.mapToGlobal(_pos), Qt.LeftButton, Qt.LeftButton, Qt.NoModifier) QApplication.postEvent(w, e)
def _mouse_event(self, mtype: int, pos: QPoint, btn: int) -> QMouseEvent: """Create mouse event""" return QMouseEvent(mtype, pos, btn, self._app.mouseButtons(), self._app.keyboardModifiers())