-
Notifications
You must be signed in to change notification settings - Fork 0
/
telopselector
executable file
·70 lines (58 loc) · 1.74 KB
/
telopselector
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
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from __future__ import print_function
import sys
try:
import ujson as json
except ImportError:
try:
import simplejson as json
except:
import json
from gi.repository import Gtk
class Group(list):
def loadArgs(self, args):
for arg in args:
if arg == 'off':
self.append(["off"])
else:
elems = arg.split(',')
self.append(elems)
def A(self, idx):
t, f = [], []
for i, elem in enumerate(self):
e = [ e for e in elem if e != "off" ]
if i == idx:
t.extend(e)
else:
f.extend(e)
return t, f
class Window(Gtk.Window):
def __init__(self, group):
Gtk.Window.__init__(self, title="Telop Selector")
self.group = group
self.set_border_width(10)
self.connect("delete-event", Gtk.main_quit)
hbox = Gtk.Box(spacing=6)
self.add(hbox)
bb = None
for i, g in enumerate(group):
b = Gtk.RadioButton.new_with_label_from_widget(bb, ",".join(g))
if bb is None: bb = b
b.connect('clicked', self.on_toggled, i)
hbox.pack_start(b, False, False, 0)
def on_toggled(self, button, idx):
if button.get_active():
showno_list, hideno_list = self.group.A(idx)
data = { 'shows': showno_list, 'hides': hideno_list }
sys.stdout.write(json.dumps(data))
sys.stdout.write("\0")
sys.stdout.flush()
def main(args):
group = Group()
group.loadArgs(args)
window = Window(group)
window.show_all()
Gtk.main()
if __name__ == '__main__':
main(sys.argv[1:])