-
-
Notifications
You must be signed in to change notification settings - Fork 157
Improve add_action implementation #460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
2dd2013
d6fa72d
cc424ae
1a77685
948c872
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -79,68 +79,35 @@ def add_action(self, *args, old_add_action): | |||
icon: QIcon | ||||
text: str | ||||
shortcut: QKeySequence | QKeySequence.StandardKey | str | int | ||||
receiver: QObject | ||||
member: bytes | ||||
if all( | ||||
isinstance(arg, t) | ||||
for arg, t in zip( | ||||
args, | ||||
[ | ||||
str, | ||||
(QKeySequence, QKeySequence.StandardKey, str, int), | ||||
QObject, | ||||
bytes, | ||||
], | ||||
) | ||||
): | ||||
if len(args) == 2: | ||||
text, shortcut = args | ||||
action = old_add_action(self, text) | ||||
action.setShortcut(shortcut) | ||||
elif len(args) == 3: | ||||
text, shortcut, receiver = args | ||||
action = old_add_action(self, text, receiver) | ||||
action.setShortcut(shortcut) | ||||
elif len(args) == 4: | ||||
text, shortcut, receiver, member = args | ||||
action = old_add_action(self, text, receiver, member, shortcut) | ||||
else: | ||||
return old_add_action(self, *args) | ||||
return action | ||||
if all( | ||||
isinstance(arg, t) | ||||
for arg, t in zip( | ||||
args, | ||||
[ | ||||
QIcon, | ||||
str, | ||||
(QKeySequence, QKeySequence.StandardKey, str, int), | ||||
QObject, | ||||
bytes, | ||||
], | ||||
|
||||
# if args and isinstance(args[0], QIcon): | ||||
if any( | ||||
isinstance(arg, QIcon) for arg in args[:1] | ||||
): # Better to use previous line instead of this | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The condition means that an instance of Line 83 in 948c872
|
||||
icon, *args = args | ||||
else: | ||||
icon = QIcon() | ||||
|
||||
if ( | ||||
all( | ||||
isinstance(arg, t) | ||||
for arg, t in zip( | ||||
args, | ||||
[ | ||||
str, | ||||
(QKeySequence, QKeySequence.StandardKey, str, int), | ||||
QObject, | ||||
bytes, | ||||
], | ||||
) | ||||
) | ||||
and len(args) >= 2 | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here, you lose the case when only an icon and a text are provided. Indeed, from Line 87 in 948c872
args becomes ('text', ) , i.e., len(args) == 1 .
|
||||
): | ||||
if len(args) == 3: | ||||
icon, text, shortcut = args | ||||
action = old_add_action(self, icon, text) | ||||
action.setShortcut(QKeySequence(shortcut)) | ||||
elif len(args) == 4: | ||||
icon, text, shortcut, receiver = args | ||||
action = old_add_action(self, icon, text, receiver) | ||||
action.setShortcut(QKeySequence(shortcut)) | ||||
elif len(args) == 5: | ||||
icon, text, shortcut, receiver, member = args | ||||
action = old_add_action( | ||||
self, | ||||
icon, | ||||
text, | ||||
receiver, | ||||
member, | ||||
QKeySequence(shortcut), | ||||
) | ||||
else: | ||||
return old_add_action(self, *args) | ||||
text, shortcut, *args = args | ||||
action = old_add_action(self, icon, text, *args) | ||||
action.setShortcut(shortcut) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You might have to explicitly convert the For the latest packages,
It appears that all the flavors support a string as the shortcut. However, I've composed #461 thanks to this PR. If you wish, you may cherry-pick the test from #461. I'm going to add a back port for |
||||
return action | ||||
|
||||
return old_add_action(self, *args) | ||||
|
||||
|
||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a pending change to be done?