eric6/Preferences/MouseClickDialog.py

Sat, 27 Feb 2021 12:08:23 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 27 Feb 2021 12:08:23 +0100
changeset 8138
169e65a6787c
parent 7923
91e843545d9a
child 8143
2c730d5fd177
permissions
-rw-r--r--

Shell: added functionality to show a prompt when the main client process has exited (e.g. a script ended).

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
7923
91e843545d9a Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7780
diff changeset
3 # Copyright (c) 2015 - 2021 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 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
11 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
12
5f7f8c8d8bc2 Added a dialog to configure a mouse click sequence.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 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
14
5f7f8c8d8bc2 Added a dialog to configure a mouse click sequence.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 from Utilities import MouseUtilities
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
5f7f8c8d8bc2 Added a dialog to configure a mouse click sequence.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 class MouseClickDialog(QDialog, Ui_MouseClickDialog):
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 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
21 sequence.
5f7f8c8d8bc2 Added a dialog to configure a mouse click sequence.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 """
5f7f8c8d8bc2 Added a dialog to configure a mouse click sequence.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 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
24 """
5f7f8c8d8bc2 Added a dialog to configure a mouse click sequence.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 Constructor
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 @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
28 @type Qt.KeyboardModifiers
5f7f8c8d8bc2 Added a dialog to configure a mouse click sequence.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 @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
30 @type Qt.MouseButton
5f7f8c8d8bc2 Added a dialog to configure a mouse click sequence.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 @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
32 @type QWidget
5f7f8c8d8bc2 Added a dialog to configure a mouse click sequence.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 """
5f7f8c8d8bc2 Added a dialog to configure a mouse click sequence.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 super(MouseClickDialog, self).__init__(parent)
5f7f8c8d8bc2 Added a dialog to configure a mouse click sequence.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 self.setupUi(self)
5f7f8c8d8bc2 Added a dialog to configure a mouse click sequence.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 self.setModal(True)
5f7f8c8d8bc2 Added a dialog to configure a mouse click sequence.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37
5f7f8c8d8bc2 Added a dialog to configure a mouse click sequence.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 self.clickGroup.installEventFilter(self)
5f7f8c8d8bc2 Added a dialog to configure a mouse click sequence.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 self.clearButton.installEventFilter(self)
5f7f8c8d8bc2 Added a dialog to configure a mouse click sequence.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 self.clickEdit.installEventFilter(self)
5f7f8c8d8bc2 Added a dialog to configure a mouse click sequence.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41
5f7f8c8d8bc2 Added a dialog to configure a mouse click sequence.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 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
43 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
44
5f7f8c8d8bc2 Added a dialog to configure a mouse click sequence.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 self.__modifiers = modifiers
5f7f8c8d8bc2 Added a dialog to configure a mouse click sequence.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 self.__button = button
5f7f8c8d8bc2 Added a dialog to configure a mouse click sequence.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47
5f7f8c8d8bc2 Added a dialog to configure a mouse click sequence.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 self.__showClickText()
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 msh = self.minimumSizeHint()
5f7f8c8d8bc2 Added a dialog to configure a mouse click sequence.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 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
52
5f7f8c8d8bc2 Added a dialog to configure a mouse click sequence.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 @pyqtSlot()
5f7f8c8d8bc2 Added a dialog to configure a mouse click sequence.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 def on_clearButton_clicked(self):
5f7f8c8d8bc2 Added a dialog to configure a mouse click sequence.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 """
5f7f8c8d8bc2 Added a dialog to configure a mouse click sequence.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 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
57 """
5f7f8c8d8bc2 Added a dialog to configure a mouse click sequence.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 self.__modifiers = Qt.NoModifier
5f7f8c8d8bc2 Added a dialog to configure a mouse click sequence.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 self.__button = Qt.NoButton
5f7f8c8d8bc2 Added a dialog to configure a mouse click sequence.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 self.__showClickText()
5f7f8c8d8bc2 Added a dialog to configure a mouse click sequence.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61
5f7f8c8d8bc2 Added a dialog to configure a mouse click sequence.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 def __showClickText(self):
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 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
65 sequence.
5f7f8c8d8bc2 Added a dialog to configure a mouse click sequence.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 """
5f7f8c8d8bc2 Added a dialog to configure a mouse click sequence.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 if self.__button == Qt.NoButton:
5f7f8c8d8bc2 Added a dialog to configure a mouse click sequence.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 self.clickEdit.setText("")
5f7f8c8d8bc2 Added a dialog to configure a mouse click sequence.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 else:
5f7f8c8d8bc2 Added a dialog to configure a mouse click sequence.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 self.clickEdit.setText(MouseUtilities.MouseButtonModifier2String(
5f7f8c8d8bc2 Added a dialog to configure a mouse click sequence.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 self.__modifiers, self.__button))
5f7f8c8d8bc2 Added a dialog to configure a mouse click sequence.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72
5f7f8c8d8bc2 Added a dialog to configure a mouse click sequence.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 def eventFilter(self, watched, event):
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 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
76
5f7f8c8d8bc2 Added a dialog to configure a mouse click sequence.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 @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
78 @type QObject
5f7f8c8d8bc2 Added a dialog to configure a mouse click sequence.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 @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
80 @type QEvent
5f7f8c8d8bc2 Added a dialog to configure a mouse click sequence.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 @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
82 @rtype bool
5f7f8c8d8bc2 Added a dialog to configure a mouse click sequence.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 """
7263
c1af2e327675 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
84 if (
c1af2e327675 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
85 event.type() == QEvent.MouseButtonRelease and
c1af2e327675 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
86 watched == self.clickEdit
c1af2e327675 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
87 ):
4291
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