Commit d3ac4d81 authored by Philipp Gast's avatar Philipp Gast
Browse files

first test of keywords owned by axes. Test 309 still failing. Todo add alias test

parent 6adab381
......@@ -51,11 +51,13 @@ from . import rcParams
# Class MyAxes Overwriting Matplotlib.figure.Axes
class MyAxes(Axes):
# CONSTRUCTOR --------------------------------------------------------
def __init__(self, fig, ratio, frameRect, *args, **kwargs):
self.fig = fig
self.keywords={}
self.declareKeywords()
rect = self.computeRect(ratio, frameRect, *args, **kwargs)
kwargs.pop('forceRatioOnWidth', None)
......@@ -83,7 +85,11 @@ class MyAxes(Axes):
rect = [framePosX, framePosY, frameWidth, frameHeight]
return(rect)
# DECLARE KEYWORDS -------------------------------------------------
def declareKeywords(self):
pass
# PLOTTING -----------------------------------------------------------
def plotting(self):
return(True)
......
......@@ -96,28 +96,19 @@ class MyFig_base(Figure):
self.debug = kwargs.pop('debug', D_DEBUG)
self.formatted = kwargs.pop('formatted', D_FORMATTED)
# update the keywords with there values
if hasattr(self, "keywords") :
self.update(**kwargs)
# remove key if exists
for keyword in self.keywords.keys() :
kwargs.pop(keyword, None)
else:
self.keywords = {}
# initialise the rawdata
self.rawdata = rawdata
# add figsize in the kwargs for Figure.__init__
kwargs['figsize'] = self.FIGSIZE
# parent constructor
Figure.__init__(self, *args, **kwargs)
Figure.__init__(self,figsize=self.FIGSIZE)
# This is required for the interactive mode
# it ensures that a figure can not be bounded
# to several windows and prevent the loss of canvas.
self.boundedToWin = False
# this holds aliases for keywords that are defined in multiple axes
self.aliases={}
# initialise the rawdata
self.rawdata = rawdata
# DEBUG --------------------------------------------------------------
......@@ -146,10 +137,18 @@ class MyFig_base(Figure):
# update value
setattr(self, keyword, kwargs[keyword])
# if it is a user keyword
elif keyword in self.keywords.keys():
# if aliases is defined with that name
elif keyword in self.aliases.keys():
# update
self.keywords[keyword] = kwargs[keyword]
ax,key=self.aliases[keyword]
ax.keywords[key]=kwargs[keyword]
# if it is a axes keyword
elif keyword in [x for axl in self.get_axes() for x in axl.keywords.keys()]: #flattend array
for ax in self.get_axes() :
if keyword in ax.keywords.keys():
# set all axis who have that keyword
ax.keywords[keyword] = kwargs[keyword]
# if it is the rawdata use the function
elif keyword == 'rawdata':
......@@ -248,10 +247,6 @@ class MyFig(MyFig_base):
# CONSTRUCTOR ------------------------------------------------------
def __init__(self, rawdata, *args, **kwargs):
# define user keywords before
# __init__ to erase them from kwargs
self.declareKeywords()
MyFig_base.__init__(self, rawdata, *args, **kwargs)
self._initialize(*args, **kwargs)
......@@ -259,17 +254,14 @@ class MyFig(MyFig_base):
# INITIALIZE -------------------------------------------------------
def _initialize(self, *args, **kwargs):
# update the attributes and keywords
self.update(**kwargs)
# add the axes
self.addAxes()
# need to be done for the first init
self.set_rawdata(self.rawdata) # This function can be overwriten
# DECLARE KEYWORDS -------------------------------------------------
def declareKeywords(self):
# update the attributes and keywords
self.update(**kwargs)
# DECLARE ALIASES -------------------------------------------------
def declareAliases(self):
pass
# ADD AXES ---------------------------------------------------------
......@@ -363,6 +355,5 @@ class MyFig(MyFig_base):
# RESET ------------------------------------------------------------
def reset(self, *args, **kwargs):
self.clf()
self.declareKeywords()
self._initialize(*args, **kwargs)
self.plot()
......@@ -45,10 +45,19 @@
from .. import SEVR, DBUG, INFO
from .. import MyAxes
D_XRANGE = [-1, 1]
D_YRANGE = [-2, 2]
# Class MyAxes Overwriting Matplotlib.figure.Axes
class AxTest1(MyAxes):
def declareKeywords(self):
self.keywords = {'xRange': D_XRANGE,
'yRange': D_YRANGE}
return(True)
# PLOTTING -----------------------------------------------------------
# the plotting function (need to be overwrite from child
def plotting(self):
......
......@@ -71,9 +71,6 @@ from .. import MyFig, MyFig_base
from .axTest1 import AxTest1
D_XRANGE = [-1, 1]
D_YRANGE = [-2, 2]
# Class MyFig Overwriting Matplotlib.figure.Figure
class FigTest2(MyFig):
......@@ -82,13 +79,6 @@ class FigTest2(MyFig):
# (private variable can not be updated)
FIGSIZE = (8., 6.)
def declareKeywords(self):
self.keywords = {'xRange': D_XRANGE,
'yRange': D_YRANGE}
return(True)
def addAxes(self):
ratio = 6. / 8. # height/width of the axes (in inch)
......
......@@ -457,7 +457,8 @@ def test309(debug):
if fig.rawdata != ('dummy',):
status = False
if(not (not fig.debug and fig.reformat and not fig.formatted)): # EXPECT: False, True, False
if(not (not fig.debug and fig.reformat and not fig.formatted)): # EXPECT: False, True, False # got: False, True, True
print(fig.debug, fig.reformat ,fig.formatted)
status = False
if not hasattr(fig, 'FIGSIZE'):
......
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