def _scriptable_set(obj, name, value): """ The setter for a scriptable trait. """ if _outermost_call: get_script_manager().record_trait_set(obj, name, value) _name = '_' + name old_value = getattr(obj, _name, Undefined) if old_value is not value: setattr(obj, _name, value) obj.trait_property_changed(name, old_value, value)
def _scripter(*args, **kwargs): """ This is the wrapper that is returned in place of the scriptable method. """ global _outermost_call if _outermost_call: _outermost_call = False # See if there is an script manager set. sm = get_script_manager() if func.func_name == '__init__': sm.new_object(args[0], type(args[0]), args[1:], kwargs) try: result = func(*args, **kwargs) finally: _outermost_call = True else: # Record the ordinary method. try: result = sm.record_method(func, args, kwargs) finally: _outermost_call = True else: # We aren't at the outermost call so just invoke the method. result = func(*args, **kwargs) return result
def create_scriptable_object(self, name): """Invoke the factory to create the object then make it scriptable.""" obj = self.factory() sm = get_script_manager() sm.bind_event = BindEvent(name=name, obj=obj) make_object_scriptable(obj, self.api, self.includes, self.excludes) return obj
def _scriptable_get(obj, name): """ The getter for a scriptable trait. """ global _outermost_call saved_outermost = _outermost_call _outermost_call = False try: result = getattr(obj, '_' + name, None) if result is None: result = obj.trait(name).default finally: _outermost_call = saved_outermost if saved_outermost: get_script_manager().record_trait_get(obj, name, result) return result
def _gc_script_obj(obj_ref): """ The callback invoked when a scriptable object is garbage collected. """ # Avoid recursive imports. from package_globals import get_script_manager sm = get_script_manager() so = sm._so_by_ref[obj_ref] if so.name: sm._unbind(so) del sm._so_by_id[so.obj_id] del sm._so_by_ref[so.obj_ref]
def __init__(self, *args, **kwargs): """Initialise the dynamic sub-class instance.""" get_script_manager().new_object(self, scripted_type, args, kwargs, name, bind_policy) scripted_type.__init__(self, *args, **kwargs)