def update(self,data={},name=None,removeLocals=False): """Add a dictionary to the Config object. The data, if specified, should be a valid Python dict. If no name is specified, the data are added to the top dictionary and will become attributes. If a name is specified, the data are added to the named attribute, which should be a dictionary. If the name does not specify a dictionary, an empty one is created, deleting the existing attribute. If a name is specified, but no data, the effect is to add a new empty dictionary (section) with that name. If removeLocals is set, keys starting with '_' are removed from the data before updating the dictionary and not included in the config. This behaviour can be changed by setting removeLocals to false. """ if removeLocals: for k in list(data.keys()): if k[0] == '_': del data[k] if name: if name not in self or not isinstance(self[name], dict): self[name] = Dict() self[name].update(data) else: Dict.update(self, data)
def __init__(self): """Create a new properties database.""" Dict.__init__(self) self.mats = MaterialDB() self.sect = SectionDB() self.prop = [] self.nprop = [] self.eprop = []
def __init__(self, label=None, value=None): """Create a new element load. Empty by default. An element load can hold the following sub-properties: - label: the distributed load type label. - value: the magnitude of the distibuted load. """ Dict.__init__(self, {"label": label, "value": value})
def __init__(self,mat='',sec=''): """Create a new properties database.""" setMaterialDB(mat) setSectionDB(sec) Dict.__init__(self) self.prop = [] self.nprop = [] self.eprop = []
def __init__(self,edge=-1,label=None,value=None): """Create a new element edge load. Empty by default. An element edgeload can hold the following sub-properties: - edge: the element edge number - label: the distributed load type label ('x','y','z'). - value: the magnitude of the distibuted load. """ Dict.__init__(self, {'edge':edge,'label':label,'value':value})
def __delitem__(self, key): """Allows items to be delete with del self[section/key]. """ i = key.rfind('/') if i == -1: Dict.__delitem__(self, key) else: del self[key[:i]][key[i+1:]]
def __init__(self,label=None,value=None,amplitude=None): """Create a new element load. Empty by default. An element load can hold the following sub-properties: - label: the distributed load type label. - value: the magnitude of the distibuted load. - amplitude: an amplitude instance. """ Dict.__init__(self,{'label':label,'value':value,'amplitude':amplitude})
def __init__(self,data={},default=None): """Creates a new Config instance. The configuration can be initialized with a dictionary, or with a variable that can be passed to the read() function. The latter includes the name of a config file, or a multiline string holding the contents of a configuration file. """ Dict.__init__(self, default=default) if isinstance(data, dict): self.update(data) elif data: self.read(data)
def __init__(self,data={},default=None): """Create a new Attributes dict""" if isinstance(default, Attributes): self._default_dict_ = default default = self._return_default_ elif default is None: default = returnNone elif callable(default): pass else: raise ValueError("The 'default' argument should be an Attributes instance or None; got %s:" % type(default)) default = returnNone Dict.__init__(self, data, default)
def __init__(self,label=None,value=None,dir=None): """Create a new element load. Empty by default. An element load can hold the following sub-properties: - label: the distributed load type label - value: the magnitude of the distibuted load - dir: vector specifying the direction of the load """ if label == 'GRAV': if dir is None: dir = [0, 0, -1] if value is None: value = 9.81 Dict.__init__(self, {'label':label,'value':value,'dir':dir})
def readDatabase(self,filename,*args,**kargs): """Import all records from a database file. For now, it can only read databases using flatkeydb. args and kargs can be used to specify arguments for the FlatDB constructor. """ mat = FlatDB(*args,**kargs) mat.readFile(filename) for k, v in mat.items(): self[k] = Dict(v)
def keys(self,descend=True): """Return the keys in the config. By default this descends one level of Dicts. """ keys = list(Dict.keys(self)) if descend: for k, v in self.items(): if isinstance(v, Dict): keys += ['%s/%s' % (k, ki) for ki in v] return keys
def setCamera(self,**kargs): """Set the camera position and direction. This takes two (optional) keyword parameters: - `position=`: specify a list of 3 coordinates. The camera will be positioned at that place, and be looking at the origin. This should be set to a proper distance from the scene to get a decent result on first display. - `upvector=`: specify a list of 3 components of a vector indicating the upwards direction of the camera. The default is [0.,1.,0.]. """ self._camera = Dict(kargs)
def __getitem__(self, key): """Allows items to be addressed as self[key]. This is equivalent to the Dict lookup, except that items in subsections can also be retrieved with a single key of the format section/key. While this lookup mechanism works for nested subsections, the syntax for config files allows for only one level of sections! Also beware that because of this functions, no '/' should be used inside normal keys and sections names. """ i = key.rfind('/') if i == -1: return Dict.__getitem__(self, key) else: try: return self[key[:i]][key[i+1:]] except KeyError: return self._default_(key)
def __setitem__(self, key, value): if value is None: if key in self: del self[key] else: Dict.__setitem__(self, key, value)
def __init__(self,data={}): """Initialize a database. The database can be initialized with a dict. """ Dict.__init__(self, data)
def __init__(self, data={}): """Initialize a database. The database can be initialized with a dict. """ Dict.__init__(self, data)