eric6/Preferences/MouseClickDialog.py

Sun, 01 Sep 2019 19:40:53 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 01 Sep 2019 19:40:53 +0200
branch
without_py2_and_pyqt4
changeset 7198
684261ef2165
parent 6942
2602857055c5
child 7229
53054eb5b15a
permissions
-rw-r--r--

Removed the Qt4 runtime stuff.

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

eric ide

mercurial