-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdbus_connector.py
executable file
·67 lines (52 loc) · 1.66 KB
/
dbus_connector.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
#!/usr/bin/env python3
import dbus
import dbus.mainloop.glib
import cmd
class DBUSBlinkConnector:
def __init__(self):
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = dbus.SessionBus()
obj = bus.get_object("de.ch.blink", "/de/ch/blink")
self.iface = dbus.Interface(obj, dbus_interface="de.ch.blink")
class Prompt(cmd.Cmd):
prompt = '> '
def do_add(self, line):
idx = connector.iface.add_to_playlist(line)
if idx == -1:
print("ERR")
else:
print("OK. ID: %d" % idx)
def help_add(self):
print("Adds a file to the playlist.")
def do_load_file(self, line):
line = line.split(" ")
connector.iface.load_clip(*line)
print("OK")
def help_load_file(self):
print("Loads a .bml file to the storage")
def do_clear(self, line):
connector.iface.clear()
print("OK")
def do_remove(self, line):
try:
i = int(line)
except ValueError:
print("ERR")
ret = connector.iface.remove_from_playlist(i)
if ret:
print("OK")
else:
print("ERR")
def do_show(self, line):
items = [str(x) for x in list(connector.iface.get_playlist())]
for item in items:
print(item)
def do_show_clips(self, line):
clips = [str(x) for x in list(connector.iface.get_available_clips())]
for c in clips:
print(c)
def help_load_file(self):
print("Reads a file and adds it to the list of available clips.")
if __name__ == '__main__':
connector = DBUSBlinkConnector()
Prompt().cmdloop()