forked from albertlauncher/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
63 lines (52 loc) · 1.93 KB
/
__init__.py
File metadata and controls
63 lines (52 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# -*- coding: utf-8 -*-
"""
Displays a color parsed from name, which may be in one of these formats:
* #RGB (each of R, G, and B is a single hex digit)
* #RRGGBB
* #AARRGGBB
* #RRRGGGBBB
* #RRRRGGGGBBBB
* A name from the list of colors defined in the list of SVG color keyword
names provided by the World Wide Web Consortium; for example, "steelblue"
or "gainsboro".
Note: This extension started as a prototype to test the internal color pixmap
generator. However it may serve as a starting point for people having a real
need for color workflows. PR's welcome.
"""
from albert import *
from urllib.parse import quote_plus
from string import hexdigits
md_iid = '2.0'
md_version = '1.0'
md_name = 'Color'
md_description = 'Display color for color codes'
md_license = 'MIT'
md_url = 'https://github.com/albertlauncher/python/color'
class Plugin(PluginInstance, GlobalQueryHandler):
def __init__(self):
GlobalQueryHandler.__init__(self,
id=md_id,
name=md_name,
description=md_description,
defaultTrigger='#')
PluginInstance.__init__(self, extensions=[self])
def handleGlobalQuery(self, query):
rank_items = []
s = query.string.strip()
if s:
if s.startswith('#'): # remove hash
s = s[1:]
# check length and hex
if any([len(s) == l for l in [3, 6, 8, 9, 12]]) and all(c in hexdigits for c in s):
rank_items.append(
RankItem(
StandardItem(
id=md_id,
text=s,
subtext="The color for this code.",
iconUrls=[f"gen:?background=%23{s}"],
),
1
)
)
return rank_items