-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathItems.py
75 lines (64 loc) · 2.53 KB
/
Items.py
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
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# ------------------------------------------------
# Author: Konfido <[email protected]>
# Created Date: July 27th 2020
# ------------------------------------------------
import json
import sys
from Utils import Utils as U
class Items():
""" To generate Script Filter item """
def __init__(self):
self.items = []
self.item = {
# "title": "xxx", # str, title
# "subtitle": "xxx", # str, subtitle
# "arg": "xxx", # str, arg parsed to next
# "type": "xxx", # str, file
# "autocomplete": "xxx", # str, auto completed after enter
# "icon": {
# "type": "xxx", # str, "fileicon" | "image"
# "path": "xxx" # str, path to file/image
# },
# "mods": {
# "xxx": { # str, "alt" | "cmd" | "shift" | "ctrl" | "fn"
# "valid": "xxx", # boolean, validity of the mod
# "arg": "xxx", # str, return to next
# "subtitle": "xxx" # str, subtitle showed under mod
# }
# "quicklookurl": "xxx" # str, relative/abs path
# }
}
def add_item(self, arg):
""" Allowed arg structure: int/float/str/dict/list/tuple """
if isinstance(arg, list) or isinstance(arg, tuple):
for i in arg:
self.add_item(i)
elif isinstance(arg, dict):
self.items.append(arg)
else:
try:
self.items.append({"title": arg})
except Exception as e:
self.items.append({"title": "Exception!", "subtitle": e})
def add_mod_all(self, mod, arg, subtitle, valid=True, icon_type="", icon_path=""):
""" Add one mod to self.items """
para = {"arg": arg, "subtitle": subtitle, "valid": valid}
icon = {"icon_type": icon_type, "icon_path": icon_path}
for item in self.items:
item["mods"].update({mod: para})
item.update({"icon": icon})
def write(self):
""" Generate Script Filter Output """
out = json.dumps({"items": self.items})
sys.stdout.write(out)
class Display():
""" Customize SrciptFilter to show specific content """
@staticmethod
def show(*args):
""" Send common messages to script filter """
I = Items()
for arg in args:
I.add_item(arg)
I.write()