Changeset - 3b73f0a58a54
[Not reviewed]
default
0 2 0
David McClosky - 20 years ago 2005-06-18 01:45:05
dmcc@bigasterisk.com
Move general use gyro function get_sub to Submaster, make global Submasters object
- gyro's error subs now look like normal subs since they might reload and turn
into good subs.
- Also, add Submaster.fullsub which helps you make subs from channel names.
2 files changed with 45 insertions and 20 deletions:
0 comments (0 inline, 0 general)
bin/gyrocontroller
Show inline comments
 
@@ -2,7 +2,8 @@
 
# vi: syntax=python
 

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

	
 
@@ -49,25 +50,7 @@ class AbstractSimpleController(SubClient
 
        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("#%d" % val, {val : 1.0}, temporary=True)
 
            return s
 
        except ValueError:
 
            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)
 
        return get_sub_by_name(name, self.submasters)
 
    def refresh(self):
 
        # reload subs from disk
 
        self.submasters = Submasters()
light9/Submaster.py
Show inline comments
 
@@ -187,6 +187,48 @@ class Submasters:
 
        return self.submasters.get(name, Submaster(name))
 
    __getitem__ = get_sub_by_name
 

	
 
def fullsub(*chans):
 
    """Make a submaster with chans at full."""
 
    return Submaster('%r' % chans,
 
        dict([(c, 1.0) for c in chans]), temporary=True)
 

	
 
# a global instance of Submasters, created on demand
 
_submasters = None
 

	
 
def get_global_submasters():
 
    """Get (and make on demand) the global instance of Submasters"""
 
    global _submasters
 
    if _submasters is None:
 
        _submasters = Submasters()
 
    return _submasters
 

	
 
def get_sub_by_name(name, submasters=None):
 
    """name is a channel or sub nama, submasters is a Submasters object.
 
    If you leave submasters empty, it will use the global instance of
 
    Submasters."""
 
    if not submasters:
 
        submasters = get_global_submasters()
 

	
 
    if name in submasters.get_all_sub_names():
 
        return submasters.get_sub_by_name(name)
 

	
 
    try:
 
        val = int(name)
 
        s = Submaster("#%d" % val, {val : 1.0}, temporary=True)
 
        return s
 
    except ValueError:
 
        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)
 

	
 
if __name__ == "__main__":
 
    Patch.reload_data()
 
    s = Submasters()
0 comments (0 inline, 0 general)