Skip to content

Commit e07ec21

Browse files
committed
Use AssetManager to manage icons
One of the new features of StreamController is the `AssetManager` component, which allows users to override icons and other assets used by the plugin in its settings UI. Among other things, this allows users to configure state-dependent icons from plugins instead of overriding the icon per-button. This patch implements `AssetManager`-managed icons so users can configure them as they wish.
1 parent a363c2a commit e07ec21

15 files changed

Lines changed: 97 additions & 57 deletions

actions/Interact.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77

88

99
class Interact(TimerSourceActionCore):
10+
icon_keys = ["interact"]
11+
1012
def __init__(self, *args, **kwargs):
1113
super().__init__(*args, **kwargs)
1214

1315
def get_icon_name(self) -> str:
14-
return "interact.png"
16+
return "interact"
1517

1618
def create_event_assigners(self):
1719
self.add_event_assigner(

actions/NextComparison.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44

55

66
class NextComparison(OBSLiveSplitOneCore):
7+
icon_keys = ["next-comparison"]
8+
79
def __init__(self, *args, **kwargs):
810
super().__init__(*args, **kwargs)
911

1012
def get_icon_name(self) -> str:
11-
return "next-comparison.png"
13+
return "next-comparison"
1214

1315
def create_event_assigners(self):
1416
self.add_event_assigner(

actions/OBSLiveSplitOneCore.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111

1212
class OBSLiveSplitOneCore(ActionCore):
13+
icon_keys = []
14+
1315
def __init__(self, *args, **kwargs):
1416
super().__init__(*args, **kwargs)
1517

@@ -23,18 +25,36 @@ def __init__(self, *args, **kwargs):
2325
if not self.plugin_base.backend.get_connected():
2426
self.reconnect_obs()
2527

28+
self.current_icon = None
29+
30+
self.plugin_base.asset_manager.icons.add_listener(self.on_icon_changed)
31+
2632
self.create_event_assigners()
2733

2834
def create_event_assigners(self):
2935
pass
3036

3137
def on_ready(self):
32-
self.set_media(
33-
media_path=self.get_asset_path(self.get_icon_name())
34-
)
38+
self.display_icon()
3539

3640
def get_icon_name(self) -> str:
37-
return "livesplit.png"
41+
return "livesplit"
42+
43+
def _effective_icon_name(self):
44+
if self.icon_keys:
45+
return self.current_icon or self.icon_keys[0]
46+
return "livesplit"
47+
48+
def display_icon(self):
49+
icon_name = self._effective_icon_name()
50+
icon_asset = self.get_icon(icon_name)
51+
if icon_asset:
52+
_, rendered = icon_asset.get_values()
53+
self.set_media(image=rendered)
54+
55+
def on_icon_changed(self, event, key, asset):
56+
if key == self._effective_icon_name():
57+
self.display_icon()
3858

3959
def get_config_rows(self) -> list:
4060
self.websocket_settings = Adw.PreferencesGroup()

actions/Pause.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44

55

66
class Pause(OBSLiveSplitOneCore):
7+
icon_keys = ["pause"]
8+
79
def __init__(self, *args, **kwargs):
810
super().__init__(*args, **kwargs)
911

1012
def get_icon_name(self) -> str:
11-
return "pause.png"
13+
return "pause"
1214

1315
def create_event_assigners(self):
1416
self.add_event_assigner(

actions/PrevComparison.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44

55

66
class PrevComparison(OBSLiveSplitOneCore):
7+
icon_keys = ["prev-comparison"]
8+
79
def __init__(self, *args, **kwargs):
810
super().__init__(*args, **kwargs)
911

1012
def get_icon_name(self) -> str:
11-
return "prev-comparison.png"
13+
return "prev-comparison"
1214

1315
def create_event_assigners(self):
1416
self.add_event_assigner(

actions/Reset.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44

55

66
class Reset(OBSLiveSplitOneCore):
7+
icon_keys = ["reset"]
8+
79
def __init__(self, *args, **kwargs):
810
super().__init__(*args, **kwargs)
911

1012
def get_icon_name(self) -> str:
11-
return "reset.png"
13+
return "reset"
1214

1315
def create_event_assigners(self):
1416
self.add_event_assigner(

actions/SaveSplits.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77

88

99
class SaveSplits(TimerSourceActionCore):
10+
icon_keys = ["save-splits"]
11+
1012
def __init__(self, *args, **kwargs):
1113
super().__init__(*args, **kwargs)
1214

1315
def get_icon_name(self) -> str:
14-
return "save-splits.png"
16+
return "save-splits"
1517

1618
def create_event_assigners(self):
1719
self.add_event_assigner(

actions/SetLayoutPath.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212

1313

1414
class SetLayoutPath(TimerSourceActionCore):
15+
icon_keys = ["set-layout-path"]
16+
1517
def __init__(self, *args, **kwargs):
1618
super().__init__(*args, **kwargs)
1719

1820
def get_icon_name(self) -> str:
19-
return "set-layout-path.png"
21+
return "set-layout-path"
2022

2123
def get_config_rows(self) -> list:
2224
self.layout_path_settings = Adw.PreferencesGroup()

actions/SetSplitsPath.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212

1313

1414
class SetSplitsPath(TimerSourceActionCore):
15+
icon_keys = ["set-splits-path"]
16+
1517
def __init__(self, *args, **kwargs):
1618
super().__init__(*args, **kwargs)
1719

1820
def get_icon_name(self) -> str:
19-
return "set-splits-path.png"
21+
return "set-splits-path"
2022

2123
def get_config_rows(self) -> list:
2224
self.splits_path_settings = Adw.PreferencesGroup()

actions/Skip.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44

55

66
class Skip(OBSLiveSplitOneCore):
7+
icon_keys = ["skip"]
8+
79
def __init__(self, *args, **kwargs):
810
super().__init__(*args, **kwargs)
911

1012
def get_icon_name(self) -> str:
11-
return "skip.png"
13+
return "skip"
1214

1315
def create_event_assigners(self):
1416
self.add_event_assigner(

0 commit comments

Comments
 (0)