Commit 25b76d15 authored by Philipp Gast's avatar Philipp Gast
Browse files

cleaned up myFig_base init. myFig.update now prints the unknown keywords in debug mode.

parent 273df977
......@@ -83,32 +83,16 @@ class MyFig_base(Figure):
# CONSTRUCTOR --------------------------------------------------------
def __init__(self, rawdata, *args, **kwargs):
attributes = {'fignum': -1, # need to be hard coded for interactive mode
'reformat': D_REFORMAT,
'debug': D_DEBUG,
'formatted': D_FORMATTED}
# check attributes
for attribute in attributes.keys():
# if in kwargs
if attribute in kwargs.keys():
# overwrite default value
setattr(self, attribute, kwargs[attribute])
# suppress keyword from kwargs for Figure.__init__
del kwargs[attribute]
else:
setattr(self, attribute, attributes[attribute])
# If some user keywords are defined
if hasattr(self, 'keywords'):
# check keywords
for keyword in self.keywords.keys():
# if in kwargs
if keyword in kwargs.keys():
# overwrite the default value
self.keywords[keyword] = kwargs[keyword]
# suppress keyword from kwargs for Figure.__init__
del kwargs[keyword]
self._userAttributesKeys = ['fignum', 'reformat','debug','formatted']
self.fignum = kwargs.pop('fignum', -1) # need to be hard coded for interactive mode
self.reformat = kwargs.pop('reformat', D_REFORMAT)
self.debug = kwargs.pop('debug', D_DEBUG)
self.formatted = kwargs.pop('formatted', D_FORMATTED)
if hasattr(self,"keywords") :
self.update(**kwargs)
for key in self.keywords.keys() :
kwargs.pop(key,None) # remove key if exists
else:
self.keywords = {}
......@@ -142,24 +126,30 @@ class MyFig_base(Figure):
# UPDATE -------------------------------------------------------------
def update(self, **kwargs):
attributes = ('fignum', 'reformat', 'debug', 'formatted')
rdict = dict()
# check attributes in keywords
for keyword in kwargs.keys():
# if it is an attribute
if keyword in attributes:
if keyword in self._userAttributesKeys:
# update value
setattr(self, keyword, kwargs[keyword])
# if it is a user keyword
if keyword in self.keywords.keys():
elif keyword in self.keywords.keys():
# update
self.keywords[keyword] = kwargs[keyword]
# if it is the rawdata use the function
if keyword == 'rawdata':
elif keyword == 'rawdata':
self.set_rawdata(kwargs[keyword])
else:
rdict.update({keyword : kwargs[keyword]})
if (self.debug) :
print(DBUG + "These keywords have not been updated: " + str(rdict))
# PRINT 2 FILE -------------------------------------------------------
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment