|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2015 - 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog for the configuration of a mouse click sequence. |
|
8 """ |
|
9 |
|
10 from PyQt6.QtCore import pyqtSlot, Qt, QEvent |
|
11 from PyQt6.QtWidgets import QDialog, QDialogButtonBox |
|
12 |
|
13 from .Ui_MouseClickDialog import Ui_MouseClickDialog |
|
14 |
|
15 from Utilities import MouseUtilities |
|
16 |
|
17 |
|
18 class MouseClickDialog(QDialog, Ui_MouseClickDialog): |
|
19 """ |
|
20 Class implementing a dialog for the configuration of a mouse click |
|
21 sequence. |
|
22 """ |
|
23 def __init__(self, modifiers, button, parent=None): |
|
24 """ |
|
25 Constructor |
|
26 |
|
27 @param modifiers keyboard modifiers of the handler |
|
28 @type Qt.KeyboardModifiers |
|
29 @param button mouse button of the handler |
|
30 @type Qt.MouseButton |
|
31 @param parent reference to the parent widget |
|
32 @type QWidget |
|
33 """ |
|
34 super().__init__(parent) |
|
35 self.setupUi(self) |
|
36 self.setModal(True) |
|
37 |
|
38 self.clickGroup.installEventFilter(self) |
|
39 self.clearButton.installEventFilter(self) |
|
40 self.clickEdit.installEventFilter(self) |
|
41 |
|
42 self.buttonBox.button( |
|
43 QDialogButtonBox.StandardButton.Ok).installEventFilter(self) |
|
44 self.buttonBox.button( |
|
45 QDialogButtonBox.StandardButton.Cancel).installEventFilter(self) |
|
46 |
|
47 self.__modifiers = modifiers |
|
48 self.__button = button |
|
49 |
|
50 self.__showClickText() |
|
51 |
|
52 msh = self.minimumSizeHint() |
|
53 self.resize(max(self.width(), msh.width()), msh.height()) |
|
54 |
|
55 @pyqtSlot() |
|
56 def on_clearButton_clicked(self): |
|
57 """ |
|
58 Private slot to clear the entered sequence. |
|
59 """ |
|
60 self.__modifiers = Qt.KeyboardModifier.NoModifier |
|
61 self.__button = Qt.MouseButton.NoButton |
|
62 self.__showClickText() |
|
63 |
|
64 def __showClickText(self): |
|
65 """ |
|
66 Private method to show a string representing the entered mouse click |
|
67 sequence. |
|
68 """ |
|
69 if self.__button == Qt.MouseButton.NoButton: |
|
70 self.clickEdit.setText("") |
|
71 else: |
|
72 self.clickEdit.setText(MouseUtilities.MouseButtonModifier2String( |
|
73 self.__modifiers, self.__button)) |
|
74 |
|
75 def eventFilter(self, watched, event): |
|
76 """ |
|
77 Public method called to filter the event queue. |
|
78 |
|
79 @param watched reference to the watched object |
|
80 @type QObject |
|
81 @param event reference to the event that occurred |
|
82 @type QEvent |
|
83 @return flag indicating a handled event |
|
84 @rtype bool |
|
85 """ |
|
86 if ( |
|
87 event.type() == QEvent.Type.MouseButtonRelease and |
|
88 watched == self.clickEdit |
|
89 ): |
|
90 self.__modifiers = event.modifiers() |
|
91 self.__button = event.button() |
|
92 self.__showClickText() |
|
93 return True |
|
94 |
|
95 return False |
|
96 |
|
97 def getClick(self): |
|
98 """ |
|
99 Public method to get the entered mouse click sequence. |
|
100 |
|
101 @return tuple containing the modifiers and the mouse button |
|
102 @rtype tuple of Qt.KeyboardModifiers and Qt.MouseButton |
|
103 """ |
|
104 return (self.__modifiers, self.__button) |