Commit 1c8b8680 authored by Yori Fournier's avatar Yori Fournier
Browse files

made mpl_fig, mpl_grid pep8 compilant

parent 1fc7e78e
......@@ -117,7 +117,7 @@ if D_HIERARCHY in ('CLIENT', 'client'):
from .mpl_axes_client import MplAxesClient as MplAxes
from .mpl_grid import Grid, VerticalGrid, HorizontalGrid
# MplFig: Overlay on matplotlib.Figure class
from .mpl_fig_client import MplFigClient as MplFig
......@@ -127,11 +127,11 @@ if D_HIERARCHY in ('CLIENT', 'client'):
elif(D_HIERARCHY in ('SERVER', 'server')):
# MplAxes: Overlay on matplotlib.Axes class
# MplAxes: Overlay on matplotlib.Axes class
from .mpl_axes_server import MplAxesServer as MplAxes
from .mpl_grid import Grid, VerticalGrid, HorizontalGrid
# MplFig: Overlay on matplotlib.Figure class
from .mpl_fig_server import MplFigServer as MplFig
......@@ -140,7 +140,7 @@ elif(D_HIERARCHY in ('SERVER', 'server')):
# 'readStupidData2': readStupidData2
}
SERVER_FIGURES = {
#'FigTest': FigTest
# 'FigTest': FigTest
}
from .mpl_server import MplServer, MplHandler
......
......@@ -124,7 +124,7 @@ if run4Test:
print(INFO + "TESTS: ")
for test in testList:
print('\n')
print(INFO + '{title:{c}^{n}}'.format(title=' ' + \
print(INFO + '{title:{c}^{n}}'.format(title=' ' +
str(test.__name__) + ' ', c='=', n=72))
# function, expected, fail, debug
testStatus = myTest(test, True, fail, debug)
......
......@@ -110,7 +110,7 @@ class MplFig(Figure):
# add a default Grid to the figure
self.set_grid(HorizontalGrid())
# initialise
self._initialize(*args, **kwargs)
self.set_rawdata(rawdata)
......@@ -119,7 +119,9 @@ class MplFig(Figure):
def _initialize(self, *args, **kwargs):
# add the axes
self.addAxes() # This will throw a pep8 error but its needed to prevent confusion with matplotlib
self.addAxes()
# This will throw a pep8 error but its needed to prevent
# confusion with matplotlib -- need another name
# declare the aliases
self.declare_aliases()
......@@ -183,25 +185,28 @@ class MplFig(Figure):
def declare_aliases(self):
pass
# ADD AXES ---------------------------------------------------------
# ADD AXES --------------------------------------------------------
def addAxes(self, *arg, **kwargs):
raise(NotImplementedError, 'The addAxes method needs to be implemented.')
raise(NotImplementedError,
'The addAxes method needs to be implemented.')
# This overwrites MPL add_axes. It gives a name to the axis added so that
# it is easier to refer to
def add_axes(self, ax, name):
# if isinstance(name, str) and issubclass(ax.__class__, MyAxes): # This
# lead to an error is ax is not in the same namespace
# if isinstance(name, str) and issubclass(ax.__class__, MyAxes):
# This lead to an error is ax is not in the same namespace
ax.name = name
# else:
# print(SEVR + " there is an error with the input type of add_axes()")
# print("{sevr} there is an error with the input type of \
# add_axes()".format(sevr=SEVR))
# return False
# test if an axes with that name is already present
for pax in self.get_axes():
if pax.name == name:
print(SEVR + " an axes with that name is already present")
print("{sevr} an axes with that name is already present\
".format(sevr=SEVR))
return False
Figure.add_axes(self, ax)
......@@ -216,7 +221,8 @@ class MplFig(Figure):
return ax
# if the name is correct we should never get here.
print(SEVR + "The axes name ", name, " was not found")
print("{sevr} The axes name {axes_name}, was not found\
".format(sevr=SEVR, axes_name=name))
return None
# SET LAYOUT -------------------------------------------------------
......@@ -227,7 +233,7 @@ class MplFig(Figure):
# LAYOUT -----------------------------------------------------------
def layout(self):
self.grid.layout()
# SET RAW DATA -----------------------------------------------------
def set_rawdata(self, rawdata):
......@@ -242,34 +248,40 @@ class MplFig(Figure):
if len(rawdata) == len(self.get_axes()):
if(self.debug):
print(DBUG + "set_rawdata: one item per axes")
print("{dbug} set_rawdata: one item per axes\
".format(dbug=DBUG))
self.rawdata = rawdata
status = self.format_rawdata()
else:
self.rawdata = None
print(SEVR +
"rawdata should have the dimention of the number of axes: #axes = " +
str(len(self.get_axes())) +
"; dim of rawdata = " +
str(len(rawdata)))
print("{sevr} rawdata should have the dimention of \
the number of axes: nbr of axes={nbr_axes} ; \
dim of rawdata={len_rawdata} \
".format(sevr=SEVR,
nbr_axes=len(self.get_axes()),
len_rawdata=len(rawdata)))
return(False)
# CONVINIENT: one object for all axes
elif isinstance(rawdata, MplData):
if(self.debug):
print(DBUG + "set_rawdata: one item for all axes")
print("{dbug} set_rawdata: one item for all axes\
".format(dbug=DBUG))
# This is the trick rawdata becomes a generator (so smart)
self.rawdata = repeat(rawdata)
status = self.format_rawdata()
else:
print(SEVR + "set_rawdata: I could not set the rawdata...")
print("{sevr} set_rawdata: I could not set the rawdata...\
".format(sevr=SEVR))
self.rawdata = None
status = False
if not status:
print(SEVR + "set_rawdata: I could not set the rawdata...")
print("{sevr} set_rawdata: I could not set the rawdata...\
".format(sevr=SEVR))
self.rawdata = None
return(status)
......@@ -284,13 +296,12 @@ class MplFig(Figure):
status = False
if(self.debug):
print(INFO +
"Axes: " +
str(ax.__class__.__name__) +
" with index " +
str(self.get_axes().index(ax)) +
" formats " +
rawdata.name)
print("{info} Axes: {axes_class_name} \
with index {index} formats {rawdata_name}\
".format(info=INFO,
axes_class_name=ax.__class__.__name__,
index=self.get_axes().index(ax),
rawdata_name=rawdata.name))
status = ax.test_rawdata(rawdata)
if status:
status = ax.format_rawdata(rawdata)
......@@ -300,12 +311,11 @@ class MplFig(Figure):
try:
status = ax.format_rawdata(rawdata)
except BaseException:
print(SEVR +
"The " +
str(ax.__class__.__name__) +
" with index " +
str(self.get_axes().index(ax)) +
" could not format the rawdata.")
print("{sevr} The {axes_class_name} \
with index {index} could not format the rawdata.\
".format(sevr=SEVR,
axes_class_name=ax.__class__.__name__,
index=self.get_axes().index(ax)))
return(False)
if not status:
......@@ -325,7 +335,8 @@ class MplFig(Figure):
status = True
if(self.debug):
print(DBUG + "currently formatting the data...")
print("{dbug} currently formatting the data...\
".format(dbug=DBUG))
if((self.reformat) or (not self.formatted)):
status = self.format_rawdata()
......@@ -333,7 +344,8 @@ class MplFig(Figure):
return(False)
if(self.debug):
print(DBUG + "currently plotting the axes...")
print("{dbug} currently plotting the axes...\
".format(dbug=DBUG))
# For all axes in the figure reformat if needed and plot
for ax in self.get_axes():
......@@ -378,9 +390,11 @@ class MplFig(Figure):
dpi = 100.
add_metadata = False # NOT YET IMPLEMENTED
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.backends.backend_agg import FigureCanvasAgg
as FigureCanvas
# if the figure is boundedToWin
# save to canvas in a local variable and restore after saving to file.
# save to canvas in a local variable
# and restore after saving to file.
if self.bounded_to_win:
win_canvas = self.canvas
else:
......@@ -409,9 +423,10 @@ class MplFig(Figure):
# check if the path is in the name
if '/' in str(filename):
if(debug):
print(
WARN +
"I detect that the path is in the name of the file, will ignore D_OPATH.")
print("{warn} I detect that the path is in \
the name of the file, will ignore D_OPATH.\
".format(warn=WARN))
arg = filename
filename = os.path.basename(arg)
opath = os.path.dirname(arg)
......
......@@ -41,10 +41,10 @@ class Grid(object):
def get_grids(self):
return(self.grids)
def contains_a_grid(self):
return(len(self.grids) > 0)
def set_position(self, pos):
left, bottom, width, height = pos
self.left = left
......@@ -59,30 +59,35 @@ class VerticalGrid(Grid):
nbr_axes = len(self.items)
if nbr_axes > 0:
axes_height = (self.height - (nbr_axes-1)*self.padding - 2.*self.margin)/nbr_axes
axes_height = (self.height - (nbr_axes-1)*self.padding -
2.*self.margin)/nbr_axes
for index in range(0, nbr_axes):
new_left = self.margin + self.left
new_bottom = self.margin + self.bottom + index*axes_height + index*self.padding
new_width = self.width - 2.*self.margin
new_bottom = self.margin + self.bottom + \
index*axes_height + index*self.padding
new_width = self.width - 2.*self.margin
new_height = axes_height
new_frame = [new_left, new_bottom, new_width, new_height]
self.items[index].set_position(new_frame)
Grid.layout(self)
Grid.layout(self)
class HorizontalGrid(Grid):
def layout(self):
nbr_axes = len(self.items)
if nbr_axes > 0:
axes_width = (self.width - (nbr_axes-1)*self.padding - 2.*self.margin)/nbr_axes
axes_width = (self.width - (nbr_axes-1)*self.padding -
2.*self.margin)/nbr_axes
for index in range(0, nbr_axes):
new_left = self.margin + self.left + index*axes_width + index*self.padding
new_bottom = self.margin + self.bottom
new_left = self.margin + self.left + \
index*axes_width + index*self.padding
new_bottom = self.margin + self.bottom
new_width = axes_width
new_height = self.height - 2.*self.margin
new_frame = [new_left, new_bottom, new_width, new_height]
self.items[index].set_position(new_frame)
Grid.layout(self)
Grid.layout(self)
......@@ -60,7 +60,7 @@ class Query(Signal):
class Status(Signal):
def __init__(self, value, error):
if (value == True) or (value == False):
if value in [True, False]:
self.value = value
else:
print('value parameter of a status signal'
......
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