Skip to content

Commit

Permalink
Merge branch 'improve_add_action' of https://github.com/ramses44/qtpy
Browse files Browse the repository at this point in the history
…into improve_add_action
  • Loading branch information
ramses44 committed Oct 13, 2023
2 parents d6fa72d + 1a77685 commit 948c872
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions qtpy/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,28 +81,32 @@ def add_action(self, *args, old_add_action):
shortcut: QKeySequence | QKeySequence.StandardKey | str | int

# if args and isinstance(args[0], QIcon):
if any(map(lambda arg: isinstance(arg, QIcon), args[:1])): # Better to use previous line instead of this
if any(
isinstance(arg, QIcon) for arg in args[:1]
): # Better to use previous line instead of this
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,
],
if (
all(
isinstance(arg, t)
for arg, t in zip(
args,
[
str,
(QKeySequence, QKeySequence.StandardKey, str, int),
QObject,
bytes,
],
)
)
and len(args) >= 2
):
if len(args) >= 2:
text, shortcut, *args = args
action = old_add_action(self, icon, text, *args)
action.setShortcut(shortcut)
return action
text, shortcut, *args = args
action = old_add_action(self, icon, text, *args)
action.setShortcut(shortcut)
return action

return old_add_action(self, *args)

Expand Down

0 comments on commit 948c872

Please sign in to comment.