Пример #1
0
    def handle_query(self, query: str) -> BaseAction:
        if query == '~':
            return SetUserQueryAction('~/')

        path = Path(query)  # type: Path
        result_items = []  # type: Union[List, SortedList]

        try:
            existing_dir = path.get_existing_dir()

            if existing_dir == path.get_abs_path():
                file_names = self.list_files(path.get_abs_path(), sort_by_usage=True)
                for name in self.filter_dot_files(file_names)[:self.RESULT_LIMIT]:
                    file = os.path.join(existing_dir, name)
                    result_items.append(self.create_result_item(file))

            else:
                file_names = self.list_files(existing_dir)
                search_for = path.get_search_part()

                if not search_for.startswith('.'):
                    file_names = self.filter_dot_files(file_names)

                files = [os.path.join(existing_dir, name) for name in file_names]
                result_items = SortedList(search_for, min_score=40, limit=self.RESULT_LIMIT)
                result_items.extend([self.create_result_item(name) for name in reversed(files)])

        except (InvalidPathError, OSError):
            result_items = []

        return RenderResultListAction(result_items)
Пример #2
0
 def on_event(self, event, extension):
     items = []
     arg = event.get_argument()
     if arg:
         result_list = SortedList(arg, min_score=40, limit=10)
         result_list.extend(extension.character_list)
         for char in result_list:
             image_path = get_character_icon(char)
             items.append(
                 ExtensionResultItem(
                     icon=image_path,
                     name=char.name + " - " + char.character,
                     description=char.block + " - " + char.code,
                     on_enter=CopyToClipboardAction(char.character),
                 ))
     return RenderResultListAction(items)
Пример #3
0
    def render_results(self, query):
        items = SortedList(query, min_score=0, limit=9)
        try:
            for buddy in pidgin.getBuddies():
                items.append(
                    ExtensionSmallResultItem(
                        icon='images/icon.png',
                        name='%s' % buddy.alias,
                        description='Account desc: %s' % buddy.name,
                        on_enter=ExtensionCustomAction(buddy)))
            res = []
            for i in items:
                res.append(i)

            return RenderResultListAction(res)
        except dbus.exceptions.DBusException:
            return self._pidgin_not_launched()
Пример #4
0
    def find(self, query, result_list=None):
        """
        :param str query: query to search for
        :param ResultList result_list:
        :rtype: :class:`ResultList`
        """

        result_list = result_list or SortedList(query, min_score=50, limit=9)

        if not query:
            return result_list

        for rec in self.get_records():
            result_list.append(AppResultItem(rec))

        return result_list
Пример #5
0
 def res_list(self):
     return SortedList('bro', min_score=40, limit=3)