Example #1
0
 def __init__(self, **kwargs):
     kwargs['ParentEmissionThread'] = None
     self.IsParentEmissionThread = kwargs.get('IsParentEmissionThread', False)
     thread_id = setID(kwargs.get('thread_id'))
     if thread_id in _THREADS:
         newid = '__'.join([thread_id, setID(None)])
         self.LOG.warning('thread_id %s already exists using %s' % (thread_id, newid))
         thread_id = newid
     _THREADS[thread_id] = self
     self.AllowedEmissionThreads = set()
     self.AllowedEmissionThreads |= set(kwargs.get('AllowedEmissionThreads', []))
     self.AllowedEmissionThreads.add(thread_id)
     threading.Thread.__init__(self, name=thread_id)
     OSCBaseObject.__init__(self, **kwargs)
     self._thread_id = thread_id
     self._insertion_lock = Lock()
     self.Events = {}
     timed_events = []
     
     for cls in iterbases(self, 'OSCBaseObject'):
         if not hasattr(cls, '_Events'):
             continue
         for key in cls._Events.iterkeys():
             e = self.Properties[key]
             self.Events[key] = e
             if e.wait_timeout is not None:
                 timed_events.append(e.name)
     self._threaded_calls_idle = True
     timed_events.reverse()
     self.timed_events = timed_events
     self._threaded_calls_queue = collections.deque()
     self._timed_calls_queue = TimeQueue()
     self.disable_threaded_call_waits = kwargs.get('disable_threaded_call_waits', False)
 def calc_to_base_value(self):
     v = self.value
     attr = '_'.join([self.standard, 'multiplier'])
     default_m = getattr(self, attr)
     for cls in iterbases(self, 'Byte'):
         m = getattr(cls, attr, default_m)
         v *= m
     return v
 def calc_from_base_value(self, value):
     attr = '_'.join([self.standard, 'multiplier'])
     default_m = getattr(self, attr)
     bases = []
     for cls in iterbases(self, 'Byte'):
         bases.append(cls)
     for cls in reversed(bases):
         m = getattr(cls, attr, default_m)
         value /= m
     return value
Example #4
0
 def build_dependencies(self):
     h = self.handler
     dep_cls = []
     for act_cls in iterbases(self, Action):
         if not hasattr(act_cls, 'dependencies'):
             continue
         dep_cls.extend(getattr(act_cls, 'dependencies', []))
     for cls in dep_cls:
         if isinstance(cls, Action):
             fkwargs = {'obj': cls}
         elif issubclass(cls, Action):
             fkwargs = {'cls': cls}
         else:
             fkwargs = {'name': cls}
         obj = h.find_action_obj(**fkwargs)
         self.add_dependancy(obj)
Example #5
0
 def build_dependencies(self):
     h = self.handler
     dep_cls = []
     for act_cls in iterbases(self, Action):
         if not hasattr(act_cls, 'dependencies'):
             continue
         dep_cls.extend(getattr(act_cls, 'dependencies', []))
     for cls in dep_cls:
         if isinstance(cls, Action):
             fkwargs = {'obj':cls}
         elif issubclass(cls, Action):
             fkwargs = {'cls':cls}
         else:
             fkwargs = {'name':cls}
         obj = h.find_action_obj(**fkwargs)
         self.add_dependancy(obj)
 def __new__(*args, **kwargs):
     realcls = args[0]
     #cls = realcls
     #print 'Baseobject __new__: ', cls
     if realcls != BaseObject:
         for cls in iterbases(realcls, BaseObject.__bases__[0]):
             #while issubclass(cls, BaseObject):
             #props = getattr(cls, '_Properties', {})
             props = cls.__dict__.get('_Properties', {})
             for key, val in props.iteritems():
                 if not hasattr(cls, key):
                     p_kwargs = val.copy()
                     p_kwargs.setdefault('name', key)
                     p_kwargs['cls'] = cls
                     property = Properties.ClsProperty(**p_kwargs)
                     setattr(cls, property.name, property)
             #cls = cls.__bases__[0]
     #return SignalDispatcher.dispatcher.__new__(*args, **kwargs)
     return object.__new__(realcls)
Example #7
0
 def __new__(*args, **kwargs):
     realcls = args[0]
     #cls = realcls
     #print 'Baseobject __new__: ', cls
     if realcls != BaseObject:
         for cls in iterbases(realcls, BaseObject.__bases__[0]):
         #while issubclass(cls, BaseObject):
             #props = getattr(cls, '_Properties', {})
             props = cls.__dict__.get('_Properties', {})
             for key, val in props.iteritems():
                 if not hasattr(cls, key):
                     p_kwargs = val.copy()
                     p_kwargs.setdefault('name', key)
                     p_kwargs['cls'] = cls
                     property = Properties.ClsProperty(**p_kwargs)
                     setattr(cls, property.name, property)
             #cls = cls.__bases__[0]
     #return SignalDispatcher.dispatcher.__new__(*args, **kwargs)
     return object.__new__(realcls)
Example #8
0
    def __init__(self, **kwargs):
        kwargs['ParentEmissionThread'] = None
        self.IsParentEmissionThread = kwargs.get('IsParentEmissionThread',
                                                 False)
        thread_id = setID(kwargs.get('thread_id'))
        if thread_id in _THREADS:
            newid = '__'.join([thread_id, setID(None)])
            self.LOG.warning('thread_id %s already exists using %s' %
                             (thread_id, newid))
            thread_id = newid
        _THREADS[thread_id] = self
        self.AllowedEmissionThreads = set()
        self.AllowedEmissionThreads |= set(
            kwargs.get('AllowedEmissionThreads', []))
        self.AllowedEmissionThreads.add(thread_id)
        threading.Thread.__init__(self, name=thread_id)
        OSCBaseObject.__init__(self, **kwargs)
        self._thread_id = thread_id
        self._insertion_lock = Lock()
        self.Events = {}
        timed_events = []

        for cls in iterbases(self, 'OSCBaseObject'):
            if not hasattr(cls, '_Events'):
                continue
            for key in cls._Events.iterkeys():
                e = self.Properties[key]
                self.Events[key] = e
                if e.wait_timeout is not None:
                    timed_events.append(e.name)
        self._threaded_calls_idle = True
        timed_events.reverse()
        self.timed_events = timed_events
        self._threaded_calls_queue = collections.deque()
        self._timed_calls_queue = TimeQueue()
        self.disable_threaded_call_waits = kwargs.get(
            'disable_threaded_call_waits', False)
    def __init__(self, **kwargs):
        if globals().get('GLOBAL_CONFIG', {}).get('EnableEmissionThreads'):
            build_thread = kwargs.get(
                'BuildEmissionThread',
                getattr(self, 'BuildEmissionThread', False))
            t = kwargs.get('ParentEmissionThread')
            if type(t) == type and issubclass(t, BaseThread):
                ptkwargs = kwargs.get('ParentEmissionThread_kwargs', {})
                ptkwargs.setdefault(
                    'thread_id', '_'.join([t.__name__,
                                           'ParentEmissionThread']))
                t = t(**ptkwargs)
                build_thread = False
            if build_thread:
                if type(build_thread) == str:
                    bthread_id = build_thread
                else:
                    bthread_id = '_'.join(
                        [self.__class__.__name__, 'ParentEmissionThread'])
                t = BaseThread(thread_id=bthread_id)
            if isinstance(t, BaseThread):
                if not getattr(t, 'owner', None):
                    t.owner = self
                if not t.isAlive():
                    t.start()
                kwargs['ParentEmissionThread'] = t
                t.IsParentEmissionThread = True
        else:
            kwargs['ParentEmissionThread'] = None
        self.ParentEmissionThread = kwargs.get('ParentEmissionThread')
        self.Properties = {}
        self._Index_validate_default = True
        #cls = self.__class__
        #bases_limit = getattr(cls, '_saved_bases_limit', self._saved_class_name)
        signals_to_register = set()
        save_dict = {}
        for key in save_keys.iterkeys():
            save_dict.update({key: set()})
        self.SettingsProperties = {}
        self.SettingsPropKeys = []
        self.ChildGroups = {}
        childgroups = {}
        for cls in iterbases(self, BaseObject.__bases__[0]):
            #while cls != BaseObject.__bases__[0]:# and getattr(cls, '_saved_class_name', '') != bases_limit:
            if not hasattr(self, 'saved_class_name'):
                if hasattr(cls, '_saved_class_name'):
                    self.saved_class_name = cls._saved_class_name
            signals = getattr(cls, 'signals_to_register', None)
            if signals is not None:
                for s in signals:
                    signals_to_register.add(s)
            for key, val in save_keys.iteritems():
                if hasattr(cls, val):
                    save_dict[key] |= set(getattr(cls, val))
            for propname in getattr(cls, '_Properties', {}).iterkeys():
                prop = getattr(cls, propname)
                if isinstance(prop, Properties.ClsProperty):
                    prop.init_instance(self)
            if hasattr(cls, '_SettingsProperties'):
                spropkeys = cls._SettingsProperties[:]
                spropkeys.reverse()
                self.SettingsPropKeys.extend(spropkeys)
                for propname in spropkeys:
                    prop = self.Properties.get(propname)
                    if prop:
                        self.SettingsProperties.update({propname: prop})
                save_dict['saved_attributes'] |= set(cls._SettingsProperties)
            if hasattr(cls, '_ChildGroups'):
                for cgkey, cgval in cls._ChildGroups.iteritems():
                    if cgkey in childgroups:
                        childgroups[cgkey].update(cgval)
                    else:
                        childgroups[cgkey] = cgval
            #cls = cls.__bases__[0]
        self.SettingsPropKeys.reverse()
        self.SettingsPropKeys = tuple(self.SettingsPropKeys)
        for key, val in save_dict.iteritems():
            if not hasattr(self, key):
                setattr(self, key, val)

        if not hasattr(self, 'root_category'):
            self.root_category = kwargs.get('root_category')
        self.categories = {}
        self.categories_id = kwargs.get('categories_id', set())

        kwargs.update({'signals_to_register': signals_to_register})
        SignalDispatcher.dispatcher.__init__(self, **kwargs)

        prebind = kwargs.get('prebind', {})
        self.bind(**prebind)

        childgroup = kwargs.get('ChildGroup_parent')
        if childgroup is not None:
            self.ChildGroup_parent = childgroup

        for key, val in childgroups.iteritems():
            cgkwargs = val.copy()
            cgkwargs.setdefault('name', key)
            ds_cb = cgkwargs.get('deserialize_callback')
            if type(ds_cb) == str:
                cgkwargs['deserialize_callback'] = getattr(self, ds_cb, None)
            self.add_ChildGroup(**cgkwargs)

        Serializer.__init__(self, **kwargs)

        i = kwargs.get('Index')
        if self.Index is None and i is not None:
            self.Index = i

        self.register_signal('category_update')

        for c_id in self.categories_id:
            if not getattr(self, 'root_category', None):
                self.root_category = self.GLOBAL_CONFIG.get('ROOT_CATEGORY')
            category = self.root_category.find_category(id=c_id)
            if category:
                self.add_category(category)
            else:
                self.LOG.warning('could not locate category id: ' + str(c_id))

        f = getattr(self, 'on_program_exit', None)
        if f:
            atexit.register(f)
Example #10
0
 def __init__(self, **kwargs):
     if globals().get('GLOBAL_CONFIG', {}).get('EnableEmissionThreads'):
         build_thread = kwargs.get('BuildEmissionThread', getattr(self, 'BuildEmissionThread', False))
         t = kwargs.get('ParentEmissionThread')
         if type(t) == type and issubclass(t, BaseThread):
             ptkwargs = kwargs.get('ParentEmissionThread_kwargs', {})
             ptkwargs.setdefault('thread_id', '_'.join([t.__name__, 'ParentEmissionThread']))
             t = t(**ptkwargs)
             build_thread = False
         if build_thread:
             if type(build_thread) == str:
                 bthread_id = build_thread
             else:
                 bthread_id = '_'.join([self.__class__.__name__, 'ParentEmissionThread'])
             t = BaseThread(thread_id=bthread_id)
         if isinstance(t, BaseThread):
             if not getattr(t, 'owner', None):
                 t.owner = self
             if not t.isAlive():
                 t.start()
             kwargs['ParentEmissionThread'] = t
             t.IsParentEmissionThread = True
     else:
         kwargs['ParentEmissionThread'] = None
     self.ParentEmissionThread = kwargs.get('ParentEmissionThread')
     self.Properties = {}
     self._Index_validate_default = True
     #cls = self.__class__
     #bases_limit = getattr(cls, '_saved_bases_limit', self._saved_class_name)
     signals_to_register = set()
     save_dict = {}
     for key in save_keys.iterkeys():
         save_dict.update({key:set()})
     self.SettingsProperties = {}
     self.SettingsPropKeys = []
     self.ChildGroups = {}
     childgroups = {}
     for cls in iterbases(self, BaseObject.__bases__[0]):
     #while cls != BaseObject.__bases__[0]:# and getattr(cls, '_saved_class_name', '') != bases_limit:
         if not hasattr(self, 'saved_class_name'):
             if hasattr(cls, '_saved_class_name'):
                 self.saved_class_name = cls._saved_class_name
         signals = getattr(cls, 'signals_to_register', None)
         if signals is not None:
             for s in signals:
                 signals_to_register.add(s)
         for key, val in save_keys.iteritems():
             if hasattr(cls, val):
                 save_dict[key] |= set(getattr(cls, val))
         for propname in getattr(cls, '_Properties', {}).iterkeys():
             prop = getattr(cls, propname)
             if isinstance(prop, Properties.ClsProperty):
                 prop.init_instance(self)
         if hasattr(cls, '_SettingsProperties'):
             spropkeys = cls._SettingsProperties[:]
             spropkeys.reverse()
             self.SettingsPropKeys.extend(spropkeys)
             for propname in spropkeys:
                 prop = self.Properties.get(propname)
                 if prop:
                     self.SettingsProperties.update({propname:prop})
             save_dict['saved_attributes'] |= set(cls._SettingsProperties)
         if hasattr(cls, '_ChildGroups'):
             for cgkey, cgval in cls._ChildGroups.iteritems():
                 if cgkey in childgroups:
                     childgroups[cgkey].update(cgval)
                 else:
                     childgroups[cgkey] = cgval
         #cls = cls.__bases__[0]
     self.SettingsPropKeys.reverse()
     self.SettingsPropKeys = tuple(self.SettingsPropKeys)
     for key, val in save_dict.iteritems():
         if not hasattr(self, key):
             setattr(self, key, val)
         
     if not hasattr(self, 'root_category'):
         self.root_category = kwargs.get('root_category')
     self.categories = {}
     self.categories_id = kwargs.get('categories_id', set())
     
     kwargs.update({'signals_to_register':signals_to_register})
     SignalDispatcher.dispatcher.__init__(self, **kwargs)
     
     prebind = kwargs.get('prebind', {})
     self.bind(**prebind)
     
     childgroup = kwargs.get('ChildGroup_parent')
     if childgroup is not None:
         self.ChildGroup_parent = childgroup
         
     for key, val in childgroups.iteritems():
         cgkwargs = val.copy()
         cgkwargs.setdefault('name', key)
         ds_cb = cgkwargs.get('deserialize_callback')
         if type(ds_cb) == str:
             cgkwargs['deserialize_callback'] = getattr(self, ds_cb, None)
         self.add_ChildGroup(**cgkwargs)
     
     Serializer.__init__(self, **kwargs)
     
     i = kwargs.get('Index')
     if self.Index is None and i is not None:
         self.Index = i
     
     self.register_signal('category_update')
     
     for c_id in self.categories_id:
         if not getattr(self, 'root_category', None):
             self.root_category = self.GLOBAL_CONFIG.get('ROOT_CATEGORY')
         category = self.root_category.find_category(id=c_id)
         if category:
             self.add_category(category)
         else:
             self.LOG.warning('could not locate category id: ' + str(c_id))
         
     f = getattr(self, 'on_program_exit', None)
     if f:
         atexit.register(f)