Ejemplo n.º 1
0
    def on_query(self, query):
        if query == '~':
            return ActionList((SetUserQueryAction('~/'), ))

        path = Path(query)

        try:
            existing_dir = path.get_existing_dir()
            if existing_dir == str(path):
                results = self.list_files(str(path), sort_by_usage=True)
                result_items = map(
                    self.create_result_item,
                    map(lambda name: os.path.join(existing_dir, name),
                        self.filter_dot_files(results)[:self.RESULT_LIMIT]))
            else:
                results = self.list_files(existing_dir)
                search_for = path.get_search_part()
                if not search_for.startswith('.'):
                    # don't show dot files in the results
                    results = map(
                        lambda name: os.path.join(existing_dir, name),
                        self.filter_dot_files(results))
                else:
                    results = map(
                        lambda name: os.path.join(existing_dir, name), results)

                result_items = SortedResultList(search_for,
                                                min_score=40,
                                                limit=self.RESULT_LIMIT)
                result_items.extend(
                    map(self.create_result_item, reversed(results)))
        except (InvalidPathError, OSError):
            return ActionList((RenderResultListAction([]), ))

        return ActionList((RenderResultListAction(result_items), ))
Ejemplo n.º 2
0
 def on_enter(self, query):
     self._file_queries.put(str(self.path))
     if self.path.is_dir():
         return ActionList([
             SetUserQueryAction(os.path.join(self.path.get_user_path(), ''))
         ])
     else:
         return ActionList([OpenAction(str(self.path))])
Ejemplo n.º 3
0
    def test_run_all(self):
        l = ActionList((self.create_action(False), self.create_action(True),
                        self.create_action(False)))
        l.run_all()

        l[0].run.assert_called_with()
        l[1].run.assert_called_with()
        l[2].run.assert_called_with()
Ejemplo n.º 4
0
 def test_keep_app_open(self):
     l = ActionList((self.create_action(False), self.create_action(True),
                     self.create_action(False)))
     assert l.keep_app_open()
     l = ActionList((self.create_action(False), self.create_action(False)))
     assert not l.keep_app_open()
     l = ActionList()
     assert l.keep_app_open()
Ejemplo n.º 5
0
 def on_query(self, query):
     error_msg = 'Invalid expression'
     try:
         result = eval_expr(query)
         if not result:
             raise ValueError(error_msg)
         result_item = CalcResultItem(result=eval_expr(query))
     except Exception as e:
         result_item = CalcResultItem(error=e.message or error_msg)
     return ActionList((RenderResultListAction([result_item]),))
Ejemplo n.º 6
0
    def on_query(self, query):
        custom_items = [GoogleResultItem(), WikipediaResultItem(), StackoverflowResultItem()]
        default_items = custom_items[:2]
        action_item = next((i for i in custom_items if query.startswith('%s ' % i.get_keyword())), None)

        if action_item:
            result_list = (action_item,)
        else:
            result_list = AppDb.get_instance().find(query)

            # add web search items
            result_list.extend(custom_items)

            if not len(result_list) and query:
                # default search
                map(lambda i: i.set_default_search(True), custom_items)
                result_list = default_items

        return ActionList((RenderResultListAction(result_list),))
Ejemplo n.º 7
0
    def on_enter(self, query):
        action_list = ActionList()
        if query.get_keyword() == self.keyword and query.get_argument():
            argument = query.get_argument()
        elif self.is_default_search:
            argument = query
        else:
            argument = None

        if argument:
            action_list.append(OpenUrlAction(self.url % argument))
        else:
            action_list.append(SetUserQueryAction('%s ' % self.keyword))

        return action_list
Ejemplo n.º 8
0
 def on_enter(self, query):
     return ActionList([OpenAction(str(self.path))])
Ejemplo n.º 9
0
 def on_enter(self, query):
     self._app_queries.put(query, self.record.get('name'))
     self._app_queries.commit()
     return ActionList((LaunchAppAction(self.record.get('desktop_file')), ))
Ejemplo n.º 10
0
 def on_alt_enter(self, query):
     menu_items = self._get_dir_alt_menu() if self.path.is_dir(
     ) else self._get_file_alt_menu()
     return ActionList((RenderResultListAction(menu_items), ))
Ejemplo n.º 11
0
 def on_enter(self, query):
     return ActionList([CopyToClipboardAction(str(self.path))])