--- a/qmsk/dmx/web.py Fri Apr 11 21:45:26 2014 +0300
+++ b/qmsk/dmx/web.py Fri Apr 11 22:22:11 2014 +0300
@@ -39,23 +39,27 @@
TITLE = u"Hello World"
def process (self) :
- self.color = (
- self.request.form.get('r'),
- self.request.form.get('g'),
- self.request.form.get('b'),
- )
+ if self.request.method == 'POST' :
+ self.color = tuple((int(x, 16) if x else 0) for x in (
+ self.request.form.get('r'),
+ self.request.form.get('g'),
+ self.request.form.get('b'),
+ ))
- self.color = tuple((int(x, 16) if x else None) for x in self.color)
-
- if self.request.method == 'POST' :
r, g, b = self.color
self.app.dmx_color(r, g, b, 255)
+ else :
+ self.color = None
+
log.info("%s", self.color)
def render (self) :
- r, g, b = self.color
+ if self.color :
+ r, g, b = self.color
+ else :
+ r = g = b = None
def color_input (name, value) :
color = dict(r=0, g=0, b=0)
@@ -63,12 +67,16 @@
if value :
color[name] = value
+ alpha = value / 2
+ else :
+ alpha = 0
+
bgcolor[name] = 255
return html.input(type='text', name=name, class_='form-control', placeholder=name,
- value = '{:02x}'.format(value),
+ value = '{v:02x}'.format(v=value) if value else None,
#style = 'background-color: #{r:02x}{g:02x}{b:02x}'.format(**color),
- style = 'background-color: rgba({r}, {g}, {b}, {a})'.format(a=value, **bgcolor),
+ style = 'background-color: rgba({r}, {g}, {b}, {a})'.format(a=alpha, **bgcolor),
)
return html.div(class_='container')(
@@ -99,6 +107,7 @@
def dmx_color (self, r, g, b, a=255) :
for c in (1, 30) :
+ # XXX: this is four separate commands... each one flushes...
self.dmx[c + 0:c + 26:3] = r
self.dmx[c + 1:c + 26:3] = g
self.dmx[c + 2:c + 26:3] = b