def test_handle_response__action__is_ran(self, renderer, controller): response = mock.Mock() response.event = KeywordQueryEvent(Query('test'), {}) renderer.active_event = response.event renderer.active_controller = controller renderer.handle_response(response, controller) response.action.run.assert_called_once_with()
def handle_query(self, query): """ Handles user query with a keyword from this extension :returns: :class:`BaseAction` object """ event = KeywordQueryEvent(query) return self.trigger_event(event)
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)
def get_departures(self, ev: KeywordQueryEvent, arg: str) -> BaseAction: items = [] stop = self.drt.stop(arg) items.append(self.make_departures_stop(stop, ev.get_query())) for departure in self.drt.departures(stop.id)[:5]: items.append(self.make_departures_departure(departure)) return RenderResultListAction(items)
def test_handle_response__keep_app_open_is_False__hide_is_called( self, renderer, controller, GLib, mocker): UlauncherWindow = mocker.patch( 'ulauncher.ui.windows.UlauncherWindow.UlauncherWindow') response = mock.Mock() response.event = KeywordQueryEvent(Query('test'), {}) response.action.keep_app_open.return_value = False renderer.active_event = response.event renderer.active_controller = controller renderer.handle_response(response, controller) GLib.idle_add.assert_called_with( UlauncherWindow.get_instance.return_value.hide_and_clear_input)
def handle_query(self, query): """ Handles user query with a keyword from this extension :returns: :class:`BaseAction` object """ # Normalize the query to the extension default keyword, not the custom user keyword for pref in self.preferences.get_items(): if pref['type'] == "keyword" and pref['value'] == query.keyword: query = Query( query.replace(pref['value'], pref['default_value'], 1)) event = KeywordQueryEvent(query) return self.trigger_event(event)
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)])
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)
def on_event(self, event: KeywordQueryEvent, extension: Extension): """ Handles the event """ query = event.get_argument() or "" return extension.get_projects(query)
def query(self, query: str): query = Query("ti " + query) query_event = KeywordQueryEvent(query) self.timer.trigger_event(query_event) results = self.client.response.action.result_list return [ResultItem(item, query, self) for item in results]
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)
def get_favorites(self, ev: KeywordQueryEvent) -> BaseAction: return RenderResultListAction([ self.make_favourite(stop, self.drt.departures(str(stop.id)), ev.get_query()) for stop in self.fav_get() ])