How to use the ganga.GangaCore.GPIDev.Base.Objects.Descriptor function in ganga

To help you get started, we’ve selected a few ganga examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ganga-devs / ganga / ganga / GangaCore / GPIDev / Base / Objects.py View on Github external
self._check_getter()

        # make sure we have the session lock
        obj._getSessionLock(root_obj)

        # make sure the object is loaded if it's attached to a registry
        obj._loadObject()

        basic=False
        for i in [int, str, bool, type]:
            if isinstance(val, i):
                new_value = deepcopy(val)
                basic=True
                break
        if not basic:
            new_value = Descriptor.cleanValue(obj, val, _set_name)

        obj.setSchemaAttribute(_set_name, new_value)

        obj._setDirty()
github ganga-devs / ganga / ganga / GangaCore / GPIDev / Base / Objects.py View on Github external
if hasattr(cls, '_additional_slots'):
            attrs_to_add += [_ for _ in cls._additional_slots]

        cls.__slots__ = ('_index_cache_dict', '_registry', '_data_dict', '__dict__', '_proxyObject') + tuple(attrs_to_add)

        # If a class has not specified a '_name' then default to using the class '__name__'
        if not cls.__dict__.get('_name'):
            cls._name = name

        if this_schema._pluginclass is not None:
            logger.warning('Possible schema clash in class %s between %s and %s', name, _getName(cls), _getName(this_schema._pluginclass))

        # export visible properties... do not export hidden properties
        # This constructs one Descriptor for each attribute which can be set for this class
        for attr, item in this_schema.allItems():
            setattr(cls, attr, Descriptor(attr, item))

        # additional check of type
        # bugfix #40220: Ensure that default values satisfy the declared types
        # in the schema
        for attr, item in this_schema.simpleItems():
            if not item['getter']:
                item._check_type(item['defvalue'], '.'.join([name, attr]), False)

        # create reference in schema to the pluginclass
        this_schema._pluginclass = cls

        # if we've not even declared this we don't want to use it!
        if not cls._declared_property('hidden') or cls._declared_property('enable_plugin'):
            allPlugins.add(cls, cls._category, _getName(cls))

        # create a configuration unit for default values of object properties
github ganga-devs / ganga / ganga / GangaCore / GPIDev / Base / Objects.py View on Github external
new_v = GangaList()
                except ImportError:
                    new_v = []
                for elem in v:
                    new_v.append(Descriptor.cloneObject(elem, obj, name))
                #return new_v
            elif not isinstance(v, Node):
                if isclass(v):
                    new_v = v()
                else:
                    new_v = v
                if not isinstance(new_v, Node):
                    logger.error("v: %s" % v)
                    raise GangaException("Error: found Object: %s of type: %s expected an object inheriting from Node!" % (v, type(v)))
                else:
                    new_v = Descriptor.cloneNodeObject(new_v, obj, name)
            else:
                new_v = Descriptor.cloneNodeObject(v, obj, name)

            return new_v
github ganga-devs / ganga / ganga / GangaCore / GPIDev / Base / Objects.py View on Github external
else:
                if isinstance(item, ComponentItem):
                    new_val = makeGangaList(val, Descriptor.cloneListOrObject, obj, _preparable, (name, obj))
                else:
                    new_val = makeGangaList(val, None, obj, _preparable)
        else:
            ## Else we need to work out what we've got.
            if isinstance(item, ComponentItem):
                if isinstance(val, (list, tuple, GangaList)):
                    ## Can't have a GangaList inside a GangaList easily so lets not
                    if isinstance(obj, GangaList):
                        new_val = []
                    else:
                        new_val = GangaList()
                    # Still don't know if val list of object here
                    Descriptor.createNewList(new_val, val, Descriptor.cloneListOrObject, (name, obj))
                else:
                    # Still don't know if val list of object here
                    new_val = Descriptor.cloneListOrObject(val, (name, obj))
            else:
                new_val = val
                pass

        if isinstance(new_val, Node) and new_val._getParent() is not obj:
            new_val._setParent(obj)
        return new_val
github ganga-devs / ganga / ganga / GangaCore / GPIDev / Base / Objects.py View on Github external
self._check_getter()

        # make sure we have the session lock
        obj._getSessionLock(root_obj)

        # make sure the object is loaded if it's attached to a registry
        obj._loadObject()

        basic=False
        for i in [int, str, bool, type]:
            if isinstance(val, i):
                new_value = deepcopy(val)
                basic=True
                break
        if not basic:
            new_value = Descriptor.cleanValue(obj, val, _set_name)

        obj.setSchemaAttribute(_set_name, new_value)

        obj._setDirty()
github ganga-devs / ganga / ganga / GangaCore / GPIDev / Base / Objects.py View on Github external
else:
                    new_val = makeGangaList(val, None, obj, _preparable)
        else:
            ## Else we need to work out what we've got.
            if isinstance(item, ComponentItem):
                if isinstance(val, (list, tuple, GangaList)):
                    ## Can't have a GangaList inside a GangaList easily so lets not
                    if isinstance(obj, GangaList):
                        new_val = []
                    else:
                        new_val = GangaList()
                    # Still don't know if val list of object here
                    Descriptor.createNewList(new_val, val, Descriptor.cloneListOrObject, (name, obj))
                else:
                    # Still don't know if val list of object here
                    new_val = Descriptor.cloneListOrObject(val, (name, obj))
            else:
                new_val = val
                pass

        if isinstance(new_val, Node) and new_val._getParent() is not obj:
            new_val._setParent(obj)
        return new_val
github ganga-devs / ganga / ganga / GangaCore / GPIDev / Base / Objects.py View on Github external
name (str): This is the name of the attribute which we're changing
        """

        item = obj._schema[name]

        ## If the item has been defined as a sequence great, let's continue!
        if item['sequence']:
            # These objects are lists
            _preparable = True if item['preparable'] else False
            if val is None:
                new_val = None
            elif len(val) == 0:
                new_val = GangaList()
            else:
                if isinstance(item, ComponentItem):
                    new_val = makeGangaList(val, Descriptor.cloneListOrObject, obj, _preparable, (name, obj))
                else:
                    new_val = makeGangaList(val, None, obj, _preparable)
        else:
            ## Else we need to work out what we've got.
            if isinstance(item, ComponentItem):
                if isinstance(val, (list, tuple, GangaList)):
                    ## Can't have a GangaList inside a GangaList easily so lets not
                    if isinstance(obj, GangaList):
                        new_val = []
                    else:
                        new_val = GangaList()
                    # Still don't know if val list of object here
                    Descriptor.createNewList(new_val, val, Descriptor.cloneListOrObject, (name, obj))
                else:
                    # Still don't know if val list of object here
                    new_val = Descriptor.cloneListOrObject(val, (name, obj))
github ganga-devs / ganga / ganga / GangaCore / GPIDev / Base / Objects.py View on Github external
def __init__(self, name, item):
        """
        Lets build a descriptor for this item with this name
        Args:
            name (str): Name of the attribute being wrapped
            item (Item): The Schema entry describing this attribute (Not currently used atm)
        """
        super(Descriptor, self).__init__()

        self._name = name
        self._item = item
        self._checkset_name = None
        self._filter_name = None

        self._getter_name = item['getter']
        self._checkset_name = item['checkset']
        self._filter_name = item['filter']