Exemple #1
0
    def eventFilter(self, watched: QObject, event: QEvent) -> bool:
        if self.ui.widget_with_focus() is not watched:
            return False

        if not event.type() == QEvent.KeyPress:
            return False

        if event.key() in (Qt.Key_Backspace, Qt.Key_Escape):
            self.line_edit.clear()
            self.restore()
            self.widget.info_overlay.display(f'Clearing filter.', 1500, True)
            return True

        # Send alphanumeric keys to LineEdit filter widget
        filter_keys = [Qt.Key_Space, Qt.Key_Underscore, Qt.Key_Minus]

        if event.text().isalnum() or event.key() in filter_keys:
            filter_txt = self.line_edit.text()
            filter_txt += event.text()

            if filter_txt:
                self.widget.info_overlay.display(f'Filtering: {filter_txt}',
                                                 1500, True)
            self.line_edit.setText(filter_txt)

            return True

        return False
Exemple #2
0
 def eventFilter(self, obj: QComboBox, event: QEvent):
     """Event filter that ensure the QComboBox popup as soon as the delegate is created."""
     # src: https://forum.qt.io/topic/51476/qcombobox-delegate-best-way-to-show-the-popup-menu-immediately
     if event.type(
     ) == QEvent.FocusIn and event.reason() != Qt.PopupFocusReason:
         obj.showPopup()
     return super().eventFilter(obj, event)
Exemple #3
0
    def startDrag(self, event: QEvent) -> None:
        item = self.currentItem()
        if item is None:
            event.ignore()
            return
        self.item_being_dragged = self.takeItem(self.row(item)).parent

        hot_spot_point = event.pos()

        item_data = QByteArray()
        data_stream = QDataStream(item_data, QIODevice.WriteOnly)

        data_stream << hot_spot_point  # pixmap << location

        mime_data = QMimeData()
        mime_data.setData(config_controller.component_mime, item_data)

        drag = QDrag(self)
        pixmap = item.parent.pixmap.scaledToWidth(64)
        drag.setHotSpot(QPoint(pixmap.width() / 2, pixmap.height() / 2))
        drag.setPixmap(pixmap)
        drag.setMimeData(mime_data)
        result = drag.start(QtCore.Qt.MoveAction)
        if result:  # == QtCore.Qt.MoveAction:
            pass
Exemple #4
0
    def keyPressEvent(self, q_key_event: QEvent):
        if q_key_event.key() in self.__key_to_id.keys():
            self.__controller.react_on_key_press(
                self.__key_to_id[q_key_event.key()])
            return True

        super().keyPressEvent(q_key_event)
Exemple #5
0
    def closeEvent(self, event: QtCore.QEvent) -> None:
        """ actions to be done before close the app """

        reply = QtWidgets.QMessageBox.Yes
        if self.ask_quit and self.tab_main.lib.prj.has_modified_layers():
            reply = self.do_you_really_want(
                text="quit\nwithout saving your last changes")

        if reply == QtWidgets.QMessageBox.Yes:

            # store current tab
            self.settings.setValue("tabs/icon_size",
                                   int(self.tabs.iconSize().width()))
            self.settings.setValue("toolbars/icon_size",
                                   self.tab_main.toolbars_icon_size())
            self.settings.setValue("main_window/state", self.saveState())
            self.settings.setValue("main_window/geometry", self.saveGeometry())

            self.tab_main.lib.prj.close_layers()

            event.accept()
            super().closeEvent(event)

        else:

            event.ignore()
Exemple #6
0
 def eventFilter(self, obj: QObject, event: QEvent) -> bool:
     if obj is not self.w:
         return False
     if event.type() == QEvent.WindowDeactivate or event.type() == QEvent.WindowActivate or \
             event.type() == QEvent.FocusOut or event.type() == QEvent.FocusIn:
         return False
     return super().eventFilter(obj, event)
Exemple #7
0
    def eventFilter(self, source: QtCore.QObject, event: QtCore.QEvent):
        """
        Grabs mouse events from outside the widget
        """

        # If the user clicks outside of this widget, hide it.
        if event.type() == QtCore.QEvent.MouseButtonPress:
            self.hidePopup()

        # If the user moves the mouse outside of this widget,
        # determine whether we need to do anything about that.
        elif event.type() == QtCore.QEvent.MouseMove:

            # If we are not visible, no need to compute anything
            if self.isVisible() is False:
                pass

            else:
                # Compute distance to mouse cursor.
                d = distanceToRect(event.pos(), self.geometry())

                # Update opacity based on distance
                self._updateDistanceOpacity(d)

        return super().eventFilter(source, event)
Exemple #8
0
 def keyPressEvent(self, event: QtCore.QEvent) -> None:  # pragma: no cover
     if event.key() in [QtCore.Qt.Key_Enter, QtCore.Qt.Key_Return]:
         self._advance()
     elif event.matches(QtGui.QKeySequence.Copy):
         self._copy()
     else:
         super().keyPressEvent(event)
 def eventFilter(self, watched: QtCore.QObject,
                 event: QtCore.QEvent) -> bool:
     if event.type() == QtCore.QEvent.HoverEnter:
         self.setFocus()
     elif event.type() == QtCore.QEvent:
         self.clearFocus()
     return super(PlyViewportWidget, self).eventFilter(watched, event)
    def eventFilter(self, editor, event: QEvent):
        if (isinstance(event, QKeyEvent) and
            (event.key() == Qt.Key_Enter or event.key() == Qt.Key_Return)
                and editor.text() != editor.line_edit.text()):
            # Current text not accepted
            return False

        return super().eventFilter(editor, event)
Exemple #11
0
class QSlotEvent(QEvent):
    EVENT_TYPE = QEvent.Type(QEvent.registerEventType())

    def __init__(self, reference, *args, **kwargs):
        QEvent.__init__(self, QSlotEvent.EVENT_TYPE)
        self.reference = reference
        self.args = args
        self.kwargs = kwargs
 def event(self, event: QEvent):
   if self.enabled():
     et = event.type()
     if et in self._eventDict:
       self._eventDict[et](event)
       if event.isAccepted():
         return True
   return False
    def eventFilter(self, watched: QtCore.QObject,
                    event: QtCore.QEvent) -> bool:
        if event.type() == QtCore.QEvent.HoverEnter:
            self.qBrush.setColor(self.colorHover)
        elif event.type() == QtCore.QEvent.HoverLeave:
            self.qBrush.setColor(self.colorNormal)

        return super(PlyViewportToolButton, self).eventFilter(watched, event)
 def eventFilter(self, watched: QPushButton, event: QEvent):
     if event.type() == QEvent.Enter:
         watched.setIcon(QIcon(self.h_icon_path))
         return True
     elif event.type() == QEvent.Leave:
         watched.setIcon(QIcon(self.l_icon_path))
         return True
     else:
         return False
Exemple #15
0
 def editorEvent(self, event: QEvent, model: QAbstractItemModel, option: QStyleOptionViewItem, index: QModelIndex) -> bool:
     if index.column() == 2:
         if event.type() is QEvent.MouseButtonPress:
             v = bool(model.data(index, Qt.CheckStateRole))
             model.setData(index, not v, Qt.CheckStateRole)
             event.accept()
     else:
         pass
     return super().editorEvent(event, model, option, index)
Exemple #16
0
 def eventFilter(self, obj: QSpinBox, event: QEvent) -> bool:
     if event.type() == QEvent.Wheel and isinstance(obj, QSpinBox):
         if obj.focusPolicy() == Qt.WheelFocus:
             event.accept()
             return False
         else:
             event.ignore()
             return True
     return super().eventFilter(obj, event)
    def eventFilter(self, obj: QObject, event: QEvent):
        if obj != self.view:
            return False

        if event.type() == QEvent.ContextMenu:
            self.popup(event.globalPos())
            return True

        return False
Exemple #18
0
class TestEvent(QEvent):
    TestEventType = QEvent.Type(QEvent.registerEventType())

    def __init__(self, rand=0):
        super(TestEvent, self).__init__(TestEvent.TestEventType)
        self._rand = rand

    def getRand(self):
        return self._rand
Exemple #19
0
 def event(self, event: QtCore.QEvent):
     """
     Tracks when the parent widget changes.
     """
     if event.type() == QtCore.QEvent.ParentAboutToChange:
         if self.parent():
             self.parent().removeEventFilter(self)
         elif event.type() == QtCore.QEvent.ParentChange:
             self.newParent()
     return super().event(event)
 def toolTipEvent(self, e: QtCore.QEvent):
     if not self._completer.popup().isVisible():
         prefix, base, _ = self._textCursorGetText(
             self.cursorForPosition(e.pos()))
         for item in self._command_hints:
             if item['Command'] == prefix + base:
                 QToolTip.showText(e.globalPos(), item['Hint'])
                 break
             else:
                 QToolTip.hideText()
Exemple #21
0
	def dispatchKeyEventFunctions(self, event:QtCore.QEvent, forObject=None,
	                              pressed=True):
		"""no guarantee of order in dispatched functions
		this will NOT be called automatically by this object - call it yourself from client event functions
		since you'll need to redefine them all anyway"""
		connectedFunctions = self.keyFunctionMap.get(event.key(), set())
		if forObject is not None:
			connectedFunctions.update(self.keyFunctionMap.get( (event.key(), id(forObject)), set()))
		for fn in connectedFunctions:
			fn(event, pressed)
Exemple #22
0
class _MethodInvokeEvent(QEvent):

    EVENT_TYPE = QEvent.Type(QEvent.registerEventType())

    def __init__(self, func, args, kwargs):
        # type: (Callable[[Any], Any], Any, Any) -> NoReturn
        super(_MethodInvokeEvent, self).__init__(_MethodInvokeEvent.EVENT_TYPE)
        self.func = func
        self.args = args
        self.kwargs = kwargs
Exemple #23
0
 def eventFilter(self, obj: QtCore.QObject, event: QtCore.QEvent):
     """
     Catches resize and child events from the parent widget.
     """
     if obj == self.parent():
         if event.type() == QtCore.QEvent.Resize:
             self.resize(self.parent().size())
         elif event.type() == QtCore.QEvent.ChildAdded:
             self.raise_()
     return super().eventFilter(obj, event)
Exemple #24
0
    def contextMenuEvent(self, event: QtCore.QEvent) -> None:
        event.accept()
        action_copy_image = QtWidgets.QAction(
            QtGui.QIcon.fromTheme("insert-image"), "Copy To Clipboard", self)
        action_copy_image.setStatusTip(
            "Copy the graphics view to the clipboard.")
        action_copy_image.triggered.connect(self.graphics.copyToClipboard)

        menu = QtWidgets.QMenu(self)
        menu.addAction(action_copy_image)
        menu.popup(event.globalPos())
Exemple #25
0
    def eventFilter(self, obj, event: QEvent):
        if obj is None or event is None:
            return False

        if event.type() == QMouseEvent.MouseButtonDblClick:
            LOGGER.debug('Mouse Dbl Click: %s %s', obj, event)
            self.method_call(*self.args)
            event.accept()
            return True

        return False
Exemple #26
0
    def eventFilter(self, target: QObject, event: QEvent):

        if event.type() == QEvent.KeyPress:
            if target is self.__lineEdit:
                if event.key() in ru_to_us:
                    key = ru_to_us[event.key()]
                    self.__lineEdit.setText(self.__lineEdit.text() + chr(key))
                    return True
                self.__lineEdit.keyPressEvent(event)
                return True
        return super().eventFilter(target, event)
Exemple #27
0
 def update_mode(self, event: QEvent):
     if event.buttons() == Qt.LeftButton:
         if event.type(
         ) != QEvent.Wheel:  # This condition is used only to fix strange bug
             # after a mouse click on the app title bar, try to change brush radius (using Ctrl + mouse wheel)
             # event.buttons() shows, that LeftButton is pressed (but it is not pressed)
             # that leads to draw mode, but we want only change brush radius (in show mode)
             self.mode = Mode.DRAW
     elif event.buttons() == Qt.RightButton:
         self.mode = Mode.ERASE
     else:
         self.mode = Mode.SHOW
Exemple #28
0
    def eventFilter(self, watched: QObject, event: QEvent) -> bool:
        if watched == self.ui.textInput and event.type() == QEvent.KeyPress:
            event: QKeyEvent
            if event.modifiers() == Qt.ControlModifier:
                if event.key() in [
                        Qt.Key_Down, Qt.Key_Up, Qt.Key_PageDown, Qt.Key_PageUp,
                        Qt.Key_Home, Qt.Key_End
                ]:
                    QApplication.sendEvent(self.ui.resultsTree, event)
                    return True

        return super().eventFilter(watched, event)
Exemple #29
0
    def event(self, event: QEvent) -> bool:
        # handle pinch zoom on mac
        if (event.type() == QEvent.Type.NativeGesture and event.gestureType()
                == Qt.NativeGestureType.ZoomNativeGesture):
            self.engine.zoom(
                2.0 * event.value(),
                event.localPos().x() * self._factor,
                event.localPos().y() * self._factor,
            )
            return True

        return super().event(event)
Exemple #30
0
 def closeEvent(self, event: QEvent) -> None:
     """Defines the message box for when the user wants to quit ViolinGUI."""
     title = 'Quit Application'
     mes = "Are you sure you want to quit?"
     reply = QMessageBox.question(self, title, mes,
                                  QMessageBox.Yes | QMessageBox.No,
                                  QMessageBox.No)
     if reply == QMessageBox.Yes:
         self.setEnabled(False)
         self.threadpool.waitForDone()
         event.accept()
     else:
         event.ignore()
Exemple #31
0
    def testFlagAccess(self):
        #QEvent.Type flags usage

        event = QEvent(QEvent.Timer)
        self.assertEqual(event.type(), QEvent.Timer)

        event = QEvent(QEvent.Close)
        self.assertEqual(event.type(), QEvent.Close)

        event = QEvent(QEvent.IconTextChange)
        self.assertEqual(event.type(), QEvent.IconTextChange)
Exemple #32
0
 def __init__(self):
     QEvent.__init__(self, QEvent.Type(999))
Exemple #33
0
from PySide2.QtCore import QEvent, Qt
import PySide

import unittest

TEST_EVENT_TYPE = QEvent.Type(QEvent.registerEventType())

class TestEvent(QEvent):
    TestEventType = QEvent.Type(QEvent.registerEventType())

    def __init__(self, rand=0):
        super(TestEvent, self).__init__(TestEvent.TestEventType)
        self._rand = rand

    def getRand(self):
        return self._rand


class TestEnums(unittest.TestCase):
    def testUserTypesValues(self):
        self.assert_(QEvent.User <= int(TestEvent.TestEventType) <= QEvent.MaxUser)
        self.assert_(QEvent.User <= int(TEST_EVENT_TYPE) <= QEvent.MaxUser)

    def testUserTypesRepr(self):
        self.assertEqual(eval(repr(TestEvent.TestEventType)), TestEvent.TestEventType)
        self.assertEqual(eval(repr(TEST_EVENT_TYPE)), TEST_EVENT_TYPE)

if __name__ == '__main__':
    unittest.main()