Skip to content

Commit

Permalink
Use font
Browse files Browse the repository at this point in the history
  • Loading branch information
Garulf committed Jan 2, 2022
1 parent 08675ee commit ed5fa8a
Showing 1 changed file with 37 additions and 28 deletions.
65 changes: 37 additions & 28 deletions plugin/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,67 @@
import os
import webbrowser
from pathlib import Path
from difflib import SequenceMatcher as sm


from flox import Flox, Clipboard
from flox import Flox, Clipboard, ICON_BROWSER


META_FILE = "meta.json"
META_PATH = Path(Path.cwd(), META_FILE)
META_PATH = Path(Path.cwd(), 'plugin', META_FILE)
MAX_RESULTS = 100
MDI_URL = "https://materialdesignicons.com/icon/"


class MDI(Flox):
class MDI(Flox, Clipboard):
def __init__(self):
with open(META_PATH, "r") as f:
self.icons = json.load(f)
super().__init__()

def filter(self, icon):

self.add_item(
title=icon["name"],
subtitle="Press ENTER to copy to clipboard (SHIFT+ENTER for more options)",
icon=self.create_icon(icon["name"]),
context=[icon["name"]],
method="copy_to_clipboard",
parameters=[icon["name"]],
)

def context_menu(self, data):
name = data[0]
self.add_item(
title="View icon on website",
subtitle=f"{MDI_URL}{data[0]}",
icon=self.create_icon("web"),
subtitle=f"{MDI_URL}{name}",
icon=ICON_BROWSER,
method="open_web",
parameters=[data[0]],
)
return self._results

def query(self, query):
# names = [icon['name'] for icon in icons['icons']]
q = query.lower()

for icon in self.icons["icons"]:
self.add_item(
title=icon["name"],
)

def codepoint_to_char(self, codepoint):
return chr(int(codepoint, 16))

return self._results
def match(self, query, icon_name, aliases):
query = query.lower()
score = []
for alias in aliases:
_ = sm(lambda x: x==" " or x=="-", query, alias.lower())
score.append(_.ratio() * 100)
_ = sm(lambda x: x==" " or x=="-", query, icon_name.lower())
score.append(_.ratio() * 100)
return max(score)

def copy_to_clipboard(self, icon_name):
pyperclip.copy(icon_name)
def query(self, query):
for icon in self.icons:
score = self.match(query, icon["name"], icon['aliases'])
if score > 50 or query == '':
self.add_item(
title=icon["name"],
subtitle=", ".join(icon['aliases']),
glyph=self.codepoint_to_char(icon["codepoint"]),
font_family=str(
Path(self.plugindir).joinpath(
'plugin',
"#Material Design Icons Desktop"
)
),
score=int(score),
context=[icon["name"]],
method=self.put,
parameters=[icon["name"]],
)

def open_web(self, icon_name):
webbrowser.open(f"{MDI_URL}{icon_name}")
Expand Down

0 comments on commit ed5fa8a

Please sign in to comment.