Esempio n. 1
0
 def on_event(self, ev: KeywordQueryEvent, ext: DRTExtension) -> BaseAction:
     try:
         if ev.get_query().endswith("`"):
             return SetUserQueryAction(ev.get_query().rstrip("`"))
         elif ev.get_argument() is None:
             return ext.get_favorites(ev)
         elif ev.get_argument().startswith("departures "):
             return ext.get_departures(
                 ev,
                 ev.get_argument().replace("departures ", "", 1))
         else:
             return ext.get_stops(ev, ev.get_argument())
     except DRTApiException as ex:
         return RenderResultListAction([self.make_error(ex)])
     except RequestException as ex:
         return RenderResultListAction([self.make_error(ex)])
Esempio n. 2
0
 def on_event(self, event: KeywordQueryEvent, extension):
     arg: str = event.get_argument()
     if arg:
         return RenderResultListAction([
             self.__result_items[self.__entries.aliases.index(aliases)]
             for aliases in self.__entries.aliases
             if any(arg in s for s in aliases)
         ])
     else:
         return RenderResultListAction(self.__result_items)
Esempio n. 3
0
    def on_event(self, event: KeywordQueryEvent,
                 extension: Extension) -> RenderResultListAction:
        """Handle the user calling the extension via ulauncher.

        Args:
            event (KeywordQueryEvent): The KeywordQueryEvent generated by the user (docs.ulauncher.io/en/latest/extensions/events.html?highlight=KeywordQueryEvent).
            extension (Extension): The Extension.

        Returns:
            RenderResultListAction: Results ready to be displayed by ulauncher.
        """

        word = event.get_argument()
        logger.info(f"word={word}")

        if not RAE.need_online_check(word):
            logger.info(f"{word=} doesn't need online check.")
            items = extension.handle_offline(word)
        else:
            logger.info(f"{word=} needs online check.")
            items = extension.handle_online(word)

        return RenderResultListAction(items)
Esempio n. 4
0
    def on_event(self, event: KeywordQueryEvent, extension: Extension):
        """ Handles the event """
        query = event.get_argument() or ""

        return extension.get_projects(query)
Esempio n. 5
0
 def get_stops(self, ev: KeywordQueryEvent, arg: str) -> BaseAction:
     items = []
     for stop in self.drt.stops(ev.get_argument())[:5]:
         items.append(self.make_stop(stop, ev.get_query()))
     return RenderResultListAction(items)