Skip to content

Commit

Permalink
feat: allow chaining of QIconifyIcon.addKey (#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
tlambert03 authored Dec 21, 2024
1 parent e471031 commit 4da5ac2
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/superqt/iconify/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ def __init__(
"`pip install superqt[iconify]` extra."
)
super().__init__()
self.addKey(*key, color=color, flip=flip, rotate=rotate, dir=dir)
if key:
self.addKey(*key, color=color, flip=flip, rotate=rotate, dir=dir)

def addKey(
self,
Expand All @@ -93,7 +94,7 @@ def addKey(
size: QSize | None = None,
mode: QIcon.Mode = QIcon.Mode.Normal,
state: QIcon.State = QIcon.State.Off,
) -> None:
) -> QIconifyIcon:
"""Add an icon to this QIcon.
This is a variant of `QIcon.addFile` that uses an iconify icon keys and
Expand Down Expand Up @@ -123,6 +124,11 @@ def addKey(
Mode specified for the icon, passed to `QIcon.addFile`.
state : QIcon.State, optional
State specified for the icon, passed to `QIcon.addFile`.
Returns
-------
QIconifyIcon
This QIconifyIcon instance, for chaining.
"""
try:
path = svg_path(*key, color=color, flip=flip, rotate=rotate, dir=dir)
Expand All @@ -135,6 +141,8 @@ def addKey(
else:
self.addFile(str(path), size or QSize(), mode, state)

return self

def _draw_text_fallback(self, key: tuple[str, ...]) -> None:
if style := QApplication.style():
pixmap = style.standardPixmap(style.StandardPixmap.SP_MessageBoxQuestion)
Expand Down

0 comments on commit 4da5ac2

Please sign in to comment.