forked from ASPP/pelita
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tkviewer.py
executable file
·47 lines (39 loc) · 1.33 KB
/
tkviewer.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
try:
import argparse
except ImportError:
from pelita.compat import argparse
from pelita.ui.tk_viewer import TkViewer
def geometry_string(s):
"""Get a X-style geometry definition and return a tuple.
600x400 -> (600,400)
"""
try:
x_string, y_string = s.split('x')
geometry = (int(x_string), int(y_string))
except ValueError:
msg = "%s is not a valid geometry specification" %s
raise argparse.ArgumentTypeError(msg)
return geometry
parser = argparse.ArgumentParser(description='Open a Tk viewer')
parser.add_argument('subscribe_sock', metavar="URL", type=str,
help='subscribe socket')
parser.add_argument('--controller-address', metavar="URL", type=str,
help='controller address')
parser.add_argument('--geometry', type=geometry_string,
help='geometry')
parser.add_argument('--delay', type=int,
help='delay')
def run_viewer():
args = parser.parse_args()
tkargs = {
'address': args.subscribe_sock,
'controller_address': args.controller_address,
'geometry': args.geometry,
'delay': args.delay
}
v = TkViewer(**dict((k, v) for k, v in tkargs.items() if v is not None))
v.run()
if __name__ == '__main__':
run_viewer()