Commit 13f30740 authored by Yori 'AGy' Fournier's avatar Yori 'AGy' Fournier
Browse files

removed myFig_base now just myFig

- all tests go through
- Now if data does not exists set to None
parent 3d6292d6
......@@ -69,7 +69,7 @@ from .config import rcParams
from .myAxes import MyAxes
# MyFig: Overlay on matplotlib.Figure class
from .myFig import MyFig_base, MyFig
from .myFig import MyFig
# MyFig: Overlay on matplotlib.FigureManager class
if rcParams['backend'] == u'TkAgg':
......
......@@ -78,7 +78,7 @@ from . import Figure
# Class MyFig Overwriting Matplotlib.figure.Figure
class MyFig_base(Figure):
class MyFig(Figure):
# Set the size of the Figure in inch
# (private variable can not be updated)
......@@ -97,37 +97,33 @@ class MyFig_base(Figure):
self.formatted = kwargs.pop('formatted', D_FORMATTED)
# parent constructor
Figure.__init__(self,figsize=self.FIGSIZE)
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.set_rawdata(rawdata)
# DEBUG --------------------------------------------------------------
def printDebug(self):
className = str(self.__class__.__name__)
print('\n' + DBUG + " {0} PARAMETERS: ".format(className))
print(SPCE + " Raw data: " + str(self.rawdata))
print(SPCE + " ID the figure: " + str(self.fignum))
print(SPCE + "Size of the figure: " + str(self.FIGSIZE) + ' [inch] \n')
# initialise
kwargs.update({'rawdata': rawdata})
self._initialize(*args, **kwargs)
# PLOT ---------------------------------------------------------------
def plot(self):
pass
# INITIALIZE -------------------------------------------------------
def _initialize(self, *args, **kwargs):
# add the axes
self.addAxes()
# declare the aliases
self.declareAliases()
# update the attributes and keywords
self.update(**kwargs)
# UPDATE -------------------------------------------------------------
# UPDATE ----------------------------------------------------------
def update(self, **kwargs):
rest = dict()
rest = kwargs.copy()
# check attributes in keywords
for keyword in kwargs.keys():
......@@ -136,32 +132,150 @@ class MyFig_base(Figure):
if keyword in self._attributesToUpdateKeys:
# update value
setattr(self, keyword, kwargs[keyword])
del rest[keyword]
# if it is the rawdata use the function
elif keyword == 'rawdata':
self.set_rawdata(kwargs['rawdata'])
del rest['rawdata']
# if aliases is defined with that name
elif keyword in self.aliases.keys():
# update
ax,key=self.aliases[keyword]
ax.keywords[key]=kwargs[keyword]
ax, key = self.aliases[keyword]
ax.keywords[key] = kwargs[keyword]
del rest[keyword]
# if it is an axes keyword
else:
# 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':
self.set_rawdata(kwargs[keyword])
ax.keywords.update({keyword: kwargs[keyword]})
delete = True
else:
rest.update({keyword : kwargs[keyword]})
if delete:
del rest[keyword]
if (self.debug and rest != {}) :
print(DBUG + "These keywords have not been updated: " + str(rest))
return(True)
# DECLARE ALIASES -------------------------------------------------
def declareAliases(self):
self.aliases = {}
# ADD AXES ---------------------------------------------------------
def addAxes(self, *arg, **kwargs):
pass
# SET RAW DATA -----------------------------------------------------
def set_rawdata(self, rawdata):
from collections import Iterable
from itertools import repeat
self.formatted = False
status = False
# DEFAULT: one item per axes in figure
if isinstance(rawdata, Iterable):
if(self.debug): print(DBUG + "set_rawdata: one item per axes")
self.rawdata = rawdata
status = self.formatRawData()
# CONVINIENT: one object for all axes
elif isinstance(rawdata, MyData):
if(self.debug): print(DBUG + "set_rawdata: one item for all axes")
self.rawdata = repeat(rawdata) # This is the trick rawdata becomes a generator (so smart)
status = self.formatRawData()
else :
print(SEVR + "set_rawdata: I could not set the rawdata...")
self.rawdata = None
status = False
if not status:
self.rawdata = None
return(status)
# FORMAT RAW DATA --------------------------------------------------
def formatRawData(self):
if self.rawdata != None:
for ax, rawdata in zip(self.get_axes(), self.rawdata):
status = False
if(self.debug):
print(INFO + "Axes: " + str(ax.__class__.__name__) + " with index " + str(self.get_axes().index(ax)) + " formats " + rawdata.name)
status = ax.testRawData(rawdata)
if status :
status = ax.formatRawData(rawdata)
else:
status = ax.testRawData(rawdata)
if status:
try:
status = ax.formatRawData(rawdata)
except:
print(SEVR + "The " + str(ax.__class__.__name__) + " with index " + str(self.get_axes().index(ax)) + " could not format the rawdata.")
return(False)
if not status:
return(False)
if self.formatted is False:
self.formatted = True
return(True)
else:
return(False)
# PLOT -------------------------------------------------------------
def plot(self):
status = True
if(self.debug):
print(DBUG + "currently formatting the data...")
if((self.reformat) or (not self.formatted)):
status = self.formatRawData()
if(not status): return(False)
if(self.debug):
print(DBUG + "currently plotting the axes...")
# For all axes in the figure reformat if needed and plot
for ax in self.get_axes():
# clean the axes
ax.cla()
# plot
plottingStatus = ax.plotting()
status = status and plottingStatus
return(status)
# RESET ------------------------------------------------------------
def reset(self, *args, **kwargs):
self.clf()
self._initialize(*args, **kwargs)
self.plot()
# DEBUG --------------------------------------------------------------
def printDebug(self):
className = str(self.__class__.__name__)
print('\n' + DBUG + " {0} PARAMETERS: ".format(className))
print(SPCE + " Raw data: " + str(self.rawdata))
print(SPCE + " ID the figure: " + str(self.fignum))
print(SPCE + "Size of the figure: " + str(self.FIGSIZE) + ' [inch] \n')
# PRINT 2 FILE -------------------------------------------------------
def print2file(self, filename, *args, **kwargs):
......@@ -239,121 +353,3 @@ class MyFig_base(Figure):
self.canvas = winCanvas
return(True)
# CLASS MyFig ==========================================================
class MyFig(MyFig_base):
# CONSTRUCTOR ------------------------------------------------------
def __init__(self, rawdata, *args, **kwargs):
MyFig_base.__init__(self, rawdata, *args, **kwargs)
self._initialize(*args, **kwargs)
# INITIALIZE -------------------------------------------------------
def _initialize(self, *args, **kwargs):
# add the axes
self.addAxes()
# update the attributes and keywords
self.update(**kwargs)
# DECLARE ALIASES -------------------------------------------------
def declareAliases(self):
pass
# ADD AXES ---------------------------------------------------------
def addAxes(self, *arg, **kwargs):
pass
# SET RAW DATA -----------------------------------------------------
def set_rawdata(self, rawdata):
print("was in setrawdata")
from collections import Iterable
from itertools import repeat
self.formatted = False
status = False
# DEFAULT: one item per axes in figure
if isinstance(rawdata, Iterable):
if(self.debug): print(DBUG + "set_rawdata: one item per axes")
self.rawdata = rawdata
status = self.formatRawData()
# CONVINIENT: one object for all axes
elif isinstance(rawdata, MyData):
if(self.debug): print(DBUG + "set_rawdata: one item for all axes")
self.rawdata = repeat(rawdata) # This is the trick rawdata becomes a generator (so smart)
status = self.formatRawData()
else :
print(SEVR + "set_rawdata: I could not set the rawdata...")
self.rawdata = ()
status = False
return(status)
# FORMAT RAW DATA --------------------------------------------------
def formatRawData(self):
print("now in formatawdata")
for ax, rawdata in zip(self.get_axes(), self.rawdata):
status = False
if(self.debug):
print(INFO + "Axes: " + str(ax.__class__.__name__) + " with index " + str(self.get_axes().index(ax)) + " formats " + rawdata.name)
status = ax.testRawData(rawdata)
if status :
status = ax.formatRawData(rawdata)
else:
status = ax.testRawData(rawdata)
if status:
try:
status = ax.formatRawData(rawdata)
except:
print(SEVR + "The " + str(ax.__class__.__name__) + " with index " + str(self.get_axes().index(ax)) + " could not format the rawdata.")
return(False)
if not status:
return(False)
if self.formatted is False:
self.formatted = True
return(True)
# PLOT -------------------------------------------------------------
def plot(self):
status = True
self.update()
if(self.debug):
print(DBUG + "currently formatting the data...")
if((self.reformat) or (not self.formatted)):
status = self.formatRawData()
if(not status): return(False)
if(self.debug):
print(DBUG + "currently plotting the axes...")
# For all axes in the figure reformat if needed and plot
for ax in self.get_axes():
# clean the axes
ax.cla()
# plot
plottingStatus = ax.plotting()
status = status and plottingStatus
return(status)
# RESET ------------------------------------------------------------
def reset(self, *args, **kwargs):
self.clf()
self._initialize(*args, **kwargs)
self.plot()
......@@ -48,6 +48,7 @@ from .. import MyAxes
D_XRANGE = None
D_YRANGE = None
# Class MyAxes Overwriting Matplotlib.figure.Axes
class AxTest1(MyAxes):
......@@ -66,7 +67,7 @@ class AxTest1(MyAxes):
try:
self.data = {'xdata': [rawdata.data[0], rawdata.data[1]],
'ydata': [rawdata.data[2], rawdata.data[3]]}
except (TypeError, KeyError,IndexError):
except(TypeError, KeyError, IndexError):
print(SEVR + 'The Raw Data could not be formatted --> EXIT')
return(False)
......
......@@ -67,7 +67,7 @@
# IMPORT ---------------------------------------------------------------
from .. import os
from .. import DBUG, SEVR, INFO, SPCE, WARN
from .. import MyFig, MyFig_base
from .. import MyFig
from .axTest1 import AxTest1
......
......@@ -418,7 +418,7 @@ def test308(debug):
print(DBUG + "test without data: " + str(status))
fig.debug = debug
G_RAWDATAS.update({'data': MyData()})
G_RAWDATAS['data'].data = [1, -1, -1, 1]
......@@ -453,12 +453,12 @@ def test309(debug):
if fig.fignum != -12:
status = False
if fig.rawdata != ('dummy',):
if fig.rawdata is not None:
status = 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)
if(not (not fig.debug and fig.reformat and not fig.formatted)): # EXPECT: False, True, False
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