diff --git a/ovos_gui/bus.py b/ovos_gui/bus.py index 0c82233..de38995 100644 --- a/ovos_gui/bus.py +++ b/ovos_gui/bus.py @@ -131,13 +131,9 @@ def get_client_pages(self, namespace): @return: list of page URIs for this GUI Client """ client_pages = [] - server_url = self.ns_manager.gui_file_server.url if \ - self.ns_manager.gui_file_server else \ - self.ns_manager.gui_file_host_path for page in namespace.pages: - uri = page.get_uri(self.framework, server_url) + uri = page.get_uri(self.framework) client_pages.append(uri) - return client_pages def synchronize(self): @@ -260,16 +256,13 @@ def send_gui_pages(self, pages: List[GuiPage], namespace: str, @param namespace: namespace to put GuiPages in @param position: position to insert pages at """ - server_url = self.ns_manager.gui_file_server.url if \ - self.ns_manager.gui_file_server else \ - self.ns_manager.gui_file_host_path framework = self.framework message = { "type": "mycroft.gui.list.insert", "namespace": namespace, "position": position, - "data": [{"url": page.get_uri(framework, server_url)} + "data": [{"url": page.get_uri(framework)} for page in pages] } LOG.debug(f"Showing pages: {message['data']}") diff --git a/ovos_gui/namespace.py b/ovos_gui/namespace.py index 47fd625..26f5470 100644 --- a/ovos_gui/namespace.py +++ b/ovos_gui/namespace.py @@ -71,9 +71,9 @@ def _validate_page_message(message: Message) -> bool: @returns: True if request is valid, else False """ valid = ( - "page" in message.data + "page_names" in message.data and "__from" in message.data - and isinstance(message.data["page"], list) + and isinstance(message.data["page_names"], list) ) if not valid: if message.msg_type == "gui.page.show": @@ -295,7 +295,7 @@ def load_pages(self, pages: List[GuiPage], show_index: int = 0): target_page = pages[show_index] for page in pages: - if page.id not in [p.id for p in self.pages]: + if page.name not in [p.name for p in self.pages]: new_pages.append(page) self.pages.extend(new_pages) @@ -334,7 +334,7 @@ def focus_page(self, page): # set the index of the page in the self.pages list page_index = None for i, p in enumerate(self.pages): - if p.id == page.id: + if p.name == page.name: # save page index page_index = i break @@ -535,8 +535,7 @@ def handle_delete_page(self, message: Message): message_is_valid = _validate_page_message(message) if message_is_valid: namespace_name = message.data["__from"] - pages_to_remove = message.data.get("page_names") or \ - message.data.get("page") # backwards compat + pages_to_remove = message.data.get("page_names") LOG.debug(f"Got {namespace_name} request to delete: {pages_to_remove}") with namespace_lock: self._remove_pages(namespace_name, pages_to_remove) @@ -579,24 +578,6 @@ def _parse_persistence(persistence: Optional[Union[int, bool]]) -> \ # Defines default behavior as displaying for 30 seconds return False, 30 - def _legacy_show_page(self, message: Message) -> List[GuiPage]: - """ - Backwards-compat method to handle messages without ui_directories and - page_names. - @param message: message requesting to display pages - @return: list of GuiPage objects - """ - pages_to_show = message.data["page"] - LOG.info(f"Handling legacy page show request. pages={pages_to_show}") - - pages_to_load = list() - persist, duration = self._parse_persistence(message.data["__idle"]) - for page in pages_to_show: - name = page.split('/')[-1] - # check if persistence is type of int or bool - pages_to_load.append(GuiPage(page, name, persist, duration)) - return pages_to_load - def handle_show_page(self, message: Message): """ Handles a request to show one or more pages on the screen. @@ -609,39 +590,19 @@ def handle_show_page(self, message: Message): namespace_name = message.data["__from"] page_ids_to_show = message.data.get('page_names') - page_resource_dirs = message.data.get('ui_directories') persistence = message.data["__idle"] - show_index = message.data.get("index", None) + show_index = message.data.get("index", 0) LOG.debug(f"Got {namespace_name} request to show: {page_ids_to_show} at index: {show_index}") - if not page_resource_dirs and page_ids_to_show and \ - all((x.startswith("SYSTEM") for x in page_ids_to_show)): - page_resource_dirs = {"all": self._system_res_dir} - - if not all((page_ids_to_show, page_resource_dirs)): - LOG.warning(f"GUI resources have not yet been uploaded for namespace: {namespace_name}") - pages = self._legacy_show_page(message) - else: - pages = list() - persist, duration = self._parse_persistence(message.data["__idle"]) - for page in page_ids_to_show: - url = None - name = page - if isfile(page): - LOG.warning(f"Expected resource name but got file: {url}") - name = page.split('/')[-1] - url = f"file://{page}" - elif "://" in page: - LOG.warning(f"Expected resource name but got URI: {page}") - name = page.split('/')[-1] - url = page - pages.append(GuiPage(url, name, persist, duration, - page, namespace_name, page_resource_dirs)) + pages = list() + persist, duration = self._parse_persistence(message.data["__idle"]) + for page in page_ids_to_show: + pages.append(GuiPage(name=page, persistent=persist, duration=duration, + namespace=namespace_name)) if not pages: - LOG.error(f"Activated namespace '{namespace_name}' has no pages! " - f"Did you provide 'ui_directories' ?") + LOG.error(f"Activated namespace '{namespace_name}' has no pages!") LOG.error(f"Can't show page, bad message: {message.data}") return diff --git a/ovos_gui/page.py b/ovos_gui/page.py index 2121d86..5085aec 100644 --- a/ovos_gui/page.py +++ b/ovos_gui/page.py @@ -11,29 +11,17 @@ class GuiPage: A GuiPage represents a single GUI Display within a given namespace. A Page can either be `persistent` or be removed after some `duration`. Note that a page is generally framework-independent - @param url: URI (local or network path) of the GUI Page @param name: Name of the page as shown in its namespace (could @param persistent: If True, page is displayed indefinitely @param duration: Number of seconds to display the page for @param namespace: Skill/component identifier - @param page_id: Page identifier - (file path relative to gui_framework directory with no extension) """ - url: Optional[str] # This param is left for backwards-compat. name: str persistent: bool duration: Union[int, bool] - page_id: Optional[str] = None namespace: Optional[str] = None resource_dirs: Optional[dict] = None - @property - def id(self): - """ - Get a unique identifier for this page. - """ - return self.page_id or self.url - @staticmethod def get_file_extension(framework: str) -> str: """ @@ -47,7 +35,7 @@ def get_file_extension(framework: str) -> str: @property def res_namespace(self): - return "system" if self.page_id.startswith("SYSTEM") else self.namespace + return "system" if self.name.startswith("SYSTEM") else self.namespace def get_uri(self, framework: str = "qt5") -> str: """ @@ -55,11 +43,7 @@ def get_uri(self, framework: str = "qt5") -> str: @param framework: String GUI framework to get resources for (currently only 'qt5') @return: Absolute path to the requested resource """ - if self.url: - LOG.warning(f"Static URI: {self.url}") - return self.url - - res_filename = f"{self.page_id}.{self.get_file_extension(framework)}" + res_filename = f"{self.name}.{self.get_file_extension(framework)}" path = f"{GUI_CACHE_PATH}/{self.res_namespace}/{framework}/{res_filename}" LOG.debug(f"Resolved page URI: {path}") if isfile(path):