Skip to content

Commit

Permalink
Added support for on-the-fly image creation
Browse files Browse the repository at this point in the history
  • Loading branch information
zensoup committed May 7, 2019
1 parent fbfba8d commit 50f31ec
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
images/cache/*
1 change: 1 addition & 0 deletions generate_master_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def locate_block(code):
num = int(code, 16)
except ValueError:
print('could not convert ' + code)
continue
index = locate_block(num)
if index is not None:
target.write(name + '\t' + code + '\t' + blocks[index] + '\n')
Expand Down
26 changes: 26 additions & 0 deletions images/unicode.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 49 additions & 14 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import sys
sys.path.append('/home/zen/.local/lib/python2.7/site-packages/')

sys.path.append("/home/zen/.local/lib/python2.7/site-packages/")

import os
import codecs
from fuzzywuzzy import process

from ulauncher.api.client.Extension import Extension
Expand All @@ -13,27 +15,28 @@
from ulauncher.api.shared.action.HideWindowAction import HideWindowAction


class DemoExtension(Extension):
FILE_PATH = os.path.dirname(sys.argv[0])


class UnicodeCharExtension(Extension):
def __init__(self):
super(DemoExtension, self).__init__()
super(UnicodeCharExtension, self).__init__()
self.subscribe(KeywordQueryEvent, KeywordQueryEventListener())


class KeywordQueryEventListener(EventListener):

def __init__(self):
f = open(os.path.dirname(sys.argv[0]) + '/unicode_list.txt', 'r')
f = open(os.path.dirname(sys.argv[0]) + "/unicode_list.txt", "r")
data = f.readlines()
self.data = {}
# self.names = []
self.items = []
# self.blocks = []
for item in data:
item = item.strip()
name, code, block = item.split('\t')
self.data[name + ' ' + block] = (name, block, code)
self.items.append(name + ' ' + block)
name, code, block = item.split("\t")
self.data[name + " " + block] = (name, block, code)
self.items.append(name + " " + block)
# self.names.append(name)
# self.blocks.append(block)

Expand All @@ -42,14 +45,46 @@ def on_event(self, event, extension):
arg = event.get_argument()
if arg:
matches = process.extract(arg, self.items, limit=15)

for m in matches:
name, block, code = self.data[m[0]]
items.append(ExtensionResultItem(icon='images/bookmark.svg',
name=name + ' - ' + unichr(int(code, 16)),
description=block,
on_enter=CopyToClipboardAction(unichr(int(code, 16)))))
image_path = self.create_icon_image(code)
items.append(
ExtensionResultItem(
icon=image_path,
name=name + " - " + unichr(int(code, 16)),
description=block,
on_enter=CopyToClipboardAction(unichr(int(code, 16))),
)
)

return RenderResultListAction(items)

if __name__ == '__main__':
DemoExtension().run()
def create_icon_image(self, code):
path = sys.argv[0] + "images/cache/icon_%s.svg" % code
if os.path.isfile(path):
return path
return create_character_icon(code)


def load_icon_template():
with open(os.path.join(FILE_PATH, "images/unicode.svg"), "r") as i:
return i.read()


def is_icon_cached(code):
return os.path.isfile(os.path.join(FILE_PATH, "images/cache/icon_%s.svg" % code))


def create_character_icon(code, font='sans-serif'):
template = load_icon_template()
icon = template.replace("{symbol}", unichr(int(code, 16))).replace('{font}', font)
with codecs.open(
os.path.join(FILE_PATH, "images/cache/icon_%s.svg" % code), "w", "utf-8"
) as target:
target.write(icon)
return os.path.join(FILE_PATH, "images/cache/icon_%s.svg" % code)


if __name__ == "__main__":
UnicodeCharExtension().run()
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"developer_name": "John Doe",
"icon": "images/bookmark.svg",
"options": {
"query_debounce": 0.1
"query_debounce": 0.5
},
"preferences": [
{
Expand Down
2 changes: 0 additions & 2 deletions unicode_list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,6 @@ bernoulli function 212C Letterlike Symbols
BET SYMBOL 2136 Letterlike Symbols
BETA SYMBOL, GREEK 03D0 Greek and Coptic
beta, curled 03D0 Greek and Coptic
Betty BOOP Greek and Coptic
BETWEEN 226C Mathematical Operators
Beverage Symbols 1F375 Miscellaneous Symbols and Pictographs
BEVERAGE, HOT 2615 Miscellaneous Symbols
Expand Down Expand Up @@ -5449,7 +5448,6 @@ Thai Digits 0E50 Thai
Thai Marks and Signs 0E48 Thai
Thai Vowels 0E30 Thai
THANTHAKHAT, THAI CHARACTER 0E4C Thai
the DOOD Thai
theater masks 1F3AD Miscellaneous Symbols and Pictographs
THERE DOES NOT EXIST 2204 Mathematical Operators
THERE EXISTS 2203 Mathematical Operators
Expand Down

0 comments on commit 50f31ec

Please sign in to comment.