Tue, 02 Mar 2021 17:17:09 +0100
Changed the use of PyQt enums because the way they were used previously is deprecated since two years and replaced some deprecated Qt stuff.
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 | |
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
|
10 | from PyQt5.QtCore import Qt, QCoreApplication |
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"), |
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
|
51 | Qt.MouseButton.MidButton: 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) |