Utilities/MouseUtilities.py

Fri, 07 Apr 2017 18:45:08 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Fri, 07 Apr 2017 18:45:08 +0200
branch
maintenance
changeset 5681
be30320a29bc
parent 5389
9b1c800daff3
child 6048
82ad8ec9548c
permissions
-rw-r--r--

Merged again because of a last second bug fix.

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
5389
9b1c800daff3 Updated copyright for 2017.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
3 # Copyright (c) 2015 - 2017 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
4291
5f7f8c8d8bc2 Added a dialog to configure a mouse click sequence.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4290
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: 4290
diff changeset
11
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
12 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
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 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
15
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 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
17 __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
18 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
19 "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
20 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
21 "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
22 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
23 "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
24 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
25 "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
26 }
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 __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
28 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
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 = {
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.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
32 "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
33 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
34 "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
35 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
36 "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
37 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
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 }
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 __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
41 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
42
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
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 __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
45 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
46 "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
47 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
48 "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
49 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
50 "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
51 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
52 "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
53 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
54 "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
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
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 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
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 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
61 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
62
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 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
64 @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
65 @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
66 @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
67 @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
68 @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
69 """
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 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
71 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
72
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 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
74 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
75 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
76 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
77 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
78 return "+".join(parts)

eric ide

mercurial