233.1.2
by Ulrik Sverdrup
mini: command line interface to kupfer |
1 |
import sys |
2 |
import gobject |
|
3 |
||
4 |
from kupfer import data |
|
5 |
from kupfer import objects |
|
6 |
from kupfer import extensions |
|
7 |
import debug |
|
8 |
||
9 |
class Test (object): |
|
10 |
def __init__(self, dc): |
|
11 |
dc.connect("search-result", self.got_result) |
|
12 |
dc.connect("predicate-result", self.got_predicates) |
|
13 |
dc.connect("launched-action", self.cont) |
|
14 |
self.Leaf = None |
|
15 |
self.Action = None |
|
16 |
self.dc = dc |
|
17 |
||
18 |
def cont(self, sender, leaf, action): |
|
19 |
gobject.idle_add(self.loop) |
|
20 |
||
233.1.13
by Ulrik Sverdrup
mini: Update to "api" changes |
21 |
def got_predicates(self, sender, result, matchview, ctx): |
233.1.2
by Ulrik Sverdrup
mini: command line interface to kupfer |
22 |
for m in reversed(list(matchview)): |
23 |
print m |
|
24 |
if result: |
|
25 |
self.Action = result.object |
|
26 |
gobject.idle_add(self.loop) |
|
27 |
||
233.1.13
by Ulrik Sverdrup
mini: Update to "api" changes |
28 |
def got_result(self, sender, result, matchview, ctx): |
233.1.2
by Ulrik Sverdrup
mini: command line interface to kupfer |
29 |
for m in reversed(list(matchview)): |
30 |
print m |
|
31 |
obj = result and result.object or None |
|
32 |
self.Leaf = obj |
|
33 |
print obj |
|
34 |
gobject.idle_add(self.loop) |
|
35 |
||
36 |
def loop(self): |
|
37 |
try: |
|
38 |
key = raw_input("kupfer> ") |
|
39 |
except EOFError: |
|
40 |
raise SystemExit |
|
41 |
key = key.lower() |
|
42 |
parts = key.split(" ", 1) |
|
43 |
if self.Leaf and parts[0] == "a": |
|
44 |
if len(parts) > 1: |
|
45 |
key = parts[1] |
|
46 |
else: |
|
47 |
key = None |
|
48 |
dc.search_predicate(self.Leaf, key) |
|
49 |
elif key == "x" and self.Action: |
|
233.1.13
by Ulrik Sverdrup
mini: Update to "api" changes |
50 |
gobject.idle_add(self.dc.eval_action, self.Leaf, self.Action) |
233.1.2
by Ulrik Sverdrup
mini: command line interface to kupfer |
51 |
else: |
52 |
self.Leaf = None |
|
53 |
self.Action = None |
|
54 |
dc.search(key) |
|
55 |
print self.Leaf, self.Action |
|
56 |
||
57 |
def waiting(msg): |
|
58 |
print msg |
|
59 |
return True |
|
60 |
||
61 |
if __name__ == '__main__': |
|
62 |
import readline |
|
63 |
srcs = [] |
|
64 |
srcs.append(objects.FileSource(["/home/ulrik",], depth=1)) |
|
65 |
srcs.append(objects.AppSource()) |
|
66 |
srcs.append(extensions.screen.ScreenSessionsSource()) |
|
67 |
if len(srcs) == 1: |
|
68 |
src = srcs[0] |
|
69 |
else: |
|
70 |
src = objects.MultiSource(srcs) |
|
71 |
dc = data.DataController(src) |
|
72 |
print dc |
|
73 |
gobject.threads_init() |
|
74 |
gobject.set_application_name("kupfer-mini") |
|
75 |
t = Test(dc) |
|
76 |
||
77 |
gobject.idle_add(t.loop) |
|
78 |
ml = gobject.MainLoop() |
|
79 |
ml.run() |