예제 #1
0
    def enter(self, query, index=None, alt=False):
        """
        Enter into selected item, unless 'index' is passed
        Return boolean - True if Ulauncher window should be closed
        """
        if index is not None:
            if not 0 <= index < len(self.result_widgets):
                raise IndexError

            self.select(index)
            return self.enter(query)

        if self.selected is not None:
            result = self.result_widgets[self.selected].result
            if not alt and result.searchable:
                query_history.save_query(str(query), result.get_name())

            action = result.on_enter(
                query) if not alt else result.on_alt_enter(query)
            if not action:
                return True
            if isinstance(action, list):
                action = RenderResultListAction(action)
            action.run()
            return not action.keep_app_open()

        return None
예제 #2
0
    def handle_response(self, response, controller):
        """
        Calls :func:`response.action.run`
        """
        if self.active_controller != controller or self.active_event != response.event:
            return

        self._cancel_loading()
        action = response.action
        if isinstance(action, list):
            action = RenderResultListAction(action)
        action.run()
        if not action.keep_app_open:
            self._hide_window()
예제 #3
0
    def on_query_change(self, query):
        """
        Iterate over all search modes and run first enabled.
        """
        for mode in self.modes:
            mode.on_query_change(query)

        mode = self.get_mode_from_query(query)
        if mode:
            action = mode.handle_query(query)
            if not isinstance(action, BaseAction):
                action = RenderResultListAction(action)
            action.run()
        else:
            # No mode selected, which means search
            results = self.search(query)
            # If the search result is empty, add the default items for all other modes (only shortcuts currently)
            if not results and query:
                for mode in self.modes:
                    results.extend(mode.get_fallback_results())
            RenderResultListAction(results).run()