Various work on certificate handling for screens; need XML config here, now.
[dcpomatic.git] / hacks / python-playback / screens.py
1 #!/usr/bin/python
2
3 class Screen:
4     def __init__(self):
5         self.name = None
6         self.formats = []
7
8 class Format:
9     def __init__(self):
10         self.ratio = None
11         self.x = None
12         self.y = None
13         self.width = None
14         self.height = None
15         self.external = False
16
17 class Screens:
18     def __init__(self, file):
19
20         self.screens = []
21
22         f = open(file, 'r')
23         current_screen = None
24         current_format = None
25         while 1:
26             l = f.readline()
27             if l == '':
28                 break
29             if len(l) > 0 and l[0] == '#':
30                 continue
31
32             s = l.strip()
33
34             if len(s) == 0:
35                 continue
36
37             b = s.split()
38
39             if len(b) != 2:
40                 print "WARNING: ignored line `%s' in screens file" % (s)
41                 continue
42
43             if b[0] == 'screen':
44                 if current_format is not None:
45                     current_screen.formats.append(current_format)
46                     current_format = None
47
48                 if current_screen is not None:
49                     self.screens.append(current_screen)
50                     current_screen = None
51                 
52                 current_screen = Screen()
53                 current_screen.name = b[1]
54             elif b[0] == 'ratio':
55                 if current_format is not None:
56                     current_screen.formats.append(current_format)
57                     current_format = None
58                     
59                 current_format = Format()
60                 current_format.ratio = float(b[1])
61             elif b[0] == 'x':
62                 current_format.x = int(b[1])
63             elif b[0] == 'y':
64                 current_format.y = int(b[1])
65             elif b[0] == 'width':
66                 current_format.width = int(b[1])
67             elif b[0] == 'height':
68                 current_format.height = int(b[1])
69             elif b[0] == 'external':
70                 current_format.external = int(b[1]) == 1
71
72         if current_format is not None:
73             current_screen.formats.append(current_format)
74
75         if current_screen is not None:
76             self.screens.append(current_screen)
77
78     def get_format(self, screen, ratio):
79         for s in self.screens:
80             if s.name == screen:
81                 for f in s.formats:
82                     if f.ratio == ratio:
83                         return f
84
85         return None