-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
53 lines (40 loc) · 2.13 KB
/
main.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
import os
from ulauncher.api.client.Extension import Extension
from ulauncher.api.client.EventListener import EventListener
from ulauncher.api.shared.event import KeywordQueryEvent, ItemEnterEvent
from ulauncher.api.shared.item.ExtensionResultItem import ExtensionResultItem
from ulauncher.api.shared.action.RenderResultListAction import RenderResultListAction
from ulauncher.api.shared.action.OpenAction import OpenAction
from ulauncher.api.shared.action.RunScriptAction import RunScriptAction
rfile_name = "recent-files.txt"
class BlenderExtension(Extension):
def __init__(self):
super(BlenderExtension, self).__init__()
self.subscribe(KeywordQueryEvent, KeywordQueryEventListener())
class KeywordQueryEventListener(EventListener):
def on_event(self, event, extension):
query = event.get_argument() or str()
bl_config = os.path.join(os.environ["HOME"], ".config", "blender")
recent_files = []
blapp = extension.preferences["start"]
if os.path.exists(blapp) and len(query) < 1:
recent_files.append([blapp, "Blender", "Start New File", ""])
for i in os.listdir(bl_config):
fn = os.path.join(bl_config, i, "config", rfile_name)
if not os.path.exists(fn): continue
with open(fn) as f:
for j in f.readlines():
j = j.strip()
if len(query) > 0 and query.lower() not in j.lower():
continue
recent_files.append([j, os.path.basename(j), os.path.dirname(j), "2" if os.path.exists(j) else "3"])
items = [ExtensionResultItem(icon='images/icon{}.png'.format(icon_no),
name=f_name,
description=dir_name,
on_enter=OpenAction(path) if f_name != "Blender" else RunScriptAction(path)
)
for path, f_name, dir_name, icon_no in recent_files
]
return RenderResultListAction(items)
if __name__ == '__main__':
BlenderExtension().run()