예제 #1
0
def build_instantiator(cls, i, ex, args, meta_args):
    """Instantiates a Hive class at runtime"""
    # If this is built now, then it won't perform matchmaking, so use meta hive
    bind_meta_class = hive.meta_hive("BindEnvironment", build_bind_environment, declare_build_environment,
                                     builder_cls=BindEnvironmentClass)
    #assert bind_meta_class._hive_object_class
    i.bind_meta_class = hive.property(cls, "bind_meta_class", "class", bind_meta_class)

    i.trig_instantiate = hive.triggerfunc(cls.instantiate)
    i.do_instantiate = hive.triggerable(i.trig_instantiate)

    i.hive_class = hive.property(cls, "hive_class", "class")
    i.pull_hive_class = hive.pull_in(i.hive_class)
    ex.hive_class = hive.antenna(i.pull_hive_class)

    ex.create = hive.entry(i.do_instantiate)

    hive.trigger(i.trig_instantiate, i.pull_hive_class, pretrigger=True)

    ex.process_id = hive.property(cls, "last_created_process_id", "int.process_id")
    i.pull_process_id = hive.pull_out(ex.process_id)
    ex.last_process_id = hive.output(i.pull_process_id)

    i.push_stop_process = hive.push_in(cls.stop_hive)
    ex.stop_process = hive.antenna(i.push_stop_process)

    # Bind class plugin
    ex.bind_on_created = hive.socket(cls.add_on_created, identifier="bind.on_created", policy=hive.MultipleOptional)
    ex.add_get_plugins = hive.socket(cls.add_get_plugins, identifier="bind.get_plugins", policy=hive.MultipleOptional)
    ex.add_get_config = hive.socket(cls.add_get_config, identifier="bind.get_config", policy=hive.MultipleOptional)

    # Bind instantiator
    if meta_args.bind_process == 'child':
        # Add startup and stop callbacks
        ex.on_stopped = hive.plugin(cls.stop_all_processes, identifier="on_stopped")
예제 #2
0
def build_operator(i, ex, args, meta_args):
    """HIVE interface to python mathematical operators"""
    assert meta_args.operator in operators
    op = operators[meta_args.operator]

    i.a = hive.attribute(meta_args.data_type)
    i.b = hive.attribute(meta_args.data_type)

    i.pull_a = hive.pull_in(i.a)
    ex.a = hive.antenna(i.pull_a)

    i.pull_b = hive.pull_in(i.b)
    ex.b = hive.antenna(i.pull_b)
    hive.trigger(i.pull_a, i.pull_b)

    i.result = hive.attribute(meta_args.data_type)
    i.pull_result = hive.pull_out(i.result)
    ex.result = hive.output(i.pull_result)

    def calc(self):
        self._result = op(self._a, self._b)

    i.run_operator = hive.modifier(calc)

    hive.trigger(i.pull_a, i.run_operator)
    hive.trigger(i.pull_result, i.pull_a, pretrigger=True)
예제 #3
0
파일: item.py 프로젝트: BlenderCN-Org/hive2
def build_item(i, ex, args, meta_args):
    """Set/get item in object"""
    i.name = hive.attribute(meta_args.index_type)
    i.value = hive.attribute(meta_args.item_type)
    i.container_ = hive.attribute(meta_args.container_type)

    i.pull_name = hive.pull_in(i.name)
    i.pull_container = hive.pull_in(i.container_)

    ex.container_ = hive.antenna(i.pull_container)
    ex.name = hive.antenna(i.pull_name)

    if meta_args.mode == "set":
        i.push_value = hive.push_in(i.value)
        ex.value = hive.antenna(i.push_value)

        i.do_set_attr = hive.modifier(do_setitem)

        hive.trigger(i.push_value, i.pull_container)
        hive.trigger(i.pull_container, i.pull_name)
        hive.trigger(i.pull_name, i.do_set_attr)

    else:
        i.pull_value = hive.pull_out(i.value)
        ex.value = hive.output(i.pull_value)

        i.do_get_attr = hive.modifier(do_getitem)

        hive.trigger(i.pull_value, i.pull_container, pretrigger=True)
        hive.trigger(i.pull_container, i.pull_name)
        hive.trigger(i.pull_name, i.do_get_attr)
예제 #4
0
파일: immutable.py 프로젝트: agoose77/hive2
def build_set(i, ex, args):
    """Perform set operation on two sets"""
    i.a = hive.variable('set')
    i.pull_a = hive.pull_in(i.a)
    ex.a = hive.antenna(i.pull_a)

    i.b = hive.variable('set')
    i.pull_b = hive.pull_in(i.b)
    ex.b = hive.antenna(i.pull_b)

    i.result = hive.variable('set')
    for op_name, op in SET_SET_OPERATIONS.items():
        pull_op = hive.pull_out(i.result)
        setattr(i, "pull_{}".format(op_name), pull_op)
        setattr(ex, op_name, hive.output(pull_op))

        def do_operation(self):
            self._result = op(self._a, self._b)

        mod = hive.modifier(do_operation)
        setattr(i, "do_{}".format(op_name), mod)

        hive.trigger(pull_op, i.pull_a, pretrigger=True)
        hive.trigger(pull_op, mod, pretrigger=True)

    hive.trigger(i.pull_a, i.pull_b)
예제 #5
0
def build_attr(i, ex, args, meta_args):
    """Set/get attribute on object"""
    i.name = hive.attribute("str")
    i.value = hive.attribute(meta_args.attribute_type)
    i.object_ = hive.attribute(meta_args.object_type)

    i.pull_name = hive.pull_in(i.name)
    i.pull_object = hive.pull_in(i.object_)

    ex.object_ = hive.antenna(i.pull_object)
    ex.name = hive.antenna(i.pull_name)

    if meta_args.mode == "set":
        i.push_value = hive.push_in(i.value)
        ex.value = hive.antenna(i.push_value)

        i.do_set_attr = hive.modifier(do_setattr)

        hive.trigger(i.push_value, i.pull_object)
        hive.trigger(i.pull_object, i.pull_name)
        hive.trigger(i.pull_name, i.do_set_attr)

    else:
        i.pull_value = hive.pull_out(i.value)
        ex.value = hive.output(i.pull_value)

        i.do_get_attr = hive.modifier(do_getattr)

        hive.trigger(i.pull_value, i.pull_object, pretrigger=True)
        hive.trigger(i.pull_object, i.pull_name)
        hive.trigger(i.pull_name, i.do_get_attr)
예제 #6
0
def build_buffer(i, ex, args, meta_args):
    """Store the input value and output saved value.

    In pull mode, the trigger is used to update the internal value.
    In push mode, the trigger is used to output the internal value.

    Can be used to cache changing values
    """
    args.start_value = hive.parameter(meta_args.data_type, None)
    i.cached_value = hive.attribute(meta_args.data_type, args.start_value)

    if meta_args.mode == "push":
        i.push_value = hive.push_in(i.cached_value)
        ex.value = hive.antenna(i.push_value)

        i.push_cached_value = hive.push_out(i.cached_value)
        ex.cached_value = hive.output(i.push_cached_value)

        ex.output = hive.entry(i.push_cached_value)

    elif meta_args.mode == "pull":
        i.pull_value = hive.pull_in(i.cached_value)
        ex.value = hive.antenna(i.pull_value)

        i.pull_cached_value = hive.pull_out(i.cached_value)
        ex.cached_value = hive.output(i.pull_cached_value)

        ex.update_cache = hive.entry(i.pull_value)
예제 #7
0
def build_and(i, ex, args):
    ex.a_value = hive.attribute(("bool", ), False)
    ex.b_value = hive.attribute(("bool", ), False)

    i.a = hive.pull_in(ex.a_value)
    i.b = hive.pull_in(ex.b_value)

    ex.a = hive.antenna(i.a)
    ex.b = hive.antenna(i.b)

    def on_and(h):
        h._pull_inputs()

        if h.a_value and h.b_value:
            h.trig_out()

    i.trig_out = hive.triggerfunc()
    i.trig_in = hive.modifier(on_and)

    # Update attributes before calling modifier
    i.pull_inputs = hive.triggerfunc()
    hive.trigger(i.pull_inputs, i.a, pretrigger=True)
    hive.trigger(i.pull_inputs, i.b, pretrigger=True)

    ex.trig_out = hive.hook(i.trig_out)
    ex.trig_in = hive.entry(i.trig_in)
예제 #8
0
파일: range_.py 프로젝트: agoose77/hive2
def build_range(i, ex, args):
    """A range iterator hive"""
    i.min_value = hive.variable("int")
    i.max_value = hive.variable("int")
    i.step = hive.variable("int")

    i.pull_min_value = hive.pull_in(i.min_value)
    i.pull_max_value = hive.pull_in(i.max_value)
    i.pull_step = hive.pull_in(i.step)

    ex.min_value = hive.antenna(i.pull_min_value)
    ex.max_value = hive.antenna(i.pull_max_value)
    ex.step = hive.antenna(i.pull_step)

    i.iterator = hive.variable("int")

    def get_range(self):
        self._iterator = range(self._min_value, self._max_value, self._step)

    i.get_range = hive.modifier(get_range)

    i.pull_iterator = hive.pull_out(i.iterator, "iterator")
    ex.iterator = hive.output(i.pull_iterator)

    hive.trigger(i.pull_iterator, i.pull_min_value, pretrigger=True)
    hive.trigger(i.pull_iterator, i.pull_max_value, pretrigger=True)
    hive.trigger(i.pull_iterator, i.pull_step, pretrigger=True)
    hive.trigger(i.pull_iterator, i.get_range, pretrigger=True)
예제 #9
0
파일: spawn.py 프로젝트: agoose77/hive2
def build_spawn(cls, i, ex, args, meta_args):
    """Spawn an entity into the scene"""
    ex.get_spawn_entity = hive.socket(cls.set_spawn_entity, "entity.spawn")

    # Associate entity with this hive so it is safely destroyed
    ex.get_register_destructor = hive.socket(cls.set_register_destructor,
                                             "entity.register_destructor")
    ex.on_entity_process_instantiated = hive.plugin(
        cls.on_entity_process_created, "bind.on_created")

    i.entity_class_id = hive.property(cls, "entity_class_id",
                                      "str.entity_class_id")
    i.pull_class_id = hive.pull_in(i.entity_class_id)
    ex.entity_class_id = hive.antenna(i.pull_class_id)

    i.entity_last_created_id = hive.property(cls, "entity_last_created_id",
                                             "int.entity_id")

    if meta_args.spawn_hive:
        i.pull_entity_id = hive.pull_out(i.entity_last_created_id)
        ex.entity_last_created_id = hive.output(i.pull_entity_id)

    else:
        i.push_entity_id = hive.push_out(i.entity_last_created_id)
        ex.created_entity_id = hive.output(i.push_entity_id)

    i.do_spawn = hive.triggerable(cls.do_spawn_entity)
    i.trigger = hive.triggerfunc(i.do_spawn)
    i.on_triggered = hive.triggerable(i.trigger)

    hive.trigger(i.trigger, i.pull_class_id, pretrigger=True)

    # Process instantiator
    if meta_args.spawn_hive:
        i.instantiator = Instantiator(forward_events='all',
                                      bind_process='child')

        # Pull entity to instantiator
        hive.connect(i.pull_entity_id, i.instantiator.entity_id)

        # Get last created
        ex.hive_class = hive.antenna(i.instantiator.hive_class)
        ex.last_process_id = hive.output(i.instantiator.last_process_id)
        ex.stop_process = hive.antenna(i.instantiator.stop_process)
        ex.pause_events = hive.antenna(i.instantiator.pause_events)
        ex.resume_events = hive.antenna(i.instantiator.resume_events)

        # Instantiate
        hive.trigger(i.trigger, i.instantiator.create)

    else:
        # Finally push out entity
        hive.trigger(i.trigger, i.push_entity_id)

    ex.spawn = hive.entry(i.on_triggered)
예제 #10
0
파일: server.py 프로젝트: agoose77/hive2
def build_server(cls, i, ex, args):
    i.local_address = hive.property(cls, "local_address", "tuple")
    i.push_bind_address = hive.push_in(i.local_address)
    ex.bind_to = hive.antenna(i.push_bind_address)

    i.do_bind = hive.triggerable(cls.do_bind)
    hive.trigger(i.push_bind_address, i.do_bind)

    # Receiving connection
    i.connected_address = hive.property(cls, "connected_address", "tuple")
    i.push_connected_address = hive.push_out(i.connected_address)
    ex.on_client_connected = hive.output(i.push_connected_address)

    # Receiving connection
    i.disconnected_address = hive.property(cls, "disconnected_address",
                                           "tuple")
    i.push_disconnected_address = hive.push_out(i.disconnected_address)
    ex.on_client_disconnected = hive.output(i.push_disconnected_address)

    # Receiving
    i.from_address = hive.property(cls, "from_address", "tuple")
    i.pull_from_address = hive.pull_out(i.from_address)
    ex.from_address = hive.output(i.pull_from_address)

    i.received_data = hive.property(cls, "received_data", "bytes")
    i.push_received = hive.push_out(i.received_data)
    ex.on_received = hive.output(i.push_received)

    # Hive callbacks
    i.on_disconnected = hive.triggerfunc()
    i.on_connected = hive.triggerfunc()
    i.on_received = hive.triggerfunc()

    hive.trigger(i.on_received, i.push_received)
    hive.trigger(i.on_connected, i.push_connected_address)
    hive.trigger(i.on_disconnected, i.push_disconnected_address)

    # Sending
    i.to_address = hive.property(cls, "to_address", "tuple")
    i.pull_to_address = hive.pull_in(i.to_address)
    ex.to_address = hive.antenna(i.pull_to_address)

    i.outgoing_data = hive.property(cls, "outgoing_data", "bytes")
    i.push_outgoing_data = hive.push_in(i.outgoing_data)
    ex.send = hive.antenna(i.push_outgoing_data)

    i.do_send_data = hive.triggerable(cls.do_send)
    hive.trigger(i.push_outgoing_data, i.pull_to_address, pretrigger=True)
    hive.trigger(i.push_outgoing_data, i.do_send_data)

    i.synchronise_data = hive.triggerable(cls.synchronise)
    i.on_tick = OnTick()
    hive.connect(i.on_tick.on_tick, i.synchronise_data)
예제 #11
0
def build_set(i, ex, args, meta_args):
    """Perform set operation on single sets"""

    i.set_ = hive.attribute('set', set())
    i.pull_set_ = hive.pull_out(i.set_)
    ex.set_out = hive.output(i.pull_set_)

    i.push_set_ = hive.push_in(i.set_)
    ex.set_ = hive.antenna(i.push_set_)

    # Pop item
    i.popped_item = hive.attribute(meta_args.data_type)
    i.pull_pop = hive.pull_out(i.popped_item)
    ex.pop = hive.output(i.pull_pop)

    def do_pop(self):
        self._popped_item = self._set_.pop()

    i.do_pop = hive.modifier(do_pop)
    hive.trigger(i.pull_pop, i.do_pop, pretrigger=True)

    # Add item
    i.to_add = hive.attribute(meta_args.data_type)
    i.push_to_add = hive.push_in(i.to_add)
    ex.add = hive.antenna(i.push_to_add)

    def to_add(self):
        self._set_.add(self._to_add)

    i.do_add = hive.modifier(to_add)
    hive.trigger(i.push_to_add, i.do_add)

    # Remove item
    i.to_remove = hive.attribute(meta_args.data_type)
    i.push_to_remove = hive.push_in(i.to_remove)
    ex.remove = hive.antenna(i.push_to_remove)

    def do_remove(self):
        self._set_.remove(self._to_remove)

    i.do_remove = hive.modifier(do_remove)
    hive.trigger(i.push_to_remove, i.do_remove)

    def do_clear(self):
        self._set_.clear()

    i.do_clear = hive.modifier(do_clear)
    ex.clear = hive.entry(i.do_clear)
예제 #12
0
def build_move(cls, i, ex, args, meta_args):
    """Apply a position delta to an entity"""
    coordinate_system = meta_args.coordinate_system

    i.displacement = hive.property(cls, "displacement", "vector")
    i.pull_displacement = hive.pull_in(i.displacement)
    ex.displacement = hive.antenna(i.pull_displacement)

    if meta_args.bound:
        ex.get_bound = hive.socket(cls.set_get_entity_id,
                                   identifier="entity.get_bound")
        i.do_get_entity_id = hive.triggerable(cls.do_get_entity_id)

        hive.trigger(i.pull_displacement, i.do_get_entity_id)

    else:
        i.entity_id = hive.property(cls, "entity_id", "int.entity_id")
        i.pull_entity_id = hive.pull_in(i.entity_id)
        ex.entity_id = hive.antenna(i.pull_entity_id)

        hive.trigger(i.pull_displacement, i.pull_entity_id)

    if coordinate_system == 'absolute':
        ex.get_set_position = hive.socket(
            cls.set_set_position, identifier="entity.position.set.absolute")
        ex.get_get_position = hive.socket(
            cls.set_get_position, identifier="entity.position.get.absolute")

        i.do_set_position = hive.triggerable(cls.do_move_absolute)

    else:
        i.other_entity_id = hive.property(cls, "other_entity_id",
                                          "int.entity_id")
        i.pull_other_entity_id = hive.pull_in(i.other_entity_id)
        ex.other_entity_id = hive.antenna(i.pull_other_entity_id)

        hive.trigger(i.pull_displacement, i.pull_other_entity_id)

        ex.get_set_position = hive.socket(
            cls.set_set_position, identifier="entity.position.set.relative")
        ex.get_get_position = hive.socket(
            cls.set_get_position, identifier="entity.position.get.relative")

        i.do_set_position = hive.triggerable(cls.do_move_relative)

    hive.trigger(i.pull_displacement, i.do_set_position)

    ex.trig = hive.entry(i.pull_displacement)
예제 #13
0
def build_decompose(i, ex, args):
    """Decompose complex number into real and imaginary components"""
    i.value = hive.attribute('complex')
    i.real = hive.attribute('float')
    i.imag = hive.attribute('float')

    i.pull_imag = hive.pull_out(i.imag)
    i.pull_real = hive.pull_out(i.real)

    ex.real = hive.output(i.pull_real)
    ex.imag = hive.output(i.pull_imag)

    i.pull_value = hive.pull_in(i.value)
    ex.value = hive.antenna(i.pull_value)

    def build_value(self):
        value = self._value
        self._real = value.real
        self._imag = value.imag

    i.build_value = hive.modifier(build_value)

    hive.trigger(i.pull_imag, i.pull_value, pretrigger=True)
    hive.trigger(i.pull_real, i.pull_value, pretrigger=True)
    hive.trigger(i.pull_value, i.build_value)
예제 #14
0
파일: bind.py 프로젝트: agoose77/hive2
def build_bind(cls, i, ex, args, meta_args):
    if meta_args.forward_events == "none":
        return

    if meta_args.forward_events == "by_leader":
        i.event_leader = hive.property(cls, "leader", "tuple")
        i.pull_event_leader = hive.pull_in(i.event_leader)
        ex.event_leader = hive.antenna(i.pull_event_leader)

    i.push_pause_in = hive.push_in(cls.pause)
    ex.pause_events = hive.antenna(i.push_pause_in)

    i.push_resume_in = hive.push_in(cls.resume)
    ex.resume_events = hive.antenna(i.push_resume_in)

    ex.on_created = hive.plugin(cls.on_created, "bind.on_created")
예제 #15
0
파일: convert.py 프로젝트: agoose77/hive2
def build_convert(i, ex, args, meta_args):
    i.value_in = hive.variable(meta_args.from_data_type)
    i.value_out = hive.variable(meta_args.to_data_type)

    # For push in, push out
    if meta_args.mode == "push":
        i.ppin = hive.push_in(i.value_in)
        i.ppout = hive.push_out(i.value_out)

        hive.trigger(i.ppin, i.ppout)

    else:
        i.ppin = hive.pull_in(i.value_in)
        i.ppout = hive.pull_out(i.value_out)

        hive.trigger(i.ppout, i.ppin, pretrigger=True)

    ex.value_in = hive.antenna(i.ppin)
    ex.value_out = hive.output(i.ppout)

    # For casting (explicit conversion)
    if meta_args.conversion == "cast":
        to_base_type_name = hive.get_base_data_type(meta_args.to_data_type)
        value_cls = _type_map[to_base_type_name]

        def converter(self):
            self._value_out = value_cls(self._value_in)

        i.do_conversion = hive.modifier(converter)
        hive.trigger(i.ppout, i.do_conversion, pretrigger=True)

    # For duck typing, move value through
    else:
        i.move_value = hive.modifier(move_value)
        hive.trigger(i.ppin, i.move_value)
예제 #16
0
파일: keyboard.py 프로젝트: agoose77/hive2
def build_keyboard(cls, i, ex, args, meta_args):
    """Listen for keyboard event"""
    if meta_args.mode == 'single key':
        ex.on_event = hive.socket(cls.add_single_listener, identifier="event.add_handler")

        args.key = hive.parameter("str.keycode", "w")
        i.key = hive.property(cls, "key", "str.keycode", args.key)

        i.push_key = hive.push_in(i.key)
        ex.key = hive.antenna(i.push_key)

        i.on_key_changed = hive.triggerable(cls.change_listener_keys)
        hive.trigger(i.push_key, i.on_key_changed)

        i.on_pressed = hive.triggerfunc()
        ex.on_pressed = hive.hook(i.on_pressed)

        i.on_released = hive.triggerfunc()
        ex.on_released = hive.hook(i.on_released)

        i.is_pressed = hive.property(cls, "is_pressed", "bool")
        i.pull_is_pressed = hive.pull_out(i.is_pressed)
        ex.is_pressed = hive.output(i.pull_is_pressed)

    else:
        ex.on_event = hive.socket(cls.add_any_listener, identifier="event.add_handler")

        i.key_pressed = hive.property(cls, 'key_pressed', data_type='str.keycode')
        i.pull_key_pressed = hive.push_out(i.key_pressed)
        ex.key_pressed = hive.output(i.pull_key_pressed)

        i.key_released = hive.property(cls, 'key_released', data_type='str.keycode')
        i.pull_key_released = hive.push_out(i.key_released)
        ex.key_released = hive.output(i.pull_key_released)
예제 #17
0
def build_expression(i, ex, args, meta_args):
    """Execute bound expression for provided inputs and output result"""
    ast_node = ast.parse(meta_args.expression, mode='eval')

    visitor = NodeVisitor()
    visitor.visit(ast_node)

    visited_nodes = visitor.visited_nodes

    variable_names = [x.id for x in visited_nodes if isinstance(x, ast.Name)]

    i.result = hive.attribute(meta_args.result_type)
    i.pull_result = hive.pull_out(i.result)
    ex.result = hive.output(i.pull_result)

    for name in variable_names:
        attribute = hive.attribute()
        setattr(i, name, attribute)

        pull_in = hive.pull_in(attribute)
        setattr(ex, name, hive.antenna(pull_in))

        hive.trigger(i.pull_result, pull_in, pretrigger=True)

    func = create_func(meta_args.expression, variable_names)
    i.modifier = hive.modifier(func)
    hive.trigger(i.pull_result, i.modifier, pretrigger=True)
예제 #18
0
def build_bind(cls, i, ex, args, meta_args):
    bind_mode = meta_args.bind_entity

    if bind_mode == 'bound':
        i.entity_id = hive.property(cls, "entity_id", "int.entity_id")
        i.pull_entity_id = hive.pull_in(i.entity_id)
        ex.entity_id = hive.antenna(i.pull_entity_id)
예제 #19
0
def build_foreach(i, ex, args, meta_args):
    """Iterate over iterable object"""
    # Set iterable
    i.iterable = hive.variable("$iterable[int]")
    i.pull_iterable = hive.pull_in(i.iterable)
    ex.iterable = hive.antenna(i.pull_iterable)

    i.do_trig = hive.triggerfunc()
    i.trig_in = hive.triggerable(i.do_trig)
    ex.start = hive.entry(i.trig_in)

    i.break_ = hive.variable('bool', False)

    i.item = hive.variable(meta_args.data_type)
    i.push_item = hive.push_out(i.item)
    ex.item = hive.output(i.push_item)

    i.index = hive.variable('int', 0)
    i.pull_index = hive.pull_out(i.index)
    ex.index = hive.output(i.pull_index)

    i.finished = hive.triggerfunc()

    i.do_break = hive.modifier(do_break)
    ex.break_ = hive.entry(i.do_break)
    ex.finished = hive.hook(i.finished)

    i.iter = hive.modifier(do_iter)
    hive.trigger(i.do_trig, i.pull_iterable)
    hive.trigger(i.do_trig, i.iter)
예제 #20
0
파일: call.py 프로젝트: BlenderCN-Org/hive2
def build_call(i, ex, args, meta_args):
    func = create_func(meta_args.declaration)
    spec = signature(func)

    for name, parameter in spec.parameters.items():
        if parameter.annotation is parameter.empty:
            raise ValueError("Expected annotation for parameter '{}'".format(name))

        attr = hive.attribute(parameter.annotation)
        pull_in = hive.pull_in(attr)
        antenna = hive.antenna(pull_in)

        setattr(i, name, attr)
        setattr(i, "pull_{}".format(name), pull_in)
        setattr(ex, name, antenna)

    wrapped_func = create_wrapper_func(meta_args.declaration, spec.parameters)
    i.modifier = hive.modifier(wrapped_func)

    return_type = spec.return_annotation

    if return_type is spec.empty:
        raise ValueError("Expected annotation for return parameter")

    i.result = hive.attribute(return_type)
    i.pull_result = hive.pull_out(i.result)
    ex.result = hive.output(i.pull_result)

    hive.trigger(i.pull_result, i.modifier, pretrigger=True)
예제 #21
0
def build_watch(cls, i, ex, args, meta_args):
    """Watch value and indicate when it is changed.

    Uses a tick callback.
    """
    args.start_value = hive.parameter(meta_args.data_type, None)
    i.value = hive.property(cls, "current_value", meta_args.data_type, args.start_value)

    if meta_args.mode == 'pull':
        i.value_in = hive.pull_in(i.value)

    else:
        i.value_in = hive.push_in(i.value)

    ex.value = hive.antenna(i.value_in)

    i.on_changed = hive.triggerfunc()
    ex.on_changed = hive.hook(i.on_changed)

    if meta_args.mode == 'pull':
        ex.get_add_handler = hive.socket(cls.set_add_handler, identifier="event.add_handler")

    else:
        i.compare_values = hive.triggerable(cls.compare_values)
        hive.trigger(i.value_in, i.compare_values)
예제 #22
0
def build_unpack_tuple(i, ex, args, meta_args):
    """Unpack a tuple from individual inputs"""
    i.tuple_ = hive.attribute('tuple')
    i.push_tuple = hive.push_in(i.tuple_)
    ex.tuple_ = hive.antenna(i.push_tuple)

    for index, data_type in enumerate(meta_args.types):
        attr = hive.attribute(data_type)
        setattr(i, "attr_{}".format(index), attr)

        pull_out = hive.pull_out(attr)
        setattr(i, "pull_out_{}".format(index), pull_out)

        setattr(ex, "item_{}".format(index), hive.output(pull_out))

    def do_unpack_tuple(self):
        tuple_ = self._tuple_
        data_types = meta_args.types

        assert len(tuple_) == len(data_types)

        for index, item in enumerate(tuple_):
            setattr(self, "_attr_{}".format(index), item)

    i.do_unpack_tuple = hive.modifier(do_unpack_tuple)
    hive.trigger(i.push_tuple, i.do_unpack_tuple)
예제 #23
0
def build_cross(i, ex, args):
    """Calculate the cross product between two vectors"""
    i.a = hive.attribute("vector")
    i.b = hive.attribute("vector")

    pull_a = hive.pull_in(i.a)
    pull_b = hive.pull_in(i.b)

    ex.a = hive.antenna(pull_a)
    ex.b = hive.antenna(pull_b)

    i.result = hive.attribute("vector")
    i.pull_result = hive.pull_out(i.result)
    ex.result = hive.output(i.pull_result)

    calculate = hive.modifier(cross_modifier)
    hive.trigger(i.pull_result, calculate, pretrigger=True)
예제 #24
0
파일: struct.py 프로젝트: agoose77/hive2
def build_io(i, ex, args, meta_args):
    if meta_args.mode == 'pull':
        i.value = hive.variable()
        i.in_ = hive.pull_in(i.value)
        ex.in_ = hive.antenna(i.in_)

        hive.trigger(i.in_, )

        i.out = meta_args.out(i.value)
        ex.out = hive.output(i.out)
    else:
        i.value = hive.variable()
        i.in_ = meta_args.in_(i.value)
        ex.in_ = hive.antenna(i.in_)

        i.out = meta_args.out(i.value)
        ex.out = hive.output(i.out)
예제 #25
0
def build_print(i, ex, args):
    """Output object to Python stdout"""
    ex.value = hive.variable()
    i.value_in = hive.push_in(ex.value)
    ex.value_in = hive.antenna(i.value_in)

    i.func = hive.modifier(lambda self: print(self.value))

    hive.trigger(i.value_in, i.func)
예제 #26
0
def build_dispatch(cls, i, ex, args):
    i.event = hive.property(cls, "event", "tuple.event")
    i.pull_event = hive.pull_in(i.event)
    ex.event = hive.antenna(i.pull_event)

    ex.get_read_event = hive.socket(cls.set_read_event, identifier="event.process")

    i.dispatch = hive.triggerable(cls.dispatch)
    ex.trig = hive.entry(i.dispatch)
예제 #27
0
def build_add_head(i, ex, args):
    """Add header to event tuple"""
    i.do_add_head = hive.modifier(do_add_head)

    i.head = hive.variable("str")
    i.pull_head = hive.pull_in(i.head)
    ex.head = hive.antenna(i.pull_head)

    i.leader = hive.variable("tuple.event")
    i.pull_leader = hive.pull_in(i.leader)
    ex.leader = hive.antenna(i.pull_leader)

    i.event = hive.variable("tuple.event")
    i.pull_event = hive.pull_out(i.event)
    ex.event = hive.output(i.pull_event)

    hive.trigger(i.pull_event, i.pull_head, pretrigger=True)
    hive.trigger(i.pull_head, i.pull_leader)
    hive.trigger(i.pull_leader, i.do_add_head)
예제 #28
0
파일: animation.py 프로젝트: agoose77/hive2
def build_animation(cls, i, ex, args, meta_args):
    """Play animation for actor"""
    i.do_start = hive.triggerable(cls.start)
    i.do_stop = hive.triggerable(cls.stop)

    ex.start = hive.entry(i.do_start)
    ex.stop = hive.entry(i.do_stop)

    i.current_frame = hive.property(cls, "current_frame", "int")
    i.end_frame = hive.property(cls, "end_frame", "int")
    i.start_frame = hive.property(cls, "start_frame", "int")

    i.pull_current_frame = hive.pull_out(i.current_frame)
    i.pull_end_frame = hive.pull_in(i.end_frame)
    i.pull_start_frame = hive.pull_in(i.start_frame)

    ex.current_frame = hive.output(i.pull_current_frame)
    ex.start_frame = hive.antenna(i.pull_start_frame)
    ex.end_frame = hive.antenna(i.pull_end_frame)
예제 #29
0
def build_endswith(i, ex, args):
    """Check if string ends with a substring"""
    i.string = hive.attribute('str')
    i.substring = hive.attribute('str')

    i.pull_string = hive.pull_in(i.string)
    i.pull_substring = hive.pull_in(i.substring)

    ex.string = hive.antenna(i.pull_string)
    ex.substring = hive.antenna(i.pull_substring)

    i.endswith = hive.attribute('bool')
    i.pull_endswith = hive.pull_out(i.endswith)
    ex.endswith = hive.output(i.pull_endswith)

    i.do_find_substr = hive.modifier(do_endswith)

    hive.trigger(i.pull_endswith, i.pull_string, pretrigger=True)
    hive.trigger(i.pull_string, i.pull_substring)
    hive.trigger(i.pull_substring, i.do_find_substr)
예제 #30
0
def build_while(i, ex, args):
    """Trigger output while condition is True"""
    ex.condition = hive.attribute()
    i.condition_in = hive.pull_in(ex.condition)
    ex.condition_in = hive.antenna(i.condition_in)

    i.trig = hive.triggerfunc()
    ex.trig_out = hive.hook(i.trig)

    i.trig_in = hive.modifier(do_while)
    ex.trig_in = hive.entry(i.trig_in)