Preferences/MouseClickDialog.py

changeset 4291
5f7f8c8d8bc2
child 4631
5c1a96925da4
equal deleted inserted replaced
4290:5d4f4230a5ed 4291:5f7f8c8d8bc2
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2015 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 __future__ import unicode_literals
11
12 from PyQt5.QtCore import pyqtSlot, Qt, QEvent
13 from PyQt5.QtWidgets import QDialog, QDialogButtonBox
14
15 from .Ui_MouseClickDialog import Ui_MouseClickDialog
16
17 from Utilities import MouseUtilities
18
19
20 class MouseClickDialog(QDialog, Ui_MouseClickDialog):
21 """
22 Class implementing a dialog for the configuration of a mouse click
23 sequence.
24 """
25 def __init__(self, modifiers, button, parent=None):
26 """
27 Constructor
28
29 @param modifiers keyboard modifiers of the handler
30 @type Qt.KeyboardModifiers
31 @param button mouse button of the handler
32 @type Qt.MouseButton
33 @param parent reference to the parent widget
34 @type QWidget
35 """
36 super(MouseClickDialog, self).__init__(parent)
37 self.setupUi(self)
38 self.setModal(True)
39
40 self.clickGroup.installEventFilter(self)
41 self.clearButton.installEventFilter(self)
42 self.clickEdit.installEventFilter(self)
43
44 self.buttonBox.button(QDialogButtonBox.Ok).installEventFilter(self)
45 self.buttonBox.button(QDialogButtonBox.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.NoModifier
61 self.__button = Qt.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.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 event.type() == QEvent.MouseButtonRelease and \
87 watched == self.clickEdit:
88 self.__modifiers = int(event.modifiers())
89 self.__button = int(event.button())
90 self.__showClickText()
91 return True
92
93 return False
94
95 def getClick(self):
96 """
97 Public method to get the entered mouse click sequence.
98
99 @return tuple containing the modifiers and the mouse button
100 @rtype tuple of Qt.KeyboardModifiers and Qt.MouseButton
101 """
102 return (self.__modifiers, self.__button)

eric ide

mercurial