qmsk/dmx/heads.py
changeset 95 478b9d0485aa
parent 88 c923295ee520
equal deleted inserted replaced
94:28ae9bc41c63 95:478b9d0485aa
     1 """
     1 """
     2     High-level DMX output.
     2     High-level DMX output.
     3 """
     3 """
     4 
     4 
     5 class Head (object) :
     5 class Head :
     6     CHANNELS = None
     6     CHANNELS = None
     7 
     7 
     8     def __init__ (self, channel) :
     8     def __init__ (self, channel) :
     9         self.channel = channel
     9         self.channel = channel
    10         self.channels = self.init()
    10         self.channels = self.init()
    76         'control',
    76         'control',
    77         'alpha',
    77         'alpha',
    78     ]
    78     ]
    79 
    79 
    80 
    80 
    81 class Universe (object) :
    81 class Universe :
    82     """
    82     """
    83         An universe of Heads for DMX output.
    83         An universe of Heads for DMX output.
    84     """
    84     """
    85 
    85 
    86     def __init__ (self, dmx, heads) :
    86     def __init__ (self, heads, dmx=None) :
       
    87         self.heads = heads
    87         self.dmx = dmx
    88         self.dmx = dmx
    88         self.heads = heads
       
    89 
    89 
    90     def __getitem__ (self, name) :
    90     def __getitem__ (self, name) :
    91         return self.heads[name]
    91         return self.heads[name]
    92 
    92 
    93     def __iter__ (self) :
    93     def __iter__ (self) :
    94         return self.heads.iteritems()
    94         return iter(self.heads.items())
    95 
    95 
    96     def update (self, head, attrs) :
    96     def update (self, head, attrs) :
    97         """
    97         """
    98             Update per-head values..
    98             Update per-head values..
    99         """
    99         """
   100 
   100 
   101         for attr, value in attrs.iteritems():
   101         for attr, value in attrs.items():
   102             head[attr] = value
   102             head[attr] = value
   103         
   103         
   104         # output
   104         # output
   105         self.dmx.set(head.channel, *head)
   105         if self.dmx:
       
   106             self.dmx.set(head.channel, *head)
   106 
   107