# Path: flow/signal.py
# class Signal(HasTraits):
# 	color = Str("white")
# 	name = Str()
# 
# 	buffer_size = Int(256)
# 
# 	sample_rate = Int(250)
# 
# 	def __init__(self, name='', **config):
# 		super(Signal, self).__init__(**config)
# 
# 		self.name = name
# 
# 		latency = 0
# 		self.connections_ = set()
# 		self.new_samples = 0
# 		self.timestamp = 0
# 
# 		self._buffer_size_changed()
# 
# 	def _buffer_size_changed(self):
# 		self.buffer = [0] * self.buffer_size
# 
# 
# 	# Store a connection to connected input blocks
# 	def _connect(self, block):
# 		self.connections_.add(block)
# 
# 	def _disconnect(self, block):
# 		self.connections_.remove(block)
# 
# 	def clear_connections(self):
# 		self.connections_.clear()
# 
# 	def append(self, data):
# 		size = len(self.buffer)
# 
# 		self.buffer[:-len(data)] = self.buffer[len(data):]
# 		self.buffer[-len(data):] = data
# 
# 		self.new_samples = len(data)
# 
# 		self.timestamp += len(data)
# 
# 	def process(self):
# 		for c in self.connections_:
# 			c._signal_ready(self)
# 
# 	@property
# 	def new(self):
# 		return self.buffer[-self.new_samples:]
# 
# 	@property
# 	def posedge(self):
# 		new = self.buffer[: self.new_samples + 1]
# 		new = np.array(new) >= 1.0
# 
# 		argmax = np.argmax(new[:-1])
# 		if new[argmax] and not new[argmax + 1]:
# 			return True
# 		return False
# 
# 	@property
# 	def last(self):
# 		return self.buffer[-1]


from .signal import Signal
from traits.api import HasTraits, Disallow, TraitType, on_trait_change

class Input(TraitType):
    def __init__(self, default=None):
        super(Input, self).__init__(default, input=True)

        self.default = default

    def info(self):
        return 'a Signal or output Block instance'

    def validate(self, object, name, value):
        if isinstance(object, Block) and not hasattr(object, 'inputs'):
            raise Exception("Input trait can't be assigned before Block.__init__")

        if isinstance(value, Block):
            if hasattr(value, 'output'):
                value = value.output


# Path: flow/signal.py
# class Signal(HasTraits):
# 	color = Str("white")
# 	name = Str()
# 
# 	buffer_size = Int(256)
# 
# 	sample_rate = Int(250)
# 
# 	def __init__(self, name='', **config):
# 		super(Signal, self).__init__(**config)
# 
# 		self.name = name
# 
# 		latency = 0
# 		self.connections_ = set()
# 		self.new_samples = 0
# 		self.timestamp = 0
# 
# 		self._buffer_size_changed()
# 
# 	def _buffer_size_changed(self):
# 		self.buffer = [0] * self.buffer_size
# 
# 
# 	# Store a connection to connected input blocks
# 	def _connect(self, block):
# 		self.connections_.add(block)
# 
# 	def _disconnect(self, block):
# 		self.connections_.remove(block)
# 
# 	def clear_connections(self):
# 		self.connections_.clear()
# 
# 	def append(self, data):
# 		size = len(self.buffer)
# 
# 		self.buffer[:-len(data)] = self.buffer[len(data):]
# 		self.buffer[-len(data):] = data
# 
# 		self.new_samples = len(data)
# 
# 		self.timestamp += len(data)
# 
# 	def process(self):
# 		for c in self.connections_:
# 			c._signal_ready(self)
# 
# 	@property
# 	def new(self):
# 		return self.buffer[-self.new_samples:]
# 
# 	@property
# 	def posedge(self):
# 		new = self.buffer[: self.new_samples + 1]
# 		new = np.array(new) >= 1.0
# 
# 		argmax = np.argmax(new[:-1])
# 		if new[argmax] and not new[argmax + 1]:
# 			return True
# 		return False
# 
# 	@property
# 	def last(self):
# 		return self.buffer[-1]


# Path: flow/block.py
from .signal import Signal
from traits.api import HasTraits, Disallow, TraitType, on_trait_change


class Input(TraitType):
    def __init__(self, default=None):
        super(Input, self).__init__(default, input=True)

        self.default = default

    def info(self):
        return 'a Signal or output Block instance'

    def validate(self, object, name, value):
        if isinstance(object, Block) and not hasattr(object, 'inputs'):
            raise Exception("Input trait can't be assigned before Block.__init__")

        if isinstance(value, Block):
            if hasattr(value, 'output'):
                value = value.output


        if not isinstance(value, Signal):