Utilities/MouseUtilities.py

Wed, 24 Jun 2015 19:52:13 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 24 Jun 2015 19:52:13 +0200
changeset 4290
5d4f4230a5ed
child 4291
5f7f8c8d8bc2
permissions
-rw-r--r--

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.

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
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
3 # Copyright (c) 2015 Detlev Offenbach <detlev@die-offenbachs.de>
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 = {
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
16 Qt.ShiftModifier: QCoreApplication.translate(
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"),
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
18 Qt.AltModifier: QCoreApplication.translate(
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"),
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
20 Qt.ControlModifier: QCoreApplication.translate(
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"),
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
22 Qt.MetaModifier: QCoreApplication.translate(
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 }
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
25 __modifierOrder = [Qt.MetaModifier, Qt.AltModifier, Qt.ShiftModifier,
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
26 Qt.ControlModifier]
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
27 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
28 __modifier2String = {
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 Qt.ShiftModifier: QCoreApplication.translate(
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 "MouseUtilities", "Shift"),
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
31 Qt.AltModifier: QCoreApplication.translate(
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", "Alt"),
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
33 Qt.ControlModifier: QCoreApplication.translate(
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", "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
35 Qt.MetaModifier: QCoreApplication.translate(
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", "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
37 }
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 __modifierOrder = [Qt.MetaModifier, Qt.ControlModifier, Qt.AltModifier,
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 Qt.ShiftModifier]
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
40
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
41
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
42 __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
43 Qt.LeftButton: QCoreApplication.translate(
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 "MouseUtilities", "Left 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
45 Qt.RightButton: QCoreApplication.translate(
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 "MouseUtilities", "Right 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
47 Qt.MidButton: QCoreApplication.translate(
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", "Middle 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
49 Qt.XButton1: QCoreApplication.translate(
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", "Extra Button 1"),
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
51 Qt.XButton2: QCoreApplication.translate(
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", "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
53 }
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
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
55
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 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
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 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
59 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
60
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 @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
62 @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
63 @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
64 @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
65 @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
66 @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
67 """
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 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
69 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
70
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 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
72 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
73 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
74 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
75 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
76 return "+".join(parts)

eric ide

mercurial