Refactored mani.py
This commit is contained in:
parent
af0421e8df
commit
4c542c2d26
|
@ -8,8 +8,6 @@
|
||||||
version="1.1"
|
version="1.1"
|
||||||
id="svg8">
|
id="svg8">
|
||||||
<g
|
<g
|
||||||
inkscape:label="Layer 1"
|
|
||||||
inkscape:groupmode="layer"
|
|
||||||
id="layer1"
|
id="layer1"
|
||||||
transform="translate(-66.505356,-78.373996)">
|
transform="translate(-66.505356,-78.373996)">
|
||||||
<text
|
<text
|
||||||
|
|
Before Width: | Height: | Size: 1 KiB After Width: | Height: | Size: 998 B |
5
images/unicode2.svg
Normal file
5
images/unicode2.svg
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="28.73" height="29.16" viewBox="0 0 7.602 7.715">
|
||||||
|
<text style="line-height:125%;text-align:center" x="70.304" y="86.089" font-weight="400" font-size="10.583" font-family="sans-serif" letter-spacing="0" word-spacing="0" text-anchor="middle" stroke-width=".265" transform="translate(-66.505 -78.374)" textLength="100%">
|
||||||
|
<tspan x="70.304" y="86.089" font-family="{font}">{symbol}</tspan>
|
||||||
|
</text>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 462 B |
59
main.py
59
main.py
|
@ -3,6 +3,8 @@ 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 os
|
||||||
|
from os.path import join
|
||||||
|
import time
|
||||||
import codecs
|
import codecs
|
||||||
from ulauncher.search.SortedList import SortedList
|
from ulauncher.search.SortedList import SortedList
|
||||||
|
|
||||||
|
@ -14,9 +16,22 @@ from ulauncher.api.shared.action.RenderResultListAction import RenderResultListA
|
||||||
from ulauncher.api.shared.action.CopyToClipboardAction import CopyToClipboardAction
|
from ulauncher.api.shared.action.CopyToClipboardAction import CopyToClipboardAction
|
||||||
from ulauncher.api.shared.action.HideWindowAction import HideWindowAction
|
from ulauncher.api.shared.action.HideWindowAction import HideWindowAction
|
||||||
|
|
||||||
|
if sys.version_info[0] >= 3:
|
||||||
|
unichr = chr
|
||||||
|
|
||||||
FILE_PATH = os.path.dirname(sys.argv[0])
|
FILE_PATH = os.path.dirname(sys.argv[0])
|
||||||
|
|
||||||
|
class UnicodeChar:
|
||||||
|
def __init__(self, name, block, code):
|
||||||
|
self.name = name
|
||||||
|
self.block = block
|
||||||
|
self.code = code
|
||||||
|
self.character = unichr(int(code, 16))
|
||||||
|
|
||||||
|
def get_search_name(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
class SearchableItem:
|
class SearchableItem:
|
||||||
def __init__(self, name, item):
|
def __init__(self, name, item):
|
||||||
self._name = name
|
self._name = name
|
||||||
|
@ -33,45 +48,37 @@ class UnicodeCharExtension(Extension):
|
||||||
|
|
||||||
class KeywordQueryEventListener(EventListener):
|
class KeywordQueryEventListener(EventListener):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
print('======'*40)
|
self._load_character_table()
|
||||||
f = open(os.path.dirname(sys.argv[0]) + "/unicode_list.txt", "r")
|
|
||||||
data = f.readlines()
|
def _load_character_table(self):
|
||||||
self.data = {}
|
self.character_list = []
|
||||||
# self.names = []
|
with open(join(FILE_PATH, "unicode_list.txt"), "r") as f:
|
||||||
self.items = []
|
for line in f.readlines():
|
||||||
self.items_ = []
|
name, code, block = line.strip().split('\t')
|
||||||
# self.blocks = []
|
character = UnicodeChar(name, block, code)
|
||||||
for item in data:
|
self.character_list.append(character)
|
||||||
item = item.strip()
|
|
||||||
name, code, block = item.split("\t")
|
|
||||||
self.data[name + " " + block] = (name, block, code)
|
|
||||||
self.items.append(name + " " + block)
|
|
||||||
self.items_.append(SearchableItem(name , (name, block, code)))
|
|
||||||
# self.names.append(name)
|
|
||||||
# self.blocks.append(block)
|
|
||||||
|
|
||||||
def on_event(self, event, extension):
|
def on_event(self, event, extension):
|
||||||
items = []
|
items = []
|
||||||
arg = event.get_argument()
|
arg = event.get_argument()
|
||||||
if arg:
|
if arg:
|
||||||
|
|
||||||
m_ = SortedList(arg, min_score=60, limit=10)
|
m_ = SortedList(arg, min_score=60, limit=10)
|
||||||
m_.extend(self.items_)
|
m_.extend(self.character_list)
|
||||||
for m in m_:
|
for char in m_:
|
||||||
name, block, code = m._item
|
image_path = self._get_character_icon(char.code)
|
||||||
image_path = self.create_icon_image(code)
|
|
||||||
items.append(
|
items.append(
|
||||||
ExtensionResultItem(
|
ExtensionResultItem(
|
||||||
icon=image_path,
|
icon=image_path,
|
||||||
name=name + " - " + unichr(int(code, 16)),
|
name=char.name + " - " + char.character,
|
||||||
description=block,
|
description=char.block + " - " + char.code,
|
||||||
on_enter=CopyToClipboardAction(unichr(int(code, 16))),
|
on_enter=CopyToClipboardAction(char.character),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
return RenderResultListAction(items)
|
return RenderResultListAction(items)
|
||||||
|
|
||||||
def create_icon_image(self, code):
|
def _get_character_icon(self, code):
|
||||||
path = sys.argv[0] + "images/cache/icon_%s.svg" % code
|
path = sys.argv[0] + "images/cache/icon_%s.svg" % code
|
||||||
if os.path.isfile(path):
|
if os.path.isfile(path):
|
||||||
return path
|
return path
|
||||||
|
@ -79,7 +86,7 @@ class KeywordQueryEventListener(EventListener):
|
||||||
|
|
||||||
|
|
||||||
def load_icon_template():
|
def load_icon_template():
|
||||||
with open(os.path.join(FILE_PATH, "images/unicode.svg"), "r") as i:
|
with open(os.path.join(FILE_PATH, "images/unicode2.svg"), "r") as i:
|
||||||
return i.read()
|
return i.read()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue