Skip to content

Commit 4da5ac2

Browse files
authored
feat: allow chaining of QIconifyIcon.addKey (#267)
1 parent e471031 commit 4da5ac2

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/superqt/iconify/__init__.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ def __init__(
8181
"`pip install superqt[iconify]` extra."
8282
)
8383
super().__init__()
84-
self.addKey(*key, color=color, flip=flip, rotate=rotate, dir=dir)
84+
if key:
85+
self.addKey(*key, color=color, flip=flip, rotate=rotate, dir=dir)
8586

8687
def addKey(
8788
self,
@@ -93,7 +94,7 @@ def addKey(
9394
size: QSize | None = None,
9495
mode: QIcon.Mode = QIcon.Mode.Normal,
9596
state: QIcon.State = QIcon.State.Off,
96-
) -> None:
97+
) -> QIconifyIcon:
9798
"""Add an icon to this QIcon.
9899
99100
This is a variant of `QIcon.addFile` that uses an iconify icon keys and
@@ -123,6 +124,11 @@ def addKey(
123124
Mode specified for the icon, passed to `QIcon.addFile`.
124125
state : QIcon.State, optional
125126
State specified for the icon, passed to `QIcon.addFile`.
127+
128+
Returns
129+
-------
130+
QIconifyIcon
131+
This QIconifyIcon instance, for chaining.
126132
"""
127133
try:
128134
path = svg_path(*key, color=color, flip=flip, rotate=rotate, dir=dir)
@@ -135,6 +141,8 @@ def addKey(
135141
else:
136142
self.addFile(str(path), size or QSize(), mode, state)
137143

144+
return self
145+
138146
def _draw_text_fallback(self, key: tuple[str, ...]) -> None:
139147
if style := QApplication.style():
140148
pixmap = style.standardPixmap(style.StandardPixmap.SP_MessageBoxQuestion)

0 commit comments

Comments
 (0)