Exemplo n.º 1
0
def createItems(windows, spans=None):
    results = []
    # print('spans: ', spans)
    # [print(w.wm_name) for w in windows]
    # print(len(windows))
    for win in windows:
        if spans:
            text_subtext = highlightText(win, spans[win.wid])
        else:
            text_subtext = {
                'text':
                '%s: %s' %
                (win.desktop, win.wm_class.split('.')[-1].replace('-', ' ')),
                'subtext':
                '%s➜%s' % (win.wm_class.split('.')[-1], win.wm_name)
            }

        win_instance, win_class = win.wm_class.replace(' ', '-').split('.')
        iconPath = iconLookup(win_instance) or iconLookup(win_class.lower())
        results.append(
            Item(id="%s%s" % (__title__, win.wm_class),
                 **text_subtext,
                 icon=iconPath,
                 actions=[
                     ProcAction(text="Switch Window",
                                commandline=["wmctrl", '-i', '-a', win.wid]),
                     ProcAction(text="Move window to this desktop",
                                commandline=["wmctrl", '-i', '-R', win.wid]),
                     ProcAction(text="Close the window gracefully.",
                                commandline=["wmctrl", '-c', win.wid])
                 ]))

    return results
Exemplo n.º 2
0
def handleList(query):
    if len(config.sections()) == 0:
        # Try to reload the config.
        config.read(calendar_configuration_file)
        if len(config.sections()) == 0:
            info("No sections defined in config.")
            return Item(id="config",
                        icon=unresolved_todo,
                        text="Configuration not complete",
                        subtext="No sections in the Configuration file",
                        actions=[
                            ProcAction(
                                text="Edit configuration in default editor",
                                commandline=['xdg-open',
                                             calendar_configuration_file],
                                cwd="~"),
                            ClipAction(
                                text="Copy the path of the configuration file",
                                clipboardText=calendar_configuration_file)
                        ])
        else:
            connections.set_connections(config)
            connections.load_todos()
    items = []
    connections.refresh()
    for todo in connections.query(query.string):
        items.append(buildItem(todo))

    return items
Exemplo n.º 3
0
def handleQuery(query):
    results = []
    if query.isTriggered:

        # avoid rate limiting
        sleep(0.2)
        if not query.isValid:
            return

        item = Item(id=__title__,
                    icon=iconPath,
                    text=__title__,
                    actions=[
                        ProcAction("Open the language configuration file.",
                                   commandline=[
                                       "xdg-open", language_configuration_file
                                   ])
                    ])
        if len(query.string) >= 2:
            for lang in languages:
                try:
                    url = urltmpl % (lang, urllib.parse.quote_plus(
                        query.string))
                    req = urllib.request.Request(url,
                                                 headers={'User-Agent': ua})
                    with urllib.request.urlopen(req) as response:
                        #print(type())
                        #try:
                        data = json.loads(response.read().decode())
                        #except TypeError as typerr:
                        #    print("Urgh this type.error. %s" % typerr)
                        translText = data[0][0][0]
                        sourceText = data[2]
                        if sourceText == lang:
                            continue
                        else:
                            results.append(
                                Item(id=__title__,
                                     icon=iconPath,
                                     text="%s" % (translText),
                                     subtext="%s" % lang.upper(),
                                     actions=[
                                         ClipAction(
                                             "Copy translation to clipboard",
                                             translText),
                                         UrlAction(
                                             "Open in your Browser",
                                             urlbrowser % (lang, query.string))
                                     ]))
                except urllib.error.URLError as urlerr:
                    print("Check your internet connection: %s" % urlerr)
                    item.subtext = "Check your internet connection."
                    return item
        else:
            item.subtext = "Enter a query: 'mtr <text>'. Languages {%s}" % ", ".join(
                languages)
            return item
    return results
Exemplo n.º 4
0
def handleQuery(query):
    if query.isTriggered:
        return Item(id=__title__,
                    icon=iconPath,
                    text=__title__,
                    subtext="Look up '%s' using %s" %
                    (query.string, __title__),
                    actions=[
                        ProcAction("Start query in %s" % __title__,
                                   ["goldendict", query.string])
                    ])
Exemplo n.º 5
0
def handleQuery(query):
    stripped = query.string.strip().lower()
    if stripped:
        results = []
        for line in subprocess.check_output(['wmctrl', '-lG',
                                             '-x']).splitlines():
            try:
                win = Window(*parseWindow(line))

                if win.desktop == "-1":
                    continue

                win_instance, win_class = win.wm_class.replace(' ',
                                                               '-').split('.')
                matches = [
                    win_instance.lower(),
                    win_class.lower(),
                    win.wm_name.lower()
                ]

                if any(stripped in match for match in matches):
                    iconPath = iconLookup(win_instance) or iconLookup(
                        win_class.lower())
                    results.append(
                        Item(id="%s%s" % (__title__, win.wm_class),
                             icon=iconPath,
                             text="%s  - <i>Display %s</i>" %
                             (win_class.replace('-', ' '), win.display),
                             subtext=win.wm_name,
                             actions=[
                                 ProcAction("Switch Window",
                                            ["wmctrl", '-i', '-a', win.wid]),
                                 ProcAction("Move window to this desktop",
                                            ["wmctrl", '-i', '-R', win.wid]),
                                 ProcAction("Close the window gracefully.",
                                            ["wmctrl", '-c', win.wid])
                             ]))
            except:
                continue

        return results
Exemplo n.º 6
0
def handleQuery(query):
    results = []

    # add all matching commands
    stripped = query.string.strip().lower().split()
    if stripped:
        for title, command in commands.items():
            # query is split on spaces and each part must be in the command title
            title_lower = title.lower()
            if all(strip in title_lower for strip in stripped):
                results.append(
                    Item(id=title,
                         text=title,
                         subtext=' '.join(command),
                         actions=[
                             ProcAction("Run", command),
                         ]))

    return results