예제 #1
0
 def send(self, msg_dict):
     """ Send to all registered GUIs. """
     for connection in GUIWebsocketHandler.clients:
         try:
             connection.send(msg_dict)
         except Exception as e:
             LOG.exception(repr(e))
예제 #2
0
 def on_gui_show_page(self, message):
     try:
         page, namespace, index = _get_page_data(message)
         # Pass the request to the GUI(s) to pull up a page template
         with namespace_lock:
             self.show(namespace, page, index)
     except Exception as e:
         LOG.exception(repr(e))
예제 #3
0
 def on_gui_delete_namespace(self, message):
     """ Bus handler for removing namespace. """
     try:
         namespace = message.data['__from']
         with namespace_lock:
             self.remove_namespace(namespace)
     except Exception as e:
         LOG.exception(repr(e))
예제 #4
0
 def on_gui_delete_page(self, message):
     """ Bus handler for removing pages. """
     page, namespace, _ = _get_page_data(message)
     try:
         with namespace_lock:
             self.remove_pages(namespace, page)
     except Exception as e:
         LOG.exception(repr(e))
예제 #5
0
    def on_gui_set_value(self, message):
        data = message.data
        namespace = data.get("__from", "")

        # Pass these values on to the GUI renderers
        for key in data:
            if key not in RESERVED_KEYS:
                try:
                    self.set(namespace, key, data[key])
                except Exception as e:
                    LOG.exception(repr(e))
예제 #6
0
    def __switch_page(self, namespace, pages):
        """ Switch page to an already loaded page.

        Args:
            pages (list): pages (str) to switch to
            namespace (str):  skill namespace
        """
        try:
            num = self.loaded[0].pages.index(pages[0])
        except Exception as e:
            LOG.exception(repr(e))
            num = 0

        LOG.debug('Switching to already loaded page at '
                  'index {} in namespace {}'.format(num, namespace))
        self.send({"type": "mycroft.events.triggered",
                   "namespace": namespace,
                   "event_name": "page_gained_focus",
                   "data": {"number": num}})
예제 #7
0
    def remove_pages(self, namespace, pages):
        """ Remove the listed pages from the provided namespace.

        Args:
            namespace (str):    The namespace to modify
            pages (list):       List of page names (str) to delete
        """
        try:
            index = self.__find_namespace(namespace)
            if index is None:
                return
            else:
                # Remove any pages that doesn't exist in the namespace
                pages = [p for p in pages if p in self.loaded[index].pages]
                # Make sure to remove pages from the back
                indexes = [self.loaded[index].pages.index(p) for p in pages]
                indexes = sorted(indexes)
                indexes.reverse()
                for page_index in indexes:
                    self.__remove_page(namespace, page_index)
        except Exception as e:
            LOG.exception(repr(e))
예제 #8
0
    def show(self, namespace, page, index):
        """ Show a page and load it as needed.

        Args:
            page (str or list): page(s) to show
            namespace (str):  skill namespace
            index (int): ??? TODO: Unused in code ???

        TODO: - Update sync to match.
              - Separate into multiple functions/methods
        """

        LOG.debug("GUIConnection activating: " + namespace)
        pages = page if isinstance(page, list) else [page]

        # find namespace among loaded namespaces
        try:
            index = self.__find_namespace(namespace)
            if index is None:
                # This namespace doesn't exist, insert them first so they're
                # shown.
                self.__insert_new_namespace(namespace, pages)
                return
            else:  # Namespace exists
                if index > 0:
                    # Namespace is inactive, activate it by moving it to
                    # position 0
                    self.__move_namespace(index, 0)

                # Find if any new pages needs to be inserted
                new_pages = [p for p in pages if p not in self.loaded[0].pages]
                if new_pages:
                    self.__insert_pages(namespace, new_pages)
                else:
                    # No new pages, just switch
                    self.__switch_page(namespace, pages)
        except Exception as e:
            LOG.exception(repr(e))