Skip to content

Commit e964e21

Browse files
feat: support iconify icon keys (#130)
* feat: icon color stuff * docs * remove passs * more docs * coverage * move import * remove color stuff * style: [pre-commit.ci] auto fixes [...] --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 80c795e commit e964e21

File tree

10 files changed

+43
-32
lines changed

10 files changed

+43
-32
lines changed

demo/model_app.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from typing import List
22

3-
from fonticon_fa6 import FA6S
43
from qtpy.QtCore import QFile, QFileInfo, QSaveFile, Qt, QTextStream
54
from qtpy.QtWidgets import QApplication, QFileDialog, QMessageBox, QTextEdit
65

@@ -160,7 +159,7 @@ class CommandId:
160159
ACTIONS: List[types.Action] = [
161160
types.Action(
162161
id="new_file",
163-
icon=FA6S.file_circle_plus,
162+
icon="fa6-solid:file-circle-plus",
164163
title="New",
165164
keybindings=[types.StandardKeyBinding.New],
166165
status_tip="Create a new file",
@@ -169,7 +168,7 @@ class CommandId:
169168
),
170169
types.Action(
171170
id="open_file",
172-
icon=FA6S.folder_open,
171+
icon="fa6-solid:folder-open",
173172
title="Open...",
174173
keybindings=[types.StandardKeyBinding.Open],
175174
status_tip="Open an existing file",
@@ -178,7 +177,7 @@ class CommandId:
178177
),
179178
types.Action(
180179
id="save_file",
181-
icon=FA6S.floppy_disk,
180+
icon="fa6-solid:floppy-disk",
182181
title="Save",
183182
keybindings=[types.StandardKeyBinding.Save],
184183
status_tip="Save the document to disk",
@@ -203,7 +202,7 @@ class CommandId:
203202
),
204203
types.Action(
205204
id="cut",
206-
icon=FA6S.scissors,
205+
icon="fa6-solid:scissors",
207206
title="Cut",
208207
keybindings=[types.StandardKeyBinding.Cut],
209208
enablement="copyAvailable",
@@ -213,7 +212,7 @@ class CommandId:
213212
),
214213
types.Action(
215214
id="copy",
216-
icon=FA6S.copy,
215+
icon="fa6-solid:copy",
217216
title="Copy",
218217
keybindings=[types.StandardKeyBinding.Copy],
219218
enablement="copyAvailable",
@@ -223,7 +222,7 @@ class CommandId:
223222
),
224223
types.Action(
225224
id="paste",
226-
icon=FA6S.paste,
225+
icon="fa6-solid:paste",
227226
title="Paste",
228227
keybindings=[types.StandardKeyBinding.Paste],
229228
status_tip="Paste the clipboard's contents into the current selection",

demo/multi_file/actions.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from typing import List
22

3-
from fonticon_fa6 import FA6S
4-
53
from app_model.types import Action, KeyBindingRule, KeyCode, KeyMod, MenuRule
64

75
from . import functions
@@ -11,31 +9,31 @@
119
Action(
1210
id=CommandId.OPEN,
1311
title="Open",
14-
icon=FA6S.folder_open,
12+
icon="fa6-solid:folder-open",
1513
callback=functions.open_file,
1614
menus=[MenuRule(id=MenuId.FILE)],
1715
keybindings=[KeyBindingRule(primary=KeyMod.CtrlCmd | KeyCode.KeyO)],
1816
),
1917
Action(
2018
id=CommandId.CLOSE,
2119
title="Close",
22-
icon=FA6S.window_close,
20+
icon="fa6-solid:window-close",
2321
callback=functions.close,
2422
menus=[MenuRule(id=MenuId.FILE)],
2523
keybindings=[KeyBindingRule(primary=KeyMod.CtrlCmd | KeyCode.KeyW)],
2624
),
2725
Action(
2826
id=CommandId.UNDO,
2927
title="Undo",
30-
icon=FA6S.undo,
28+
icon="fa6-solid:undo",
3129
callback=functions.undo,
3230
menus=[MenuRule(id=MenuId.EDIT, group="1_undo_redo")],
3331
keybindings=[KeyBindingRule(primary=KeyMod.CtrlCmd | KeyCode.KeyZ)],
3432
),
3533
Action(
3634
id=CommandId.REDO,
3735
title="Redo",
38-
icon=FA6S.rotate_right,
36+
icon="fa6-solid:rotate-right",
3937
callback=functions.redo,
4038
menus=[MenuRule(id=MenuId.EDIT, group="1_undo_redo")],
4139
keybindings=[
@@ -45,23 +43,23 @@
4543
Action(
4644
id=CommandId.CUT,
4745
title="Cut",
48-
icon=FA6S.cut,
46+
icon="fa6-solid:cut",
4947
callback=functions.cut,
5048
menus=[MenuRule(id=MenuId.EDIT, group="3_copypaste")],
5149
keybindings=[KeyBindingRule(primary=KeyMod.CtrlCmd | KeyCode.KeyX)],
5250
),
5351
Action(
5452
id=CommandId.COPY,
5553
title="Copy",
56-
icon=FA6S.copy,
54+
icon="fa6-solid:copy",
5755
callback=functions.copy,
5856
menus=[MenuRule(id=MenuId.EDIT, group="3_copypaste")],
5957
keybindings=[KeyBindingRule(primary=KeyMod.CtrlCmd | KeyCode.KeyC)],
6058
),
6159
Action(
6260
id=CommandId.PASTE,
6361
title="Paste",
64-
icon=FA6S.paste,
62+
icon="fa6-solid:paste",
6563
callback=functions.paste,
6664
menus=[MenuRule(id=MenuId.EDIT, group="3_copypaste")],
6765
keybindings=[KeyBindingRule(primary=KeyMod.CtrlCmd | KeyCode.KeyV)],

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ dependencies = [
3939
[project.optional-dependencies]
4040
test = ["pytest>=6.0", "pytest-cov"]
4141
test-qt = ["pytest-qt", "fonticon-fontawesome6"]
42-
qt = ["qtpy", "superqt"]
42+
qt = ["qtpy", "superqt[iconify]"]
4343
dev = [
4444
"black",
4545
"ipython",

src/app_model/backends/qt/_qaction.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
cast,
1414
)
1515

16-
from qtpy.QtWidgets import QAction
17-
1816
from app_model import Application
1917
from app_model.expressions import Expr
2018
from app_model.types import ToggleRule
@@ -23,9 +21,12 @@
2321
from ._util import to_qicon
2422

2523
if TYPE_CHECKING:
24+
from PyQt6.QtGui import QAction
2625
from qtpy.QtCore import QObject
2726

2827
from app_model.types import CommandRule, MenuItem
28+
else:
29+
from qtpy.QtWidgets import QAction
2930

3031

3132
class QCommandAction(QAction):

src/app_model/backends/qt/_util.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@
1212

1313
def to_qicon(icon: Icon, theme: Literal["dark", "light"] = "dark") -> QIcon:
1414
"""Create QIcon from Icon."""
15-
from superqt import fonticon
15+
from superqt import QIconifyIcon, fonticon
1616

1717
if icn := getattr(icon, theme, ""):
18-
return fonticon.icon(icn)
18+
if ":" in icn:
19+
return QIconifyIcon(icn)
20+
else:
21+
return fonticon.icon(icn)
1922
return QIcon() # pragma: no cover

src/app_model/types/_command_rule.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ class CommandRule(_BaseModel):
5353
icon: Optional[Icon] = Field(
5454
None,
5555
description="(Optional) Icon used to represent this command, e.g. on buttons "
56-
"or in menus. These may be superqt fonticon keys, such as `fa6s.arrow_down`",
56+
"or in menus. These may be [iconify keys](https://icon-sets.iconify.design), "
57+
"such as `fa6-solid:arrow-down`, or "
58+
"[superqt.fonticon](https://pyapp-kit.github.io/superqt/utilities/fonticon/)"
59+
" keys, such as `fa6s.arrow_down`",
5760
)
5861
enablement: Optional[expressions.Expr] = Field(
5962
None,

src/app_model/types/_icon.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,19 @@ class Icon(_BaseModel):
1414

1515
dark: Optional[str] = Field(
1616
None,
17-
description="Icon path when a dark theme is used. These may be superqt "
18-
"fonticon keys, such as `fa6s.arrow_down`",
17+
description="Icon path when a dark theme is used. These may be "
18+
"[iconify keys](https://icon-sets.iconify.design), such as "
19+
"`fa6-solid:arrow-down`, or "
20+
"[superqt.fonticon](https://pyapp-kit.github.io/superqt/utilities/fonticon/)"
21+
" keys, such as `fa6s.arrow_down`",
1922
)
2023
light: Optional[str] = Field(
2124
None,
22-
description="Icon path when a light theme is used. These may be superqt "
23-
"fonticon keys, such as `fa6s.arrow_down`",
25+
description="Icon path when a light theme is used. These may be "
26+
"[iconify keys](https://icon-sets.iconify.design), such as "
27+
"`fa6-solid:arrow-down`, or "
28+
"[superqt.fonticon](https://pyapp-kit.github.io/superqt/utilities/fonticon/)"
29+
" keys, such as `fa6s.arrow_down`",
2430
)
2531

2632
@classmethod

src/app_model/types/_menu_rule.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ class SubmenuItem(_MenuItemBase):
9898
icon: Optional[Icon] = Field(
9999
None,
100100
description="(Optional) Icon used to represent this submenu. "
101-
"These may be superqt fonticon keys, such as `fa6s.arrow_down`",
101+
"These may be [iconify keys](https://icon-sets.iconify.design), "
102+
"such as `fa6-solid:arrow-down`, or "
103+
"[superqt.fonticon](https://pyapp-kit.github.io/superqt/utilities/fonticon/)"
104+
" keys, such as `fa6s.arrow_down`",
102105
)
103106
enablement: Optional[expressions.Expr] = Field(
104107
None,

tests/conftest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
UNDO_ICON = FA6S.rotate_left
1515
except ImportError:
16-
UNDO_ICON = "fa6s.undo"
16+
UNDO_ICON = "fa6-solid:undo"
1717

1818
FIXTURES = Path(__file__).parent / "fixtures"
1919

@@ -113,7 +113,7 @@ def build_app(name: str = "complete_test_app") -> FullApp:
113113
Action(
114114
id=Commands.COPY,
115115
title="Copy",
116-
icon="fa6s.copy",
116+
icon="fa6-solid:copy", # iconify font style works too
117117
callback=app.mocks.copy,
118118
menus=[{"id": Menus.EDIT, "group": "2_copy_paste"}],
119119
keybindings=[{"primary": KeyMod.CtrlCmd | KeyCode.KeyC}],
@@ -131,7 +131,7 @@ def build_app(name: str = "complete_test_app") -> FullApp:
131131
id=Commands.REDO,
132132
title="Redo",
133133
tooltip="Redo it!",
134-
icon="fa6s.rotate_right",
134+
icon="fa6-solid:rotate-right",
135135
enablement="allow_undo_redo",
136136
callback="fake_module:run_me", # this is a function in fixtures
137137
keybindings=[{"primary": "Ctrl+Shift+Z"}],

tests/test_qt/test_qactions.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
from app_model.types import Action, MenuItem, ToggleRule
66

77
if TYPE_CHECKING:
8-
pass
9-
108
from app_model import Application
119
from conftest import FullApp
1210

0 commit comments

Comments
 (0)