Esempio n. 1
0
def results(parsed, original_query):
    if '~unknown_language' in parsed:
      from centered_text import centered_text
      return {
        "title": "Translate",
        "html": centered_text(u"Unsupported language: {0}".format(parsed['~unknown_language'])),
        "webview_transparent_background": True
      }
    if 'clipboard' in parsed:
      from copy_to_clipboard import clipboard_text
      text = clipboard_text()
    else:
      text = parsed['~text']
    from_lang = "auto"
    to_lang = "english"
    for key, val in parsed.iteritems():
        if key.startswith('from_language/'):
            from_lang = key.split('/')[1]
        elif key.startswith('to_language/'):
            to_lang = key.split('/')[1]
    from dark_mode import dark_mode
    color = "white" if dark_mode() else "black"
    html = open("translate.html").read().replace("----text----", text).replace("----fromlang----", lang_codes[from_lang]).replace("----tolang----", lang_codes[to_lang]).replace("----color----", color)
    if from_lang == 'auto':
        title = "Translate \"{0}\" to {1}".format(text, to_lang)
    else:
        title = "Translate \"{0}\" from {1} to {2}".format(text, from_lang, to_lang)
    return {
        "title": title,
        "html": html,
        "webview_transparent_background": True,
        "pass_result_of_output_function_as_first_run_arg": True,
        "run_args": []
    }
Esempio n. 2
0
def results(fields, original_query):
    from dark_mode import dark_mode

    def li_for_path(path):
        base, filename = os.path.split(path)
        command = json.dumps(open_command(path))
        return u"""<li onclick='flashlight.bash({0})'><strong>{1}</strong> <span>from {2}</span></li>""".format(
            command, filename, base
        )

    paths = [fields["@file"]["path"]] + fields["@file"]["otherPaths"]
    rows = u"".join(map(li_for_path, paths))
    html = u"""
	<style>
	body {
		margin: 0;
		font-family: sans-serif;
		color: <!--COLOR-->;
	}
	ul {
		padding: 0;
	}
	li {
		list-style-type: none;
		padding: 10px;
		border-bottom: 1px solid rgba(0,0,0,0.2);
		cursor: default;
	}
	li:last-child {
		border-bottom: none;
	}
	li span {
		opacity: 0.7;
	}
	ul:not(:hover) li:first-child, li:hover {
		background-color: rgba(100,100,100,0.1);
	}
	</style>
	<ul>
	<!--ROWS-->
	</ul>
	""".replace(
        "<!--COLOR-->", "white" if dark_mode() else "black"
    ).replace(
        "<!--ROWS-->", rows
    )
    return {
        "title": "Reveal in Finder",
        "html": html,
        "run_args": [paths[0] if len(paths) else None],
        "webview_transparent_background": True,
    }
Esempio n. 3
0
def results(parsed, original_query):
    if '~unknown_language' in parsed:
      from centered_text import centered_text
      return {
        "title": "Translate",
        "html": centered_text(u"Unsupported language: {0}".format(parsed['~unknown_language'])),
        "webview_transparent_background": True
      }
    if 'clipboard' in parsed:
      from copy_to_clipboard import clipboard_text
      text = clipboard_text()
    else:
      text = parsed['~text']
    from_lang = "auto"
    to_lang = "english"
    for key, val in parsed.iteritems():
        if key.startswith('from_language/'):
            from_lang = key.split('/')[1]
        elif key.startswith('to_language/'):
            to_lang = key.split('/')[1]
    from dark_mode import dark_mode
    color = "white" if dark_mode() else "black"
    html = open("translate.html").read().replace("----text----", text).replace("----fromlang----", lang_codes[from_lang]).replace("----tolang----", lang_codes[to_lang]).replace("----color----", color)


    if from_lang == 'auto':
        title = u"Translate \"{0}\" to {1}".format(text, to_lang)
    else:
        title = u"Translate \"{0}\" from {1} to {2}".format(text, from_lang, to_lang)

    # Temporary Fix, adapted from Google Translate plugin
    url = 'https://translate.google.com/m/translate#<LANG_FROM>/<LANG_TO>/<TEXT>'
    url = url.replace('<LANG_FROM>', lang_codes[from_lang])
    url = url.replace('<LANG_TO>', lang_codes[to_lang])
    url = url.replace('<TEXT>', urllib.quote_plus(text))

    return {
        "title": title,
        "html": "<script>window.location=%s</script>" % json.dumps(url),
        "webview_user_agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53",
        "webview_links_open_in_browser": True,
        "run_args": [url]

        # Previous return fields
        '''
        "html": html,
        "webview_transparent_background": True,
        "pass_result_of_output_function_as_first_run_arg": True,
        "run_args": []
        '''
    }
Esempio n. 4
0
def results(fields, original_query):
	from dark_mode import dark_mode
	def li_for_path(path):
		base, filename = os.path.split(path)
		command = json.dumps(open_command(path))
		return u"""<li onclick='flashlight.bash({0})'><strong>{1}</strong> <span>from {2}</span></li>""".format(command, filename, base)
	paths = [fields['@file']['path']] + fields['@file']['otherPaths']
	rows = u"".join(map(li_for_path, paths))
	html = u"""
	<style>
	body {
		margin: 0;
		font-family: sans-serif;
		color: <!--COLOR-->;
	}
	ul {
		padding: 0;
	}
	li {
		list-style-type: none;
		padding: 10px;
		border-bottom: 1px solid rgba(0,0,0,0.2);
		cursor: default;
	}
	li:last-child {
		border-bottom: none;
	}
	li span {
		opacity: 0.7;
	}
	ul:not(:hover) li:first-child, li:hover {
		background-color: rgba(100,100,100,0.1);
	}
	</style>
	<ul>
	<!--ROWS-->
	</ul>
	""".replace("<!--COLOR-->", 'white' if dark_mode() else 'black').replace('<!--ROWS-->', rows)
	return {
		"title": "Reveal in Finder",
		"html": html,
		"run_args": [paths[0] if len(paths) else None],
		"webview_transparent_background": True
	}
Esempio n. 5
0
def results(parsed, original_query, object):
    from dark_mode import dark_mode

    body_class = 'dark' if dark_mode else 'light'

    dates = []
    if '@date_all' in parsed:
        dates = parsed['@date_all']
    elif '@date' in parsed:
        dates = [parsed['@date']]
    ensure_end_date_is_later(dates)
    if len(dates) == 0:
        dates.append({"timestamp": time.time()})
    if len(dates) == 1:
        dates.append({"timestamp": dates[0]['timestamp'] + 60 * 60})

    date_strings = map(html_from_date_obj, dates)
    if len(dates) > 1:
        date_strings.insert(1, "<span class='dash'>&mdash;</span>")

    event = parsed.get('~name', "Calendar Event")

    location = parsed.get('~location', None)

    from jinja2 import Template
    html = Template(open("template.html").read()).render({
        "dates":
        date_strings,
        "event":
        event,
        "location":
        location,
        "color":
        'dark' if dark_mode() else 'light'
    })

    from_date = dates[0]['timestamp'] if len(dates) else None
    to_date = dates[1]['timestamp'] if len(dates) > 1 else None
    return {
        "title": json.loads(open("info.json").read())['displayName'],
        "run_args": [event, from_date, to_date, location],
        "html": html,
        "webview_transparent_background": True
    }
Esempio n. 6
0
def results(parsed, original_query):
    if '~unknown_language' in parsed:
        from centered_text import centered_text
        return {
            "title":
            "Translate",
            "html":
            centered_text(u"Unsupported language: {0}".format(
                parsed['~unknown_language'])),
            "webview_transparent_background":
            True
        }
    if 'clipboard' in parsed:
        from copy_to_clipboard import clipboard_text
        text = clipboard_text()
    else:
        text = parsed['~text']
    from_lang = "auto"
    to_lang = "english"
    for key, val in parsed.iteritems():
        if key.startswith('from_language/'):
            from_lang = key.split('/')[1]
        elif key.startswith('to_language/'):
            to_lang = key.split('/')[1]
    from dark_mode import dark_mode
    color = "white" if dark_mode() else "black"
    html = open("translate.html").read().replace("----text----", text).replace(
        "----fromlang----", lang_codes[from_lang]).replace(
            "----tolang----",
            lang_codes[to_lang]).replace("----color----", color)

    if from_lang == 'auto':
        title = u"Translate \"{0}\" to {1}".format(text, to_lang)
    else:
        title = u"Translate \"{0}\" from {1} to {2}".format(
            text, from_lang, to_lang)
    return {
        "title": title,
        "html": html,
        "webview_transparent_background": True,
        "pass_result_of_output_function_as_first_run_arg": True,
        "run_args": []
    }
Esempio n. 7
0
def to_html(ok, word, n, suggestions):
		page1 = open('template_base.html')
		html_template_base = page1.read().decode('utf-8')
		
		term_to_insert = word.decode('utf-8') + u' ✓' if ok else word
		html = html_template_base.replace("#TERM#", term_to_insert, 1)
		html = html.replace("#COLORSCHEME#", ('dark' if dark_mode() else 'light'))

		list_html = ""
		if ok:
			list_html += "<p class='info'>That's a word.</p>"
		
		if not ok:
				page2 = open('template_listitem.html')
				html_template_listitem = page2.read()
				if len(suggestions) and len(suggestions[0]):
					list_html = "<p class='info'>Did you mean:</p>"
					for guess in suggestions:
							list_html += html_template_listitem.replace("#GUESS#", guess.strip(), 1)
				else:
					list_html += "<p class='info'>No suggestions.</p>"
		html = html.replace("#LIST#", list_html, 1)

		return html
Esempio n. 8
0
def results(fields, original_query):
	from dark_mode import dark_mode
	items = menu_items()
	if items != None:
		# remove submenus from results:
		menus = set((i.parent_path() for i in items))
		items = [i for i in items if i.full_path() + u"/" not in menus]
		# filter items:
		if '~item' in fields:
			query = fields['~item']
			for item in items:
				item.score = item.match_score(query)
			items = [item for item in items if item.score > 0]
			items.sort(key=lambda x: -x.score)
		# truncate items:
		n_more = max(0, len(items) - 10)
		if n_more:
			items = items[:-n_more]
		# generate html:
		html = u"""
		<style>
		body {
			padding: 0;
			margin: 0;
			font-family: "HelveticaNeue";
		}
		body.dark {
			color: white;
		}
		body.light {
			color: black;
		}
		ol {
			list-style-type: none;
			padding: 0;
			cursor: default;
		}
		ol#items > li {
			border-bottom: 1px solid rgba(120,120,120,0.2);
			padding: 0.5em;
			font-size: small;
		}
		ol#items > li:last-child {
			border-bottom: none;
		}
		ol.path {
			display: inline;
		}
		ol.path > li {
			display: inline-block;
			opacity: 0.6;
		}
		ol.path > li:after {
			content: "⟩";
			display: inline-block;
			padding-left: 0.5em;
			padding-right: 0.5em;
			opacity: 0.7;
		}
		.title {
			font-weight: bold;
		}
		.nmore {
			text-align: center;
			font-size: small;
			opacity: 0.5;
		}
		
		ol#items > li:first-child {
			background-color: rgba(125, 125, 125, 0.3);
		}
		
		/*ol#items:not(:hover) > li:first-child, ol#items:hover > li:hover {
			background-color: rgba(125, 125, 125, 0.3);
		}*/
		
		</style>
		
		<ol id='items'>
		<!--ITEMS-->
		</ol>
		""".replace(u"<!--ITEMS-->", u"".join([i.html() for i in items])).replace("<!--COLOR-->", ("dark" if dark_mode() else "light"))
		if n_more:
			html += u"<p class='nmore'>{0} more...</p>".format(n_more)
	else:
		from centered_text import centered_text
		html = centered_text("""
		<style>
		p {
			margin: 10px;
			font-size: 15px;
		}
		</style>
		<p>Spotlight needs accessibility permissions to search menu items.</p>
		<p><img src='settings.png' style='max-width: 250px'/></p>
		<p><button onclick="flashlight.bash('open /System/Library/PreferencePanes/Security.prefPane')">Open Privacy Settings</button></p>
		""")
	d = {
		"title": "Search menu items",
		"html": html,
		"webview_transparent_background": True
	}
	if items and len(items) > 0:
		d['run_args'] = [items[0].applescript]
	return d
Esempio n. 9
0
def results(parsed, original_query, object):
    from dark_mode import dark_mode

    body_class = "dark" if dark_mode else "light"

    dates = []
    if "@date_all" in parsed:
        dates = parsed["@date_all"]
    elif "@date" in parsed:
        dates = [parsed["@date"]]
    ensure_end_date_is_later(dates)
    if len(dates) == 0:
        dates.append({"timestamp": time.time()})
    if len(dates) == 1:
        dates.append({"timestamp": dates[0]["timestamp"] + 60 * 60})

    date_strings = map(html_from_date_obj, dates)
    if len(dates) > 1:
        date_strings.insert(1, "<span class='dash'>&mdash;</span>")

    event = parsed.get("~name", "Calendar Event")

    location = parsed.get("~location", None)

    from jinja2 import Template

    html = Template(open("template.html").read()).render(
        {"dates": date_strings, "event": event, "location": location, "color": "dark" if dark_mode() else "light"}
    )

    from_date = dates[0]["timestamp"] if len(dates) else None
    to_date = dates[1]["timestamp"] if len(dates) > 1 else None
    return {
        "title": json.loads(open("info.json").read())["displayName"],
        "run_args": [event, from_date, to_date, location],
        "html": html,
        "webview_transparent_background": True,
    }
Esempio n. 10
0
def results(fields, original_query):
    from dark_mode import dark_mode
    items = menu_items()
    if items != None:
        # remove submenus from results:
        menus = set((i.parent_path() for i in items))
        items = [i for i in items if i.full_path() + u"/" not in menus]
        # filter items:
        if '~item' in fields:
            query = fields['~item']
            for item in items:
                item.score = item.match_score(query)
            items = [item for item in items if item.score > 0]
            items.sort(key=lambda x: -x.score)
        # truncate items:
        n_more = max(0, len(items) - 10)
        if n_more:
            items = items[:-n_more]
        # generate html:
        html = u"""
		<style>
		body {
			padding: 0;
			margin: 0;
			font-family: "HelveticaNeue";
		}
		body.dark {
			color: white;
		}
		body.light {
			color: black;
		}
		ol {
			list-style-type: none;
			padding: 0;
			cursor: default;
		}
		ol#items > li {
			border-bottom: 1px solid rgba(120,120,120,0.2);
			padding: 0.5em;
			font-size: small;
		}
		ol#items > li:last-child {
			border-bottom: none;
		}
		ol.path {
			display: inline;
		}
		ol.path > li {
			display: inline-block;
			opacity: 0.6;
		}
		ol.path > li:after {
			content: "⟩";
			display: inline-block;
			padding-left: 0.5em;
			padding-right: 0.5em;
			opacity: 0.7;
		}
		.title {
			font-weight: bold;
		}
		.nmore {
			text-align: center;
			font-size: small;
			opacity: 0.5;
		}
		
		ol#items > li:first-child {
			background-color: rgba(125, 125, 125, 0.3);
		}
		
		/*ol#items:not(:hover) > li:first-child, ol#items:hover > li:hover {
			background-color: rgba(125, 125, 125, 0.3);
		}*/
		
		</style>
		
		<ol id='items'>
		<!--ITEMS-->
		</ol>
		""".replace(u"<!--ITEMS-->",
              u"".join([i.html() for i in items
                        ])).replace("<!--COLOR-->",
                                    ("dark" if dark_mode() else "light"))
        if n_more:
            html += u"<p class='nmore'>{0} more...</p>".format(n_more)
    else:
        from centered_text import centered_text
        html = centered_text("""
		<style>
		p {
			margin: 10px;
			font-size: 15px;
		}
		</style>
		<p>Spotlight needs accessibility permissions to search menu items.</p>
		<p><img src='settings.png' style='max-width: 250px'/></p>
		<p><button onclick="flashlight.bash('open /System/Library/PreferencePanes/Security.prefPane')">Open Privacy Settings</button></p>
		""")
    d = {
        "title": "Search menu items",
        "html": html,
        "webview_transparent_background": True
    }
    if items and len(items) > 0:
        d['run_args'] = [items[0].applescript]
    return d