Python workflow 模块,ICON_ERROR 实例源码

我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用workflow.ICON_ERROR

项目:Alfred-Workflow    作者:stidio    | 项目源码 | 文件源码
def main(wf):
    # ?????????
    param = (wf.args[0] if len(wf.args) else '').strip()
    if param:
        title, ip = resolve_ip_from_dns(param)
    else:
        title = get_local_ip()
        ip = get_public_ip()

    if ip:
        location = get_location_information(ip)
        wf.add_item(title=title, 
                    subtitle=ip + ' ' + location if location else '', 
                    arg=ip,
                    valid=True,
                    icon=ICON_INFO)
    else:
        wf.add_item(title=title, subtitle='...', icon=ICON_ERROR)

    # Send the results to Alfred as XML
    wf.send_feedback()
项目:jisho-alfred-workflow    作者:janclarin    | 项目源码 | 文件源码
def main(wf):
    """Main function to handle query and request info from Jisho.org.
    Args:
        wf: An instance of Workflow.
    """
    # Get query from Alfred.
    query = wf.args[0] if len(wf.args) else None

    # Add query result if there is an update.
    if wf.update_available:
        wf.add_item('A newer version of Jisho Alfred Workflow is available',
                    'Action this item to download and install the new version',
                    autocomplete='workflow:update',
                    icon=ICON_INFO)

    try:
        # Only fetch results from Jisho.org if it is a valid query.
        results = get_results(query) if is_valid_query(query) else []

        if results:
            # Add results to Alfred, up to the maximum number of results.
            for i in range(min(len(results), MAX_NUM_RESULTS)):
                add_alfred_result(wf, results[i])
        else:
            # Add an error result if there was an issue getting results.
            error_msg = "Could not find anything matching '%s'" % (query)
            wf.add_item(error_msg, arg=query, valid=True, icon=ICON_NOTE)
    except:
        # Add an error result if there was an issue getting results.
        error_msg = "There was an issue retrieving Jisho results"
        wf.add_item(error_msg, arg=query, valid=True, icon=ICON_ERROR)

    # Send the results to Alfred as XML.
    wf.send_feedback()
项目:Alfred-Workflow    作者:noogel    | 项目源码 | 文件源码
def main(wf):
    # ?????????
    params = (wf.args or [""])[0].strip().split(" ")
    optype, param = params[0].strip(), " ".join(params[1:]).strip()
    if not param:
        wf.add_item(title=u"?????", subtitle="Cant\'t Empty!", icon=ICON_ERROR)
    elif optype in CATEGORY_MAP:
        conf = CATEGORY_MAP[optype]
        try:
            result = globals()[conf["func"]](param)
        except Exception as ex:
            result = ex.message
        if isinstance(result, basestring):
            wf.add_item(
                title=u"{} ?{}?".format(conf["title"], param),
                subtitle=result,
                arg=result,
                valid=True,
                icon=ICON_INFO)
        elif isinstance(result, list):
            for item in result:
                wf.add_item(
                    title=item["title"],
                    subtitle=item["cmd"],
                    arg=param,
                    valid=True,
                    icon=ICON_INFO)
        else:
            wf.add_item(title=u"?????????", subtitle="...", icon=ICON_ERROR)
    else:
        wf.add_item(title=u"????", subtitle="...", icon=ICON_ERROR)

    wf.send_feedback()
项目:alfred-workflows    作者:mttjhn    | 项目源码 | 文件源码
def main(wf):
    log.debug('Started!')
    # Get query from Alfred
    if len(wf.args):
        query = wf.args[0]
    else:
        query = None

    log.debug(query)
    # If the query is blank, grab the contents of the clipboard
    if query == None:
        query = getClipboard()

    log.debug(query)

    if query != None:
        # Start by trimming whitespace
        query = query.strip()
        # Let's process the URL now!
        if URL_CHECK in query:
            # Looks like we're ok to go ahead on this one.
            # TODO: Could do full URL parsing here, but this is probably good enough
            # We're already dealing with undocumented Droplr API anyways...
            output = getDroplrInfo(query)
            if len(output) > 0:
                # Looks like we found something!
                # Let's prepare the link...
                processItem = wf.add_item(title=u'Download {0} from Droplr'.format(output[1]),
                    subtitle=u'File name: {0}'.format(output[0]),
                    arg=query, 
                    icon=u'{0}.png'.format(output[1]),
                    valid=True)
            else:
                # Didn't find data, but we could still try the link!..
                processItem = wf.add_item(title=u'Download from Droplr',
                    subtitle=u'{0}'.format(query),
                    arg=query, 
                    icon=u'image.png',
                    valid=True)
            # Set the variable we're filtering for
            processItem.setvar(u'download', '1')
        else:
            invalidError = wf.add_item(title=u'Valid URL not found in clipboard!',
                subtitle=u'Please try again with a valid Droplr URL.',
                icon=ICON_ERROR,
                valid=False)

        # Send the results to Alfred as XML
        wf.send_feedback()
项目:alfred-crypto-tracker    作者:rhlsthrm    | 项目源码 | 文件源码
def main(wf):
    # Get query from Alfred
    if len(wf.args):
        query = wf.args[0]
    else:
        query = None

    url = 'https://poloniex.com/public?command=returnTicker'
    r = web.get(url)

    # throw an error if request failed
    # Workflow will catch this and show it to the user
    r.raise_for_status()

    result = r.json()
    if query:
        usd_query = 'USDT_' + query.upper()
        usd_link = 'https://poloniex.com/exchange#' + usd_query
        if usd_query in result:
            formatted = format_strings_from_quote(query, result)
            wf.add_item(title=formatted['title'],
                        subtitle=formatted['subtitle'],
                        arg=usd_link,
                        valid=True,
                        icon=ICON_WEB)
        else:
            wf.add_item(title='Couldn\'t find a quote for that symbol.',
                        subtitle='Please try again.',
                        icon=ICON_ERROR)
    else:
        formatted = format_strings_from_quote('BTC', result)
        wf.add_item(title=formatted['title'],
                    subtitle=formatted['subtitle'],
                    arg='https://poloniex.com/exchange#usdt_btc',
                    valid=True,
                    icon='icon/btc.png')

        formatted = format_strings_from_quote('ETH', result)
        wf.add_item(title=formatted['title'],
                    subtitle=formatted['subtitle'],
                    arg='https://poloniex.com/exchange#usdt_eth',
                    valid=True,
                    icon='icon/eth.png')

        formatted = format_strings_from_quote('LTC', result)
        wf.add_item(title=formatted['title'],
                    subtitle=formatted['subtitle'],
                    arg='https://poloniex.com/exchange#usdt_ltc',
                    valid=True,
                    icon='icon/ltc.png')

    # Send the results to Alfred as XML
    wf.send_feedback()