コード例 #1
0
ファイル: variable.py プロジェクト: simeks/pluto
class VariableNode(FlowNode):
    pins = [
        FlowPin('Out', FlowPin.Out)
    ]
    properties = [
        StringProperty('name', ''),
        StringProperty('default', '')
    ]

    def __init__(self):
        super(VariableNode, self).__init__()
        self.node_class = 'flow.variable.VariableNode'
        self.title = 'Variable'
        self.category = 'Flow'
        self.ui_class = 'variable_node'

    def run(self, ctx):
        if self.name in ctx.env:
            ctx.write_pin('Out', ctx.env[self.name])
        else:
            ctx.write_pin('Out', self.default)
コード例 #2
0
ファイル: constant.py プロジェクト: simeks/pluto
class StringNode(FlowNode):
    pins = [FlowPin('Out', FlowPin.Out)]
    properties = [
        StringProperty('value', ''),
    ]

    def __init__(self):
        super(StringNode, self).__init__()
        self.node_class = 'flow.constant.StringNode'
        self.title = 'String'
        self.category = 'Constants'
        self.ui_class = 'constant_node'

    def run(self, ctx):
        ctx.write_pin('Out', self.value)
コード例 #3
0
class EvalNode(FlowNode):
    pins = [
        FlowPin('Out', FlowPin.Out)
    ]
    properties = [
        StringProperty('code', ''),
    ]

    def __init__(self):
        super(EvalNode, self).__init__()
        self.node_class = 'flow.util.Eval'
        self.title = 'Eval'
        self.category = 'Flow'
        self.ui_class = 'single_pin_node'

    def run(self, ctx):
        ctx.write_pin('Out', eval(self.code))
コード例 #4
0
class FailNode(FlowNode):
    pins = [
        FlowPin('In', FlowPin.In),
    ]
    properties = [
        StringProperty('error', ''),
    ]

    def __init__(self):
        super(FailNode, self).__init__()
        self.node_class = 'flow.debug.Fail'
        self.title = 'Fail'
        self.category = 'Debug'
        self.value = ''

    def run(self, ctx):
        if self.error != '':
            raise ValueError(self.error)
コード例 #5
0
ファイル: new.py プロジェクト: simeks/pluto
class ZerosNode(FlowNode):
    pins = [FlowPin('Out', FlowPin.Out)]
    properties = [
        StringProperty('shape', '(0, 0)'),
    ]

    def __init__(self):
        super(ZerosNode, self).__init__()
        self.node_class = 'image.new.ZerosNode'
        self.title = 'Zeros'
        self.category = 'Image/New'
        self.ui_class = 'constant_node'
        self.ui_node_title_var = 'shape'

    def run(self, ctx):
        if re.match('\((\s*\d+\s*,?\s*)*\)$', self.shape.strip()) is None:
            raise ValueError('Invalid shape specifier: %s' % self.shape)

        shape = eval(self.shape)
        ctx.write_pin('Out', Image(np.zeros(shape)))
コード例 #6
0
class SetSliceImageNode(FlowNode):
    pins = [
        FlowPin('In', FlowPin.In),
        FlowPin('Value', FlowPin.In),
        FlowPin('Out', FlowPin.Out)
    ]
    properties = [
        StringProperty('slice', '0,0'),
    ]

    def __init__(self):
        super(SetSliceImageNode, self).__init__()
        self.node_class = 'image.image.SetSliceImageNode'
        self.title = 'SetSlice'
        self.category = 'Image/Slice'

    def run(self, ctx):
        img = ctx.read_pin('In')
        if img is None or not isinstance(img, np.ndarray):
            raise ValueError('Expected an Image object')

        value = ctx.read_pin('Value')

        # Validate index
        index = ''
        tokens = self.slice.split(',')
        for i in range(0, len(tokens)):
            if i != len(tokens)-1 and tokens[i] == '': # Allow a trailing ','
                index = index + ','
                continue
            if re.match('[\-0-9:]+$', tokens[i].strip()):
                index = index + tokens[i].strip()
                if i != len(tokens)-1:
                    index = index + ','
            else:
                raise SyntaxError('Invalid syntax: %s' % self.slice) 

        tmp = img
        exec('tmp[%s] = value' % index)
        ctx.write_pin('Out', tmp)
コード例 #7
0
class IndexNode(FlowNode):
    pins = [FlowPin('In', FlowPin.In), FlowPin('Out', FlowPin.Out)]
    properties = [
        StringProperty('index', '0'),
    ]

    def __init__(self):
        super(IndexNode, self).__init__()
        self.node_class = 'flow.list.IndexNode'
        self.title = 'Slice'
        self.category = 'List'
        self.ui_class = 'one_to_one_node'
        self.ui_node_title_var = 'index'

    def run(self, ctx):
        lst = ctx.read_pin('In')

        # Validate index
        index = self.index.strip()
        if not re.match('[\-0-9:]+$', index):
            raise ValueError('Invalid index')

        ctx.write_pin('Out', eval('lst[%s]' % index))