From bd6899133fbbf6efff9fe9eabc05bae20b1f92f3 Mon Sep 17 00:00:00 2001 From: Talley Lambert Date: Mon, 23 Oct 2023 11:20:59 -0400 Subject: [PATCH] feat: icon.name() (#213) --- src/superqt/iconify/__init__.py | 8 ++++++++ tests/test_iconify.py | 1 + 2 files changed, 9 insertions(+) diff --git a/src/superqt/iconify/__init__.py b/src/superqt/iconify/__init__.py index 92fbb81..8932270 100644 --- a/src/superqt/iconify/__init__.py +++ b/src/superqt/iconify/__init__.py @@ -71,5 +71,13 @@ class QIconifyIcon(QIcon): "Please install it with `pip install pyconify` or use the " "`pip install superqt[iconify]` extra." ) from e + if len(key) == 1: + self._name = key[0] + else: + self._name = ":".join(key) self.path = svg_path(*key, color=color, flip=flip, rotate=rotate, dir=dir) super().__init__(str(self.path)) + + def name(self) -> str: + """Return the iconify `prefix:icon` represented by this QIcon.""" + return self._name diff --git a/tests/test_iconify.py b/tests/test_iconify.py index 991c5b8..3bcb167 100644 --- a/tests/test_iconify.py +++ b/tests/test_iconify.py @@ -15,6 +15,7 @@ def test_qiconify(qtbot: "QtBot", monkeypatch: "pytest.MonkeyPatch") -> None: icon = QIconifyIcon("bi:alarm-fill", color="red", rotate=90) assert icon.path.name.endswith(".svg") + assert icon.name() == "bi:alarm-fill" btn = QPushButton() qtbot.addWidget(btn)