Ejemplo n.º 1
0
    def on_event(self, event, extension):
        """ Handle query event """
        items = []

        try:
            extension.netlify_client.set_access_token(
                extension.preferences['access_token'])
            sites = extension.netlify_client.get_sites(event.get_argument())

            items = extension.build_results_list(sites)

        except AuthenticationException:
            items.append(
                ExtensionResultItem(
                    icon='images/icon.png',
                    name="Authentication failed",
                    description=
                    "Please check the 'access_token' value on extension preferences",
                    on_enter=HideWindowAction()))
        except GenericException:
            items.append(
                ExtensionResultItem(
                    icon='images/icon.png',
                    name="Error fetching information from Heroku",
                    on_enter=HideWindowAction()))
        return RenderResultListAction(items)
Ejemplo n.º 2
0
    def on_event(self, event, extension):
        query = event.get_argument() or str()

        if len(query.strip()) == 0:
            return RenderResultListAction([
                ExtensionResultItem(icon=icon_file,
                                    name='No input',
                                    on_enter=HideWindowAction())
            ])

        result_dict = YoutubeSearch.perform_search(query)
        logger.debug('Obtained result' + str(result_dict))

        if not result_dict:
            return RenderResultListAction([
                ExtensionResultItem(icon=icon_file,
                                    name='No results',
                                    on_enter=HideWindowAction())
            ])

        return RenderResultListAction([
            ExtensionResultItem(icon=icon_file,
                                name=title,
                                description='',
                                on_enter=OpenUrlAction("https://youtube.com" +
                                                       url))
            for title, url in result_dict.items()
        ])
Ejemplo n.º 3
0
    def on_event(self, event, extension):
        query = event.get_argument() or str()

        if len(query.strip()) == 0:
            return RenderResultListAction([
                ExtensionResultItem(icon='images/gt-icon.png',
                                    name='No input',
                                    on_enter=HideWindowAction())
            ])

        try:
            translations = list(TranslateShellParser(query).execute())
        except OSError:
            return RenderResultListAction([
                ExtensionResultItem(
                    icon='images/gt-icon.png',
                    name='Looks like you have no translate-shell installed',
                    description="Select to open repo",
                    on_enter=OpenUrlAction(
                        'https://github.com/soimort/translate-shell'))
            ])

        items = [
            ExtensionResultItem(icon='images/gt-icon.png',
                                name=translation.translation,
                                description=translation.part_of_speech +
                                ', '.join(translation.synonyms),
                                on_enter=HideWindowAction())
            for translation in translations
        ]

        return RenderResultListAction(items)
Ejemplo n.º 4
0
    def on_event(self, event, extension):
        """ Handles Keyword Event """
        items = []

        try:

            query = event.get_argument() or ""

            if len(query) < 3:
                return RenderResultListAction([
                    ExtensionResultItem(
                        icon='images/icon.png',
                        name="Keep Typing to search on cdn.js ...",
                        on_enter=HideWindowAction(),
                        highlightable=False,
                    )
                ])

            max_results = int(extension.preferences['max_results'])
            payload = {
                'search': query,
                'fields': 'version,description,repository'.encode('utf-8')
            }

            headers = {
                'Content-Type': 'application/json',
                'User-Agent': 'Ulauncher-cdnjs/2.0'
            }

            req = requests.get(CDN_URL, params=payload, headers=headers)
            req.raise_for_status()

            libraries = req.json()

            for library in libraries['results'][0:max_results]:
                repo_url = library['repository']['url'].replace(
                    'git://', 'https://').replace('git+', '')
                items.append(
                    ExtensionResultItem(
                        icon='images/icon.png',
                        name=library['name'] + " (" + library['version'] + ")",
                        description=library['description'],
                        on_enter=CopyToClipboardAction(library['latest']),
                        on_alt_enter=OpenUrlAction(repo_url)))

            return RenderResultListAction(items)

        except requests.exceptions.HTTPError as err:
            LOGGER.error(err)
            items.append(
                ExtensionResultItem(
                    icon='images/icon.png',
                    name="Error requesting CDNjs",
                    description="Request error: " + str(req.status_code),
                    on_enter=HideWindowAction(),
                    highlightable=False,
                ))

            return RenderResultListAction(items)
Ejemplo n.º 5
0
    def on_event(self, event, extension):
        data = event.get_data()
        type = data.get("type")

        if type == "select":
            extension.snippet = data.get("snippet")
            extension.state = "var"
        elif type == "cancel":
            extension.reset()
            return SetUserQueryAction("")

        next_variable = extension.snippet.next_variable()
        if extension.state == "var" and next_variable:
            keyword = extension.preferences["snippets_keyword"]
            extension.variable = next_variable
            return ActionList([
                SetUserQueryAction(keyword + " "),
                RenderResultListAction(
                    show_var_input(extension.snippet, next_variable,
                                   next_variable.get("default", "")))
            ])

        try:
            copy_mode = extension.preferences["snippets_copy_mode"]
            if extension.snippet.file_path_template:
                try:
                    file_path = extension.snippet.render_to_file_path(
                        copy_mode=copy_mode)
                    self._notify(extension,
                                 file_path,
                                 title="Snippet written to file")
                except FileExistsError as e:
                    self._notify(extension,
                                 e.args[0],
                                 title="File already exists")
                return HideWindowAction()
            else:
                (mimetype,
                 snippet) = extension.snippet.render(copy_mode=copy_mode)

                action = None
                if copy_mode == "xsel":
                    copy_to_clipboard_xsel(snippet, mimetype)
                    action = HideWindowAction()
                elif copy_mode == "wl":
                    copy_to_clipboard_wl(snippet, mimetype)
                    action = HideWindowAction()
                else:
                    action = CopyToClipboardAction(snippet)

                self._notify(extension, snippet, mimetype)
                return action
        except Exception as e:
            logger.exception(e)
            return RenderResultListAction(
                [ExtensionResultItem(name=str(e), on_enter=DoNothingAction())])
        finally:
            extension.reset()
Ejemplo n.º 6
0
    def on_event(self, event, extension):
        """ Handles the event """

        arg = event.get_argument() or ""

        args_array = arg.split(">")
        if len(args_array) != 2:
            return extension.show_available_docs(event, arg)

        try:

            docset = args_array[0].strip()

            search_term = args_array[1]

            if len(search_term.strip()) < 3:
                return RenderResultListAction([
                    ExtensionResultItem(
                        icon='images/icon.png',
                        name='Please type a minimum of 3 characters',
                        description='Searching ...',
                        on_enter=HideWindowAction())
                ])

            result = extension.searcher.search(docset, search_term)

            items = []

            if not result:
                return RenderResultListAction([
                    ExtensionResultItem(
                        icon='images/icon.png',
                        name='No results matching your criteria',
                        on_enter=HideWindowAction())
                ])

            for i in result[:8]:
                items.append(
                    ExtensionResultItem(icon=i['icon'],
                                        name=i['title'],
                                        description=i['category'],
                                        highlightable=False,
                                        on_enter=OpenUrlAction(i['url'])))

            return RenderResultListAction(items)

        except Exception as err:
            LOGGING.error(err)
            return RenderResultListAction([
                ExtensionResultItem(
                    icon="images/icon.png",
                    name='An error ocurred when searching documentation',
                    description='err',
                    on_enter=HideWindowAction())
            ])
Ejemplo n.º 7
0
    def on_event(self, event, extension):
        """ Handles the event """
        fd_cmd = extension.preferences["fd_cmd"]
        if shutil.which(fd_cmd) is None:
            return RenderResultListAction([
                ExtensionResultItem(
                    icon="images/icon.png",
                    name=
                    f"Command {fd_cmd} is not found, please install it first",
                    on_enter=HideWindowAction())
            ])

        query = event.get_argument()

        if not query or len(query) < 3:
            return RenderResultListAction([
                ExtensionResultItem(
                    icon="images/icon.png",
                    name="Keep typing your search criteria ...",
                    on_enter=DoNothingAction())
            ])

        keyword = event.get_keyword()
        keyword_id = None
        # Find the keyword id using the keyword (since the keyword can be changed by users)
        for kw_id, kw in list(extension.preferences.items()):
            if kw == keyword:
                keyword_id = kw_id

        file_type = FILE_SEARCH_ALL
        if keyword_id == "ff_kw":
            file_type = FILE_SEARCH_FILE
        elif keyword_id == "fd_kw":
            file_type = FILE_SEARCH_DIRECTORY

        results = extension.search(query.strip(), file_type, fd_cmd)

        if not results:
            return RenderResultListAction([
                ExtensionResultItem(icon="images/icon.png",
                                    name=f"No Results found matching {query}",
                                    on_enter=HideWindowAction())
            ])

        items = []
        for result in results[:15]:
            items.append(
                ExtensionSmallResultItem(
                    icon=result["icon"],
                    name=result["path"].decode("utf-8"),
                    on_enter=OpenAction(result["path"].decode("utf-8")),
                    on_alt_enter=extension.get_open_in_terminal_script(
                        result["path"].decode("utf-8"))))

        return RenderResultListAction(items)
Ejemplo n.º 8
0
    def on_event(self, event, extension):
        keyword = event.get_keyword()
        argument = event.get_argument()

        if not isinstance(event.get_argument(), str):
            return RenderResultListAction([
                ExtensionResultItem(icon='images/jira.svg',
                                    name='Search for an issue summary',
                                    highlightable=False,
                                    on_enter=SetUserQueryAction(
                                        "%s %s " % (keyword, 'sm'))),
                ExtensionResultItem(
                    icon='images/jira.svg',
                    name='Try to search for a specific issue. Ex: PROJECT-123',
                    highlightable=False,
                    on_enter=HideWindowAction())
            ])

        try:

            summary_query = argument.startswith("sm ")
            summary_query_arg_length = len(argument.split('sm '))

            if summary_query and summary_query_arg_length > 1:
                issues = extension.jira.search_issues(
                    'summary~"' + argument.split('sm ')[1] + '"')
                return self.render_results(issues)
            elif summary_query:
                return RenderResultListAction([
                    ExtensionResultItem(icon='images/jira.svg',
                                        name='No input',
                                        highlightable=False,
                                        on_enter=HideWindowAction())
                ])

            project_and_key = event.get_argument().split('-')

            if len(project_and_key) <= 1:
                return RenderResultListAction([
                    ExtensionResultItem(icon='images/jira.svg',
                                        name='Input not complete',
                                        highlightable=False,
                                        on_enter=HideWindowAction())
                ])

            return self.render_results(
                [extension.jira.issue(event.get_argument())])
        except JIRAError as e:
            return RenderResultListAction([
                ExtensionResultItem(icon='images/error.svg',
                                    description='',
                                    highlightable=False,
                                    name=e.text)
            ])
Ejemplo n.º 9
0
    def getDataStatus(self, items, data_string):
        eur = data_string["bpi"]["EUR"]["rate"]
        dollar = data_string["bpi"]["USD"]["rate"]
        update = data_string['time']['updated']

        items.append(ExtensionResultItem(icon='images/icon.png',
                                         name='EUR: %s' % str(eur),
                                         description='Last Update: %s' % update,
                                         on_enter=HideWindowAction()))
        items.append(ExtensionResultItem(icon='images/icon.png',
                                         name='DOLLAR: %s' % str(dollar),
                                         description='Last Update: %s' % update,
                                         on_enter=HideWindowAction()))

        return items
Ejemplo n.º 10
0
    def on_event(self, event, extension):
        items = []
        try:
            query = event.get_argument() or ""
            if len(query) < 6:
                return RenderResultListAction([
                    ExtensionResultItem(
                        icon='images/searching_icon.png',
                        name="Keep Typing to search vendors ...",
                        on_enter=HideWindowAction(),
                        highlightable=False,
                    )
                ])

            query = Vendor.format_mac(query)
            # url = search_url + query
            mac_list = Vendor.search_vendor(query)

            for result in mac_list:
                url = mac_list[0]['url']
                vendor = mac_list[0]['vendor']
                if vendor == 'Not Found!':
                    items.append(
                        ExtensionResultItem(icon='images/error_icon.png',
                                            name=vendor,
                                            description=query,
                                            on_enter=HideWindowAction()))
                else:
                    # url = mac_list['url']
                    items.append(
                        ExtensionResultItem(
                            icon='images/success_icon.png',
                            name=vendor,
                            description=query,
                            on_enter=OpenUrlAction(url),
                            on_alt_enter=CopyToClipboardAction(url)))

            return RenderResultListAction(items)
            import ipdb
            ipdb.set_trace()
        except Exception as e:
            items.append(
                ExtensionResultItem(icon='images/error_icon.png',
                                    name='ERROR',
                                    description='No items Found!',
                                    on_enter=HideWindowAction()))

            return RenderResultListAction(items)
Ejemplo n.º 11
0
    def on_event(self, event, extension):
        query = event.get_argument()

        if query:
            query = query.split()
            url = query[0] if match('\w+://',
                                    query[0]) else 'http://' + query[0]
            custom = query[1] if len(query) > 1 else None

            if custom and not (5 <= len(custom) <= 30
                               and custom.replace("_", "").isalnum()):
                name = 'Invalid custom name'
                description = 'Must be 5-30 characters long and contain only english characters.'
                on_enter = HideWindowAction()
            else:
                try:
                    urlopen(url)
                except (URLError, ValueError):
                    name = 'Not a valid URL'
                    description = 'Please check if this URL actually exists and try again'
                    on_enter = HideWindowAction()
                else:
                    req_url = 'https://is.gd/create.php?format=simple&url=%s' % url

                    if custom:
                        req_url += '&shorturl=%s' % custom

                    request = get(req_url)

                    if request.status_code == 200:
                        short = request.text
                        name = 'Shortened URL: %s' % short
                        description = 'Copy to clipboard'
                        on_enter = CopyToClipboardAction(short)
                    else:
                        name = ('Oops... (Error: %s - %s)' %
                                (request.status_code,
                                 self.errors[request.status_code][0]))
                        description = self.errors[request.status_code][1]
                        on_enter = HideWindowAction()

            item = [
                ExtensionResultItem(icon='images/icon.png',
                                    name=name,
                                    description=description,
                                    on_enter=on_enter)
            ]
            return RenderResultListAction(item)
Ejemplo n.º 12
0
def open_new_note_action(str_search, do_websearch=False):
    query = str_search.strip()  # clean string ends

    if do_websearch:
        # Build URL for Google search
        url_google = "https://www.google.com/search?q=" + query.replace(' ', "+")
        # Focus 'search' workspace now
        subprocess.call("i3-msg workspace search", shell=True)
        # Open new browser with Google and calendar search
        browser = webbrowser.get('google-chrome')
        browser.open(url_google, new=1, autoraise=True)

    # Check for keywords at the start of the search string to allocate in specific notebook
    first_word = query.split(' ', 1)[0]
    if first_word.lower() == '#fb':
        notebook = 'fb'
        rest_of_query = query.split(' ', 1)[1]
        query = rest_of_query  # drop notebook keyword
    else:
        notebook = 'personal'

    # Create new note and edit it
    new_uid = pyjoplin.new(query, notebook_name=notebook)
    cmd = 'pyjoplin edit %s' % new_uid
    proc = subprocess.Popen(cmd, shell=True)
    return new_uid, HideWindowAction()
Ejemplo n.º 13
0
    def list_available_docs(self, keyword, query):
        """
        Renders a list of available Documentation, optionally filtered by the query argument
        :param str keyword: The search keyword
        :param str query: The search query.
        """
        docs = self.devdocs_svc.get_docs(query)

        if not docs:
            return RenderResultListAction([
                ExtensionResultItem(
                    icon='images/icon.png',
                    name='No documentation found matching your criteria',
                    highlightable=False,
                    on_enter=HideWindowAction())
            ])

        items = []
        for doc in docs[:10]:
            items.append(
                ExtensionResultItem(icon=self.get_icon(doc['slug']),
                                    name=doc['name'],
                                    description=doc.get('release', ""),
                                    on_enter=SetUserQueryAction(
                                        "%s %s:" % (keyword, doc['slug'])),
                                    on_alt_enter=self.open_in_devdocs(
                                        doc['slug'])))

        return RenderResultListAction(items)
Ejemplo n.º 14
0
    def show_builds_for_repo(self, repo_id):
        """ Show the latest build results for the specified repository """

        try:
            builds = self.travis_client.get_builds_for_repo(repo_id)
        except Exception as e:
            return self.handle_errors(e)

        if not builds:
            return RenderResultListAction([
                ExtensionResultItem(
                    icon='images/icon.png',
                    name='No builds found for the specified repository',
                    highlightable=False,
                    on_enter=HideWindowAction())
            ])

        items = []
        for build in builds:

            items.append(
                ExtensionResultItem(
                    icon=self.get_icon_for_build(build['state']),
                    name='#%s - %s' %
                    (build['number'], build['commit_message']),
                    description='Branch: %s | Started by: %s | Updated: %s' %
                    (build['branch'], build['triggered_by'],
                     build['updated_at']),
                    on_enter=OpenUrlAction(build['url']),
                    highlightable=False,
                ))

        return RenderResultListAction(items)
    def on_event(self, event, extension):
        query = event.get_argument() or ""

        if not query:
            return extension.show_menu()

        logger.debug(query)

        create = re.findall(r"^create\s(.*)?$", query, re.IGNORECASE)

        try:
            if create:
                logger.debug(create)
                return RenderResultListAction([
                    ExtensionResultItem(
                        icon=extension.get_icon(),
                        name='Create task %s' % create[0],
                        description="Create a new task",
                        highlightable=False,
                        on_enter=ExtensionCustomAction({"action": "create", "query": create[0]}, keep_app_open=False))
                ])

        except:
            return RenderResultListAction([
                ExtensionResultItem(
                    icon=extension.get_icon(),
                    name='An error ocurred',
                    description="",
                    highlightable=False,
                    on_enter=HideWindowAction())
            ])
Ejemplo n.º 16
0
    def on_event(self, event, extension):
        query = event.get_argument() or str()

        if len(query.strip()) == 0:
            return RenderResultListAction([
                ExtensionResultItem(icon='images/icon.png',
                                    name='No input',
                                    on_enter=HideWindowAction())
            ])

        if len(query) > 3 and ":" in query[0]:
            from_language = "auto"
            to_language = query[1:3]
            query = query[3:]
        elif len(query) > 5 and ":" in query[2]:
            from_language = query[:2]
            to_language = query[3:5]
            query = query[5:]
        else:
            from_language = extension.preferences["otherlang"]
            to_language = extension.preferences["mainlang"]
        ceviri = translate(query, to_language, from_language,
                           extension.preferences["wrap"])
        items = [
            ExtensionResultItem(icon='images/icon.png',
                                name=query.replace("\n", ""),
                                description=translate(
                                    query, to_language, from_language,
                                    extension.preferences["wrap"]),
                                on_enter=CopyToClipboardAction(ceviri))
        ]

        return RenderResultListAction(items)
Ejemplo n.º 17
0
    def list_repos(self, query):
        """ Lists the Repositories from the user """

        try:
            repos = self.travis_client.get_repos(query)
        except Exception as e:
            return self.handle_errors(e)

        if not repos:
            return RenderResultListAction([
                ExtensionResultItem(icon='images/icon.png',
                                    name='No Repositories found',
                                    on_enter=HideWindowAction())
            ])

        items = []
        for repo in repos[:8]:
            desc = ''
            if repo['description']:
                desc = repo['description']

            items.append(
                ExtensionResultItem(
                    icon='images/icon.png',
                    name=repo['name'],
                    description=desc,
                    on_enter=SetUserQueryAction(
                        "%s %s builds" % (self.preferences["kw"], repo['id'])),
                    on_alt_enter=OpenUrlAction(repo['url'])))

        return RenderResultListAction(items)
Ejemplo n.º 18
0
    def on_event(self, event, extension):
        """ Handles the event """
        items = []

        query = event.get_argument()
        if query is None:
            tabs = extension.tabs
        else:
            tabs = [
                t for t in extension.tabs
                if query.lower() in t['name'].lower()
            ]

        if not tabs:
            items.append(
                ExtensionResultItem(
                    icon='images/icon.png',
                    name='No tabs found',
                    description=
                    'Make sure your ulauncher-tabs-helper chrome extension is installing and running',
                    on_enter=HideWindowAction()))
        else:
            for tab in tabs[:25]:
                items.append(
                    ExtensionSmallResultItem(icon='images/icon.png',
                                             name=tab['name'].encode("utf-8"),
                                             on_enter=ExtensionCustomAction(
                                                 tab['id'])))

        return RenderResultListAction(items)
Ejemplo n.º 19
0
 def on_event(self, event, extension):
     data = event.get_data()
     return RenderResultListAction([
         ExtensionResultItem(icon='images/icon.png',
                             name=data['new_name'],
                             on_enter=HideWindowAction())
     ])
Ejemplo n.º 20
0
    def list_groups(self, query):
        """ Lists the groups the user belongs to """

        items = []
        groups = self.gitlab.groups.list(archived=0,
                                         search=query,
                                         order_by='name',
                                         sort='asc',
                                         page=1,
                                         per_page=10)

        if not groups:
            return RenderResultListAction([
                ExtensionResultItem(
                    icon='images/icon.png',
                    name="No groups found matching your search criteria",
                    highlightable=False,
                    on_enter=HideWindowAction())
            ])

        for group in groups:
            if group.description is not None:
                description = group.description
            else:
                description = ''

            items.append(
                ExtensionResultItem(icon='images/icon.png',
                                    name=group.name,
                                    description=description,
                                    highlightable=False,
                                    on_enter=OpenUrlAction(group.web_url)))

        return RenderResultListAction(items)
Ejemplo n.º 21
0
    def search_users(self, query):
        """ Search GitHub users """

        if not query or len(query) < 3:
            return RenderResultListAction([
                ExtensionResultItem(
                    icon='images/icon.png',
                    name='Please keep typing your search query',
                    description='Minimum 3 chars',
                    highlightable=False,
                    on_enter=HideWindowAction())
            ])

        users = self.github.search_users(query=query,
                                         sort="followers",
                                         order="desc")[:8]

        items = []

        for user in users:
            items.append(
                ExtensionResultItem(icon='images/icon.png',
                                    name=user.name,
                                    on_enter=OpenUrlAction(user.html_url),
                                    on_alt_enter=CopyToClipboardAction(
                                        user.html_url)))

        return RenderResultListAction(items)
Ejemplo n.º 22
0
    def show_entries(self, doc_slug, query):
        """
        Renders a list of available Docs
        :param str keyword: The keyword used to trigger this search
        :param str doc: The main documentation slug
        :param str query: The search term to filter the entries
        """

        entries = self.devdocs_svc.get_doc_entries(doc_slug, query)

        if not entries:
            return RenderResultListAction([
                ExtensionResultItem(
                    icon='images/icon.png',
                    name='No entries found matching your criteria',
                    highlightable=False,
                    on_enter=HideWindowAction())
            ])

        items = []
        for entry in entries[:8]:
            items.append(
                ExtensionResultItem(icon=self.get_icon(doc_slug),
                                    name=entry['name'],
                                    description=entry['type'],
                                    on_enter=self.open_in_devdocs(
                                        doc_slug, entry['path'])))

        return RenderResultListAction(items)
Ejemplo n.º 23
0
    def search_public_repos(self, query):
        """ Search public repos """

        if not query or len(query) < 3:
            return RenderResultListAction([
                ExtensionResultItem(
                    icon='images/icon.png',
                    name='Please keep typing your search query',
                    description='Minimum 3 chars',
                    highlightable=False,
                    on_enter=HideWindowAction())
            ])

        repos = self.github.search_repositories(query=query)[:8]

        items = []

        for repo in repos:
            items.append(
                ExtensionResultItem(
                    icon='images/icon.png',
                    name="%s (%s stars)" %
                    (repo.name.encode('utf-8'), repo.stargazers_count),
                    description=repo.description.encode('utf-8'),
                    on_enter=OpenUrlAction(repo.html_url),
                    on_alt_enter=CopyToClipboardAction(repo.html_url)))

        return RenderResultListAction(items)
Ejemplo n.º 24
0
    def search_repositories(self, query):
        """ Shows the a list of DockerHub repositories """
        if len(query) < 3:
            return RenderResultListAction([
                ExtensionResultItem(
                    icon='images/icon.png',
                    name='Keep typing to search on Docker Hub ...',
                    highlightable=False,
                    on_enter=DoNothingAction())
            ])

        repos = self.dockerhub.search_repos(query)

        items = []

        if not repos:
            return RenderResultListAction([
                ExtensionResultItem(
                    icon="images/icon.png",
                    name="No results found matching your criteria",
                    highlightable=False,
                    on_enter=HideWindowAction())
            ])

        for repo in repos[:8]:
            items.append(
                ExtensionResultItem(icon='images/icon.png',
                                    name="%s 🟊 %s" %
                                    (repo["name"], repo["stars"]),
                                    description=repo["description"],
                                    on_enter=OpenUrlAction(repo["url"])))

        return RenderResultListAction(items)
Ejemplo n.º 25
0
    def on_event(self, event, extension):
        """ Handles the event """
        items = []
        keyword = event.get_keyword()
        query = event.get_argument() or ""
        file_path = extension.get_recent_projects_file_path(keyword)

        projects = RecentProjectsParser.parse(file_path, query)

        if not projects:
            return RenderResultListAction([
                ExtensionResultItem(icon=extension.get_icon(keyword),
                                    name='No projects found',
                                    on_enter=HideWindowAction())
            ])
        for project in projects:
            items.append(
                ExtensionResultItem(
                    icon=project['icon'] if project['icon'] is not None else
                    extension.get_icon(keyword),
                    name=project['name'],
                    description=project['path'],
                    on_enter=RunScriptAction(
                        '%s "%s" &' % (extension.get_launcher_file(keyword),
                                       project['path']), []),
                    on_alt_enter=CopyToClipboardAction(project['path'])))
        return RenderResultListAction(items)
Ejemplo n.º 26
0
    def search_projects(self, query, search_type):
        """ Search projects in GitLab """

        if search_type == PROJECTS_SEARCH_TYPE_MEMBER:
            projects = self.gitlab.projects.list(
                search=query,
                membership=1,
                order_by='name',
                sort='asc',
                simple=1,
                page=1,
                per_page=10
            )
        elif search_type == PROJECTS_SEARCH_TYPE_STARRED:
            projects = self.gitlab.projects.list(
                search=query,
                order_by='last_activity_at',
                sort='desc',
                starred=1,
                simple=1,
                page=1,
                per_page=10
            )
        else:
            projects = self.gitlab.projects.list(
                search=query,
                visibility='public',
                order_by='last_activity_at',
                sort='desc',
                simple=1,
                page=1,
                per_page=10
            )

        if not projects:
            return RenderResultListAction([
                ExtensionResultItem(
                    icon='images/icon.png',
                    name="No projects found matching your search criteria",
                    highlightable=False,
                    on_enter=HideWindowAction())
            ])

        items = []
        for project in projects:
            if project.description is not None:
                description = project.description
            else:
                description = ''
            items.append(
                ExtensionResultItem(
                    icon='images/icon.png',
                    name=project.name,
                    description=description,
                    highlightable=False,
                    on_enter=OpenUrlAction(project.web_url)
                )
            )

        return RenderResultListAction(items)
Ejemplo n.º 27
0
 def show_empty_results_message(self):
     """ shows empty message """
     return RenderResultListAction([
         ExtensionResultItem(icon='images/icon.png',
                             name='No cheat sheets found for your query',
                             on_enter=HideWindowAction())
     ])
Ejemplo n.º 28
0
    def show_docsets_list(self, event, query):
        """ Displays a list of available docs """

        docs = self.searcher.get_available_docs(query)

        items = []

        if not docs:
            return RenderResultListAction([
                ExtensionResultItem(
                    icon='images/icon.png',
                    name='No docsets found matching your criteria',
                    on_enter=HideWindowAction())
            ])

        for doc in docs[:8]:
            items.append(
                ExtensionResultItem(
                    icon=doc['icon'],
                    name=doc['name'],
                    description=doc['description'],
                    on_alt_enter=OpenUrlAction(doc['url']),
                    on_enter=SetUserQueryAction(
                        "%s %s " % (event.get_keyword(), doc['key']))))

        return RenderResultListAction(items)
Ejemplo n.º 29
0
    def show_applications(self, query):
        """ shows the list of available applications known by the extension """
        apps = self.shortcuts_service.get_applications(query)

        if not apps:
            return RenderResultListAction([
                ExtensionSmallResultItem(
                    icon='images/icon.png',
                    name='No applications found matching your criteria',
                    highlightable=False,
                    on_enter=HideWindowAction())
            ])

        items = []
        for app in apps[:15]:
            items.append(
                ExtensionSmallResultItem(icon=app['icon'],
                                         name=app['name'],
                                         on_enter=ExtensionCustomAction({
                                             "action":
                                             "show",
                                             "app":
                                             app,
                                         }),
                                         on_alt_enter=OpenUrlAction(
                                             app['reference_url'])))
        return RenderResultListAction(items)
Ejemplo n.º 30
0
    def on_event(self, event, extension):

        query = event.get_argument()

        if query:
            try:
                convertedItems = self.parse_query(query)

                items = []
                for i in convertedItems:
                    items.append(
                        ExtensionResultItem(
                            icon='images/icon.png',
                            name=i,
                            #description='...',
                            on_enter=HideWindowAction()))

                return RenderResultListAction(items)

            except ParseQueryError:
                return self.get_action_to_render(
                    name="Incorrect request",
                    description="For example 1 cup, 2,25 m, 4 oz or 62.5 C")

        else:
            return self.get_action_to_render(
                name="Convert by typing an amount and a unit",
                description="For example 1 cup, 2,25 m, 4 oz or 62.5 C")