37 |
37 |
38 # test |
38 # test |
39 TITLE = u"Hello World" |
39 TITLE = u"Hello World" |
40 |
40 |
41 def process (self) : |
41 def process (self) : |
42 self.color = ( |
42 if self.request.method == 'POST' : |
43 self.request.form.get('r'), |
43 self.color = tuple((int(x, 16) if x else 0) for x in ( |
44 self.request.form.get('g'), |
44 self.request.form.get('r'), |
45 self.request.form.get('b'), |
45 self.request.form.get('g'), |
46 ) |
46 self.request.form.get('b'), |
|
47 )) |
47 |
48 |
48 self.color = tuple((int(x, 16) if x else None) for x in self.color) |
|
49 |
|
50 if self.request.method == 'POST' : |
|
51 r, g, b = self.color |
49 r, g, b = self.color |
52 |
50 |
53 self.app.dmx_color(r, g, b, 255) |
51 self.app.dmx_color(r, g, b, 255) |
54 |
52 |
|
53 else : |
|
54 self.color = None |
|
55 |
55 log.info("%s", self.color) |
56 log.info("%s", self.color) |
56 |
57 |
57 def render (self) : |
58 def render (self) : |
58 r, g, b = self.color |
59 if self.color : |
|
60 r, g, b = self.color |
|
61 else : |
|
62 r = g = b = None |
59 |
63 |
60 def color_input (name, value) : |
64 def color_input (name, value) : |
61 color = dict(r=0, g=0, b=0) |
65 color = dict(r=0, g=0, b=0) |
62 bgcolor = dict(r=0, g=0, b=0) |
66 bgcolor = dict(r=0, g=0, b=0) |
63 |
67 |
64 if value : |
68 if value : |
65 color[name] = value |
69 color[name] = value |
|
70 alpha = value / 2 |
|
71 else : |
|
72 alpha = 0 |
|
73 |
66 bgcolor[name] = 255 |
74 bgcolor[name] = 255 |
67 |
75 |
68 return html.input(type='text', name=name, class_='form-control', placeholder=name, |
76 return html.input(type='text', name=name, class_='form-control', placeholder=name, |
69 value = '{:02x}'.format(value), |
77 value = '{v:02x}'.format(v=value) if value else None, |
70 #style = 'background-color: #{r:02x}{g:02x}{b:02x}'.format(**color), |
78 #style = 'background-color: #{r:02x}{g:02x}{b:02x}'.format(**color), |
71 style = 'background-color: rgba({r}, {g}, {b}, {a})'.format(a=value, **bgcolor), |
79 style = 'background-color: rgba({r}, {g}, {b}, {a})'.format(a=alpha, **bgcolor), |
72 ) |
80 ) |
73 |
81 |
74 return html.div(class_='container')( |
82 return html.div(class_='container')( |
75 html.div(class_='panel')( |
83 html.div(class_='panel')( |
76 html.form(action='.', method='POST', class_='form-horizontal')( |
84 html.form(action='.', method='POST', class_='form-horizontal')( |
97 |
105 |
98 self.dmx = dmx |
106 self.dmx = dmx |
99 |
107 |
100 def dmx_color (self, r, g, b, a=255) : |
108 def dmx_color (self, r, g, b, a=255) : |
101 for c in (1, 30) : |
109 for c in (1, 30) : |
|
110 # XXX: this is four separate commands... each one flushes... |
102 self.dmx[c + 0:c + 26:3] = r |
111 self.dmx[c + 0:c + 26:3] = r |
103 self.dmx[c + 1:c + 26:3] = g |
112 self.dmx[c + 1:c + 26:3] = g |
104 self.dmx[c + 2:c + 26:3] = b |
113 self.dmx[c + 2:c + 26:3] = b |
105 self.dmx[c + 28] = 255 |
114 self.dmx[c + 28] = 255 |
106 |
115 |