eric7/Utilities/MouseUtilities.py

Sun, 16 May 2021 20:07:24 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 16 May 2021 20:07:24 +0200
branch
eric7
changeset 8318
962bce857696
parent 8312
800c432b34c8
child 8881
54e42bc2437a
permissions
-rw-r--r--

Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.

4290
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7923
91e843545d9a Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7781
diff changeset
3 # Copyright (c) 2015 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
4290
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing utility functions related to Mouse stuff.
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
8318
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
10 from PyQt6.QtCore import Qt, QCoreApplication
4290
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 import Globals
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 if Globals.isMacPlatform():
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 __modifier2String = {
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
16 Qt.KeyboardModifier.ShiftModifier: QCoreApplication.translate(
4290
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 "MouseUtilities", "Shift"),
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
18 Qt.KeyboardModifier.AltModifier: QCoreApplication.translate(
4290
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 "MouseUtilities", "Alt"),
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
20 Qt.KeyboardModifier.ControlModifier: QCoreApplication.translate(
4290
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 "MouseUtilities", "Cmd"),
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
22 Qt.KeyboardModifier.MetaModifier: QCoreApplication.translate(
4290
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 "MouseUtilities", "Ctrl"),
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 }
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
25 __modifierOrder = [Qt.KeyboardModifier.MetaModifier,
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
26 Qt.KeyboardModifier.AltModifier,
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
27 Qt.KeyboardModifier.ShiftModifier,
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
28 Qt.KeyboardModifier.ControlModifier]
4290
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 else:
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 __modifier2String = {
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
31 Qt.KeyboardModifier.ShiftModifier: QCoreApplication.translate(
4290
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 "MouseUtilities", "Shift"),
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
33 Qt.KeyboardModifier.AltModifier: QCoreApplication.translate(
4290
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 "MouseUtilities", "Alt"),
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
35 Qt.KeyboardModifier.ControlModifier: QCoreApplication.translate(
4290
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 "MouseUtilities", "Ctrl"),
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
37 Qt.KeyboardModifier.MetaModifier: QCoreApplication.translate(
4290
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 "MouseUtilities", "Meta"),
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 }
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
40 __modifierOrder = [Qt.KeyboardModifier.MetaModifier,
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
41 Qt.KeyboardModifier.ControlModifier,
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
42 Qt.KeyboardModifier.AltModifier,
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
43 Qt.KeyboardModifier.ShiftModifier]
4290
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 __button2String = {
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
47 Qt.MouseButton.LeftButton: QCoreApplication.translate(
4290
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 "MouseUtilities", "Left Button"),
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
49 Qt.MouseButton.RightButton: QCoreApplication.translate(
4290
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 "MouseUtilities", "Right Button"),
8318
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
51 Qt.MouseButton.MiddleButton: QCoreApplication.translate(
4290
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 "MouseUtilities", "Middle Button"),
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
53 Qt.MouseButton.XButton1: QCoreApplication.translate(
4290
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 "MouseUtilities", "Extra Button 1"),
8143
2c730d5fd177 Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
55 Qt.MouseButton.XButton2: QCoreApplication.translate(
4290
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 "MouseUtilities", "Extra Button 2"),
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 }
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 def MouseButtonModifier2String(modifiers, button):
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 """
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 Function to convert a modifier and mouse button combination to a
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 displayable string.
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 @param modifiers keyboard modifiers of the handler
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 @type Qt.KeyboardModifiers
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 @param button mouse button of the handler
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 @type Qt.MouseButton
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 @return display string of the modifier and mouse button combination
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 @rtype str
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 """
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 if button not in __button2String:
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 return ""
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 parts = []
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 for mod in __modifierOrder:
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 if modifiers & mod:
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 parts.append(__modifier2String[mod])
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 parts.append(__button2String[button])
5d4f4230a5ed Moved the code to create a display string for a modifier and mouse button combination to a separate file because it will be needed in other places than just the editor as well.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 return "+".join(parts)

eric ide

mercurial