~sjdv1982/hivesystem/trunk

« back to all changes in this revision

Viewing changes to sparta/processors/transistor.py

  • Committer: Sjoerd de Vries
  • Date: 2014-06-09 10:19:38 UTC
  • mfrom: (182.1.43 hive-view)
  • Revision ID: sjdv1982@gmail.com-20140609101938-7ji5g0buo09r0se6
merged with hive-view branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import libcontext, bee
 
2
from bee.segments import *
 
3
import bee.segments.transistor
 
4
from bee.types import stringtupleparser
 
5
 
 
6
class transistor(object):
 
7
    """
 
8
    A transistor converts pull input to push output
 
9
    Whenever the transistor is triggered, the value is pulled in and then pushed out
 
10
    """
 
11
    metaguiparams = {
 
12
      "type_" : "str",
 
13
      "autocreate" : {"type_" : "bool"},
 
14
    }
 
15
    @classmethod
 
16
    def form(cls, f):
 
17
        f.type_.name = "Type"
 
18
        f.type_.type = "option"        
 
19
        f.type_.options = "bool", "int", "float", "(str,identifier)", "(str,action)", "(str,keycode)", "(str,message)", "(str,property)", "(str,process)", "str", "(object,matrix)", "(object,bge)", "object", "custom"
 
20
        f.type_.optiontitles = "Bool", "Integer", "Float", "ID String", "Action String", "Key String", "Message String", "Property String", "Process ID String",  "Generic String", "Matrix Object", "BGE Object", "Generic Object", "Custom"
 
21
        f.type_.default = "bool"
 
22
    
 
23
    def __new__(cls, type_):
 
24
        type_ = stringtupleparser(type_)
 
25
        class transistor(bee.worker):    
 
26
            __doc__ = cls.__doc__
 
27
            
 
28
            # Implementation
 
29
            val = antenna("pull", type_)
 
30
            trans = bee.segments.transistor(type_)
 
31
            outp = output("push", type_)
 
32
            connect(val, trans)
 
33
            connect(trans, outp)
 
34
            trig = antenna("push", "trigger")
 
35
            trigger(trig, trans)
 
36
                                            
 
37
            guiparams = {
 
38
              "val" : {"name": "Value"},
 
39
              "outp" : {"name": "Output"},
 
40
              "trig" : {"name": "Trigger"},
 
41
              "_memberorder" : ["trig", "val", "outp"],
 
42
            }
 
43
                              
 
44
        return transistor
 
45
    
 
 
b'\\ No newline at end of file'