Changeset - 460bc5ebcaaf
[Not reviewed]
default
0 2 0
David McClosky - 20 years ago 2005-06-17 07:00:51
dmcc@bigasterisk.com
gyrocontroller can use patch names, Submasters gets get_all_sub_names()
2 files changed with 18 insertions and 2 deletions:
0 comments (0 inline, 0 general)
bin/gyrocontroller
Show inline comments
 
#!/usr/bin/env python
 
# vi: syntax=python
 

	
 
import run_local
 
from light9.Submaster import Submasters, Submaster, combine_subdict
 
from light9.subclient import SubClient
 
import light9.Patch as Patch
 

	
 
import Tix as Tk
 

	
 
# TODO: move to Utility?
 
class circcycle:
 
    """Like itertools.cycle, but with a prev() method too.  You lose
 
@@ -45,18 +46,31 @@ class AbstractSimpleController(SubClient
 
    Triple-B2: clear kept levels"""
 
    def __init__(self, subnames):
 
        SubClient.__init__(self)
 
        self.subnames = subnames
 
        self.refresh()
 
    def get_sub(self, name):
 
        if name in self.submasters.get_all_sub_names():
 
            return self.submasters.get_sub_by_name(name)
 

	
 
        try:
 
            val = int(name)
 
            s = Submaster("Ch%d" % val, {val : 1.0}, temporary=True)
 
            s = Submaster("#%d" % val, {val : 1.0}, temporary=True)
 
            return s
 
        except ValueError:
 
            return self.submasters.get_sub_by_name(name)
 
            pass
 

	
 
        try:
 
            subnum = Patch.get_dmx_channel(name)
 
            s = Submaster("'%s'" % name, {subnum : 1.0}, temporary=True)
 
            return s
 
        except ValueError:
 
            pass
 

	
 
        # make an error sub
 
        return Submaster('%s!?' % name)
 
    def refresh(self):
 
        # reload subs from disk
 
        self.submasters = Submasters()
 
        self.all_subs = circcycle(self.subnames)
 
        self.current_sub = self.get_sub(self.all_subs.next())
 
        self.current_level = 1.0
light9/Submaster.py
Show inline comments
 
@@ -170,12 +170,14 @@ class Submasters:
 
            if s.name.startswith('song'):
 
                songs.append(s)
 
            else:
 
                notsongs.append(s)
 
        combined = notsongs + songs
 
        return combined
 
    def get_all_sub_names(self):
 
        return [s.name for s in self.get_all_subs()]
 
    def get_sub_by_name(self, name):
 
        "Makes a new sub if there isn't one."
 
        return self.submasters.get(name, Submaster(name))
 
    __getitem__ = get_sub_by_name
 

	
 
if __name__ == "__main__":
0 comments (0 inline, 0 general)