8 |
8 |
9 This extension is necessary in order to support alternate keyboard |
9 This extension is necessary in order to support alternate keyboard |
10 shortcuts. |
10 shortcuts. |
11 """ |
11 """ |
12 |
12 |
13 from PyQt4.QtGui import QAction, QActionGroup, QIcon, QKeySequence |
13 from PyQt4.QtGui import QAction, QActionGroup, QIcon, QKeySequence, qApp |
14 |
14 |
15 class ArgumentsError(RuntimeError): |
15 class ArgumentsError(RuntimeError): |
16 """ |
16 """ |
17 Class implementing an exception, which is raised, if the wrong number of arguments |
17 Class implementing an exception, which is raised, if the wrong number of arguments |
18 are given. |
18 are given. |
97 self.setIcon(icon) |
97 self.setIcon(icon) |
98 |
98 |
99 if len(args) == 7+incr: |
99 if len(args) == 7+incr: |
100 self.setCheckable(args[6+incr]) |
100 self.setCheckable(args[6+incr]) |
101 |
101 |
|
102 self.__ammendToolTip() |
|
103 |
102 def setAlternateShortcut(self, shortcut): |
104 def setAlternateShortcut(self, shortcut): |
103 """ |
105 """ |
104 Public slot to set the alternative keyboard shortcut. |
106 Public slot to set the alternative keyboard shortcut. |
105 |
107 |
106 @param shortcut the alternative accelerator (QKeySequence) |
108 @param shortcut the alternative accelerator (QKeySequence) |
123 shortcuts = self.shortcuts() |
125 shortcuts = self.shortcuts() |
124 if len(shortcuts) < 2: |
126 if len(shortcuts) < 2: |
125 return QKeySequence() |
127 return QKeySequence() |
126 else: |
128 else: |
127 return shortcuts[1] |
129 return shortcuts[1] |
|
130 |
|
131 def setShortcut(self, shortcut): |
|
132 """ |
|
133 Public slot to set the keyboard shortcut. |
|
134 |
|
135 @param shortcut the accelerator (QKeySequence) |
|
136 """ |
|
137 QAction.setShortcut(self, shortcut) |
|
138 self.__ammendToolTip() |
|
139 |
|
140 def setShortcuts(self, shortcuts): |
|
141 """ |
|
142 Public slot to set the list of keyboard shortcuts. |
|
143 |
|
144 @param shortcuts list of keyboard accelerators (list of QKeySequence) |
|
145 or key for a platform dependent list of accelerators |
|
146 (QKeySequence.StandardKey) |
|
147 """ |
|
148 QAction.setShortcuts(self, shortcuts) |
|
149 self.__ammendToolTip() |
|
150 |
|
151 def __ammendToolTip(self): |
|
152 """ |
|
153 Private slot to add the primary keyboard accelerator to the tooltip. |
|
154 """ |
|
155 shortcut = self.shortcut().toString(QKeySequence.NativeText) |
|
156 if shortcut: |
|
157 if qApp.isLeftToRight(): |
|
158 fmt = "{0} ({1})" |
|
159 else: |
|
160 fmt = "({1}) {0}" |
|
161 self.setToolTip(fmt.format(self.iconText(), shortcut)) |
128 |
162 |
129 def addActions(target, actions): |
163 def addActions(target, actions): |
130 """ |
164 """ |
131 Module function to add a list of actions to a widget. |
165 Module function to add a list of actions to a widget. |
132 |
166 |