Commit 6adab381 authored by Yori Fournier's avatar Yori Fournier
Browse files

Merge branch '18-issue' into 'dev'

Resolve "Allow user to use either a single rawdata element or a list."

Closes #18

See merge request !24
parents 6e83ddd4 175a8939
......@@ -38,6 +38,8 @@
# of a constructor, a pltting function and
# formatRawData.
#
# v 2.2.3 - Add testRawData function
#
# ======================================================================
#
#
......@@ -83,10 +85,13 @@ class MyAxes(Axes):
return(rect)
# PLOTTING -----------------------------------------------------------
# the plotting function (need to be overwrite from child
def plotting(self):
pass
return(True)
# FORMATTING ---------------------------------------------------------
def formatRawData(self, rawdata):
pass
return(True)
# TESTING THE RAWDATA ------------------------------------------------
def testRawData(self, rawdata):
return(True)
......@@ -61,6 +61,9 @@
# add the attribute boundedToWin required for the
# interactive mode of myplotlib.
#
# v 2.2.3 - Allow the possibility of giving a unique rawdata format
# all axes. /!\ self.rawdata is a generator. /!\
#
# ======================================================================
#
#
......@@ -70,6 +73,7 @@ from . import D_FIGSIZE, D_INPUTARG, D_DEBUG, D_REFORMAT, D_FORMATTED
from . import D_OFORMAT, D_OPATH
from . import DBUG, SEVR, INFO, SPCE, WARN
from . import G_RAWDATAS
from . import MyData
from . import Figure
......@@ -271,24 +275,32 @@ class MyFig(MyFig_base):
# ADD AXES ---------------------------------------------------------
def addAxes(self, *arg, **kwargs):
pass
# SET RAW DATA -----------------------------------------------------
def set_rawdata(self, rawdata):
if(type(rawdata) != tuple):
print(SEVR + "rawdata should be a tuple. i.e. (data1,)")
return(False)
from collections import Iterable
from itertools import repeat
if(len(self.get_axes()) == len(rawdata)):
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
self.formatted = False
self.formatRawData()
else:
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 = ()
print(SEVR + "rawdata should have the dimention of the number of axes: #axes = " + str(len(self.get_axes())) + "; dim of rawdata = " + str(len(rawdata)))
return(False)
status = False
return(True)
return(status)
# FORMAT RAW DATA --------------------------------------------------
def formatRawData(self):
......@@ -298,13 +310,18 @@ class MyFig(MyFig_base):
status = False
if(self.debug):
status = ax.formatRawData(rawdata)
else:
try:
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)
except:
print(SEVR + "The " + str(ax.__class__.__name__) + " with index " + str(self.get_axes().index(ax)) + " could not format the rawdata.")
return(False)
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)
......
......@@ -828,7 +828,7 @@ def test505(debug):
print(SPCE + "it should be " + str(data2.data))
status = False
if(debug): print(DBUG + "the data were not formatted by the axes.")
win.close()
del ax
del data1
......
Markdown is supported
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