qmsk/dmx/web.py
changeset 84 9ebf1a2cee3a
parent 83 136e210fce82
equal deleted inserted replaced
83:136e210fce82 84:9ebf1a2cee3a
    21 def color_input (head, c, value) :
    21 def color_input (head, c, value) :
    22     color = dict(red=0, green=0, blue=0, alpha=0)
    22     color = dict(red=0, green=0, blue=0, alpha=0)
    23 
    23 
    24     color[c] = 255
    24     color[c] = 255
    25     if value :
    25     if value :
    26         color[alpha] = value / 255.0
    26         color['alpha'] = value / 255.0
    27 
    27 
    28     return colorize(input(head, c, value), **color)
    28     return colorize(input(head, c, value), **color)
    29 
    29 
    30 def slider (head, name) :
    30 def slider (head, name) :
    31     return html.div(id='-'.join([head, name, 'slider']), class_='dmx-slider dmx-slider-{name}'.format(name=name))
    31     return html.div(id='-'.join([head, name, 'slider']), class_='dmx-slider dmx-slider-{name}'.format(name=name))
    59     # test
    59     # test
    60     TITLE = u"DMX Control"
    60     TITLE = u"DMX Control"
    61 
    61 
    62     def process (self) :
    62     def process (self) :
    63         if self.request.method == 'POST' :
    63         if self.request.method == 'POST' :
    64             # XXX
    64             for name, value in self.request.form.iteritems() :
    65             r, g, b = tuple((int(x, 16) if x else 0) for x in (
    65                 head_name, attr = name.split('-', 1)
    66                     self.request.form.get('r'),
    66                 head = self.app.heads[head_name]
    67                     self.request.form.get('g'),
       
    68                     self.request.form.get('b'),
       
    69             ))
       
    70 
    67 
    71             self.app.dmx_color(r, g, b, 255)
    68                 if value :
       
    69                     value = int(value)
       
    70                     
       
    71                     # update head
       
    72                     head[attr] = value
       
    73 
       
    74             # update dmx
       
    75             self.app.update() 
    72 
    76 
    73     def render_head (self, name, head) :
    77     def render_head (self, name, head) :
    74         if head.alpha() is None :
    78         if head.alpha() is None :
    75             head_input = head_slider = None
    79             head_input = head_slider = None
    76         else :
    80         else :
   129     def __init__ (self, dmx, heads, **opts) :
   133     def __init__ (self, dmx, heads, **opts) :
   130         super(DMXWebApplication, self).__init__(**opts)
   134         super(DMXWebApplication, self).__init__(**opts)
   131 
   135 
   132         self.dmx = dmx
   136         self.dmx = dmx
   133         self.heads = heads
   137         self.heads = heads
       
   138 
       
   139     def update (self) :
       
   140         if not self.dmx :
       
   141             return
       
   142 
       
   143         for head in self.heads.itervalues() :
       
   144             self.dmx[head.channel] = tuple(head)
       
   145