eric6/E5Gui/E5Action.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).

55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
b5c84934de9c Renamed E4Gui to E5Gui.
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) 2006 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing an Action class extending QAction.
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9 This extension is necessary in order to support alternate keyboard
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 shortcuts.
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 """
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3591
diff changeset
13 from PyQt5.QtGui import QIcon, QKeySequence
7761
ed2c67d20328 Eliminated use of qApp in order to prepare for PyQt6 migration.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
14 from PyQt5.QtWidgets import QAction, QActionGroup
ed2c67d20328 Eliminated use of qApp in order to prepare for PyQt6 migration.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
15
ed2c67d20328 Eliminated use of qApp in order to prepare for PyQt6 migration.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
16 from E5Gui.E5Application import e5App
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
18
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 class ArgumentsError(RuntimeError):
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 """
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
21 Class implementing an exception, which is raised, if the wrong number of
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
22 arguments are given.
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 """
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 def __init__(self, error):
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 """
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 Constructor
2953
703452a2876f Started correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
27
703452a2876f Started correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
28 @param error error message of the exception (string)
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 """
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 self.errorMessage = str(error)
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 def __repr__(self):
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3178
diff changeset
34 Special method returning a representation of the exception.
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 @return string representing the error message
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 """
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 return str(self.errorMessage)
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 def __str__(self):
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 """
3591
2f2a4a76dd22 Corrected a bunch of source docu issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3178
diff changeset
42 Special method returning a string representation of the exception.
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 @return string representing the error message
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 """
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 return str(self.errorMessage)
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
48
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 class E5Action(QAction):
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 """
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 Class implementing an Action class extending QAction.
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 """
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 def __init__(self, *args):
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 """
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 Constructor
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 @param args argument list of the constructor. This list is one of
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 <ul>
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
59 <li>text (string), icon (QIcon), menu text (string),
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
60 accelarator (QKeySequence), alternative accelerator
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
61 (QKeySequence), parent (QObject), name (string), toggle
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
62 (boolean)</li>
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
63 <li>text (string), icon (QIcon), menu text (string),
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
64 accelarator (QKeySequence), alternative accelerator
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
65 (QKeySequence), parent (QObject), name (string)</li>
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
66 <li>text (string), menu text (string),
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
67 accelarator (QKeySequence), alternative accelerator
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
68 (QKeySequence), parent (QObject), name (string), toggle
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
69 (boolean)</li>
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
70 <li>text (string), menu text (string),
2990
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
71 accelarator (QKeySequence), alternative accelerator
583beaf0b4b8 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2953
diff changeset
72 (QKeySequence), parent (QObject), name (string)</li>
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 </ul>
2953
703452a2876f Started correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
74 @exception ArgumentsError raised to indicate invalid arguments
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 """
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 if isinstance(args[1], QIcon):
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 icon = args[1]
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 incr = 1
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 else:
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 icon = None
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 incr = 0
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
82 if len(args) < 6 + incr:
410
e5d1addeb90c Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 267
diff changeset
83 raise ArgumentsError(
e5d1addeb90c Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 267
diff changeset
84 "Not enough arguments, {0:d} expected, got {1:d}".format(
3035
36e9f388958b Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2990
diff changeset
85 6 + incr, len(args)))
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
86 elif len(args) > 7 + incr:
410
e5d1addeb90c Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 267
diff changeset
87 raise ArgumentsError(
e5d1addeb90c Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 267
diff changeset
88 "Too many arguments, max. {0:d} expected, got {1:d}".format(
3035
36e9f388958b Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2990
diff changeset
89 7 + incr, len(args)))
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
91 parent = args[4 + incr]
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2302
diff changeset
92 super(E5Action, self).__init__(parent)
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
93 name = args[5 + incr]
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 if name:
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 self.setObjectName(name)
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
97 if args[1 + incr]:
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
98 self.setText(args[1 + incr])
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 if args[0]:
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 self.setIconText(args[0])
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
102 if args[2 + incr]:
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
103 self.setShortcut(QKeySequence(args[2 + incr]))
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
105 if args[3 + incr]:
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
106 self.setAlternateShortcut(QKeySequence(args[3 + incr]))
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 if icon:
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 self.setIcon(icon)
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
111 if len(args) == 7 + incr:
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
112 self.setCheckable(args[6 + incr])
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113
267
f4cd9c07da76 Added code to show the keyboard shortcut to the tooltip of an action.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
114 self.__ammendToolTip()
f4cd9c07da76 Added code to show the keyboard shortcut to the tooltip of an action.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
115
1521
1e684e74d2a1 Fixed an issue configuring keyboard shortcuts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
116 def setAlternateShortcut(self, shortcut, removeEmpty=False):
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 """
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 Public slot to set the alternative keyboard shortcut.
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 @param shortcut the alternative accelerator (QKeySequence)
1521
1e684e74d2a1 Fixed an issue configuring keyboard shortcuts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
121 @param removeEmpty flag indicating to remove the alternate shortcut,
1e684e74d2a1 Fixed an issue configuring keyboard shortcuts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
122 if it is empty (boolean)
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 """
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 if not shortcut.isEmpty():
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 shortcuts = self.shortcuts()
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 if len(shortcuts) > 0:
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 if len(shortcuts) == 1:
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 shortcuts.append(shortcut)
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 else:
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 shortcuts[1] = shortcut
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 self.setShortcuts(shortcuts)
1521
1e684e74d2a1 Fixed an issue configuring keyboard shortcuts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
132 elif removeEmpty:
1e684e74d2a1 Fixed an issue configuring keyboard shortcuts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
133 shortcuts = self.shortcuts()
1e684e74d2a1 Fixed an issue configuring keyboard shortcuts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
134 if len(shortcuts) == 2:
1e684e74d2a1 Fixed an issue configuring keyboard shortcuts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
135 del shortcuts[1]
1e684e74d2a1 Fixed an issue configuring keyboard shortcuts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
136 self.setShortcuts(shortcuts)
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 def alternateShortcut(self):
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 """
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140 Public method to retrieve the alternative keyboard shortcut.
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 @return the alternative accelerator (QKeySequence)
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143 """
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 shortcuts = self.shortcuts()
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 if len(shortcuts) < 2:
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 return QKeySequence()
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 else:
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 return shortcuts[1]
267
f4cd9c07da76 Added code to show the keyboard shortcut to the tooltip of an action.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
149
f4cd9c07da76 Added code to show the keyboard shortcut to the tooltip of an action.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
150 def setShortcut(self, shortcut):
f4cd9c07da76 Added code to show the keyboard shortcut to the tooltip of an action.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
151 """
f4cd9c07da76 Added code to show the keyboard shortcut to the tooltip of an action.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
152 Public slot to set the keyboard shortcut.
f4cd9c07da76 Added code to show the keyboard shortcut to the tooltip of an action.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
153
f4cd9c07da76 Added code to show the keyboard shortcut to the tooltip of an action.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
154 @param shortcut the accelerator (QKeySequence)
f4cd9c07da76 Added code to show the keyboard shortcut to the tooltip of an action.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
155 """
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2302
diff changeset
156 super(E5Action, self).setShortcut(shortcut)
267
f4cd9c07da76 Added code to show the keyboard shortcut to the tooltip of an action.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
157 self.__ammendToolTip()
f4cd9c07da76 Added code to show the keyboard shortcut to the tooltip of an action.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
158
f4cd9c07da76 Added code to show the keyboard shortcut to the tooltip of an action.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
159 def setShortcuts(self, shortcuts):
f4cd9c07da76 Added code to show the keyboard shortcut to the tooltip of an action.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
160 """
f4cd9c07da76 Added code to show the keyboard shortcut to the tooltip of an action.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
161 Public slot to set the list of keyboard shortcuts.
f4cd9c07da76 Added code to show the keyboard shortcut to the tooltip of an action.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
162
f4cd9c07da76 Added code to show the keyboard shortcut to the tooltip of an action.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
163 @param shortcuts list of keyboard accelerators (list of QKeySequence)
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
164 or key for a platform dependent list of accelerators
267
f4cd9c07da76 Added code to show the keyboard shortcut to the tooltip of an action.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
165 (QKeySequence.StandardKey)
f4cd9c07da76 Added code to show the keyboard shortcut to the tooltip of an action.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
166 """
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2302
diff changeset
167 super(E5Action, self).setShortcuts(shortcuts)
267
f4cd9c07da76 Added code to show the keyboard shortcut to the tooltip of an action.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
168 self.__ammendToolTip()
f4cd9c07da76 Added code to show the keyboard shortcut to the tooltip of an action.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
169
1580
7495b3e892a9 Enhanced the web browser about box and corrected the behavior of the web browser full screen toolbutton.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1521
diff changeset
170 def setIconText(self, text):
7495b3e892a9 Enhanced the web browser about box and corrected the behavior of the web browser full screen toolbutton.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1521
diff changeset
171 """
7495b3e892a9 Enhanced the web browser about box and corrected the behavior of the web browser full screen toolbutton.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1521
diff changeset
172 Public slot to set the icon text of the action.
7495b3e892a9 Enhanced the web browser about box and corrected the behavior of the web browser full screen toolbutton.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1521
diff changeset
173
7495b3e892a9 Enhanced the web browser about box and corrected the behavior of the web browser full screen toolbutton.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1521
diff changeset
174 @param text new icon text (string)
7495b3e892a9 Enhanced the web browser about box and corrected the behavior of the web browser full screen toolbutton.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1521
diff changeset
175 """
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2302
diff changeset
176 super(E5Action, self).setIconText(text)
1580
7495b3e892a9 Enhanced the web browser about box and corrected the behavior of the web browser full screen toolbutton.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1521
diff changeset
177 self.__ammendToolTip()
7495b3e892a9 Enhanced the web browser about box and corrected the behavior of the web browser full screen toolbutton.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1521
diff changeset
178
267
f4cd9c07da76 Added code to show the keyboard shortcut to the tooltip of an action.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
179 def __ammendToolTip(self):
f4cd9c07da76 Added code to show the keyboard shortcut to the tooltip of an action.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
180 """
f4cd9c07da76 Added code to show the keyboard shortcut to the tooltip of an action.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
181 Private slot to add the primary keyboard accelerator to the tooltip.
f4cd9c07da76 Added code to show the keyboard shortcut to the tooltip of an action.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
182 """
f4cd9c07da76 Added code to show the keyboard shortcut to the tooltip of an action.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
183 shortcut = self.shortcut().toString(QKeySequence.NativeText)
f4cd9c07da76 Added code to show the keyboard shortcut to the tooltip of an action.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
184 if shortcut:
7761
ed2c67d20328 Eliminated use of qApp in order to prepare for PyQt6 migration.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
185 if e5App().isLeftToRight():
267
f4cd9c07da76 Added code to show the keyboard shortcut to the tooltip of an action.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
186 fmt = "{0} ({1})"
f4cd9c07da76 Added code to show the keyboard shortcut to the tooltip of an action.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
187 else:
f4cd9c07da76 Added code to show the keyboard shortcut to the tooltip of an action.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
188 fmt = "({1}) {0}"
f4cd9c07da76 Added code to show the keyboard shortcut to the tooltip of an action.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 96
diff changeset
189 self.setToolTip(fmt.format(self.iconText(), shortcut))
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
191
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 def addActions(target, actions):
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 """
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194 Module function to add a list of actions to a widget.
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
195
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196 @param target reference to the target widget (QWidget)
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197 @param actions list of actions to be added to the target. A
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
198 None indicates a separator (list of QActions)
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
199 """
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
200 if target is None:
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
201 return
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
202
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203 for action in actions:
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
204 if action is None:
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
205 target.addSeparator()
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
206 else:
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207 target.addAction(action)
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
208
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
209
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
210 def createActionGroup(parent, name=None, exclusive=False):
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
211 """
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
212 Module function to create an action group.
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
213
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
214 @param parent parent object of the action group (QObject)
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
215 @param name name of the action group object (string)
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
216 @param exclusive flag indicating an exclusive action group (boolean)
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
217 @return reference to the created action group (QActionGroup)
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
218 """
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
219 actGrp = QActionGroup(parent)
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
220 if name:
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
221 actGrp.setObjectName(name)
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
222 actGrp.setExclusive(exclusive)
96
9624a110667d Started to clean up the code supported by py3flakes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
223 return actGrp

eric ide

mercurial