Skip to content

Commit f25e2b0

Browse files
authored
fix: gui extensions homescreen init (#281)
* fix: gui extensions homescreen init was passing an extra kwarg improve optional import handling and typing * docstr
1 parent f2a158d commit f25e2b0

File tree

1 file changed

+32
-13
lines changed
  • ovos_plugin_manager/templates

1 file changed

+32
-13
lines changed

ovos_plugin_manager/templates/gui.py

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
1+
from typing import Optional, Dict, Any
2+
13
from ovos_bus_client import Message
24
from ovos_bus_client import MessageBusClient
35
from ovos_bus_client.apis.gui import GUIInterface
4-
from ovos_utils.log import LOG
56
from ovos_config import Configuration
7+
from ovos_utils.log import LOG
8+
9+
try:
10+
from ovos_gui.homescreen import HomescreenManager
11+
except ImportError as _exc:
12+
13+
class HomescreenManager:
14+
"""Fallback class when ovos-gui is not installed.
15+
16+
Raises the original ImportError when instantiated to
17+
provide clear error messaging while still allowing type hints to work.
18+
"""
19+
20+
def __init__(self, *args, **kwargs):
21+
LOG.error("you seem to be running GUIExtensions without ovos-gui installed...")
22+
# raise the original ImportError
23+
raise _exc
624

725

826
class GUIExtension:
@@ -20,39 +38,40 @@ class GUIExtension:
2038
permanent (bool): disable unloading of GUI skills on gui client disconnections
2139
"""
2240

23-
def __init__(self, config, bus=None, gui=None,
24-
preload_gui=False, permanent=False):
41+
def __init__(self, config: Dict[str, Any],
42+
bus: Optional[MessageBusClient] = None,
43+
gui: Optional[GUIInterface] = None,
44+
preload_gui: bool = False,
45+
permanent: bool = False):
2546

2647
if not bus:
2748
bus = MessageBusClient()
2849
bus.run_in_thread()
2950
bus.connected_event.wait()
30-
self.bus = bus
31-
self.gui = gui or GUIInterface("ovos.shell", bus=self.bus,
32-
config=Configuration().get("gui", {}))
51+
self.bus: MessageBusClient = bus
52+
self.gui: GUIInterface = gui or GUIInterface("ovos.shell", bus=self.bus,
53+
config=Configuration().get("gui", {}))
3354
self.preload_gui = preload_gui
3455
self.permanent = permanent
3556
self.config = config
57+
self.homescreen_manager: Optional[HomescreenManager] = None
3658
self.register_bus_events()
3759

3860
def register_bus_events(self):
3961
self.bus.on("mycroft.gui.screen.close", self.handle_remove_namespace)
4062

41-
def bind_homescreen(self, homescreen=None):
63+
def bind_homescreen(self, homescreen: Optional[HomescreenManager] = None):
4264
if self.config.get("homescreen_supported", False):
4365
if not homescreen:
44-
# raise exception as usual if this fails
45-
from ovos_gui.homescreen import HomescreenManager
46-
homescreen = HomescreenManager(self.bus, self.gui)
66+
LOG.debug("Loading HomescreenManager")
67+
homescreen = HomescreenManager(self.bus)
4768
homescreen.daemon = True
4869
homescreen.start()
49-
5070
self.homescreen_manager = homescreen
5171
else:
5272
LOG.info("Homescreen support not configured")
5373

54-
def handle_remove_namespace(self, message):
55-
LOG.info("Got Clear Namespace Event In Skill")
74+
def handle_remove_namespace(self, message: Message):
5675
get_skill_namespace = message.data.get("skill_id", "")
5776
if get_skill_namespace:
5877
self.bus.emit(Message("gui.clear.namespace",

0 commit comments

Comments
 (0)