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

pep8 compliance of the modified files

parent f2522448
Pipeline #485 failed with stage
in 5 minutes and 33 seconds
......@@ -70,7 +70,7 @@ if D_HIERARCHY in ('CLIENT', 'client', 'LOCAL', 'local'):
from matplotlib.pyplot import close as mpclose
from matplotlib.pyplot import fignum_exists, savefig
from matplotlib.axes import Axes
from matplotlib.figure import FigureType name of new folder
from matplotlib.figure import Figure_type
from matplotlib import is_interactive
from matplotlib import use
......
......@@ -103,7 +103,7 @@ class MplClient2():
return True
else:
if debug:
print('something went wrong on the ' \
print('something went wrong on the '
'server side handling request type',
org_query.query_type)
print(status_sig.content)
......@@ -135,7 +135,7 @@ class MplClient2():
query = Query(Query.LISTDATA, None)
status = self.send(query)
if not status:
print('something went wrong with the ' \
print('something went wrong with the '
'sending of listRemoteData request...')
answer = self.waitForSignal()
......@@ -154,7 +154,7 @@ class MplClient2():
query = Query(Query.LISTFIG, None)
status = self.send(query)
if not status:
print('something went wrong with the ' \
print('something went wrong with the '
'sending of listRemoteFig request...')
answer = self.waitForSignal()
......@@ -174,7 +174,7 @@ class MplClient2():
query = Query(Query.GETDATA, dataname)
status = self.send(query)
if not status:
print('something went wrong with the ' \
print('something went wrong with the '
'sending of readData request...')
answer = self.waitForSignal()
......@@ -204,7 +204,7 @@ class MplClient2():
status = self.send(query)
if not status:
print('something went wrong ' \
print('something went wrong '
'with the sending of newSincFigure request...')
answer = self.wait_for_signal()
......
......@@ -2,6 +2,7 @@ _D_MARGIN = 0.05
_D_PADDING = 0.05
_D_POS = [0.0, 0.0, 1.0, 1.0]
class Grid(object):
def __init__(self, pos=_D_POS, margin=_D_MARGIN, padding=_D_PADDING):
......@@ -18,19 +19,19 @@ class Grid(object):
def layout(self):
pass
def appendAxes(self, ax, axlabel, rawdata):
def append_axes(self, ax, axlabel, rawdata):
self.items.append(ax)
self.fig.add_axes(ax, axlabel)
self.fig.set_rawdata(self.fig.rawdata + (rawdata,))
def appendGrid(self, grid):
def append_grid(self, grid):
self.items.append(grid)
self.items[-1].fig = self.fig
def getItem(self, index):
def get_item(self, index):
return(self.items[index])
def getItems(self):
def get_items(self):
return(self.items)
def set_position(self, pos):
......@@ -40,28 +41,35 @@ class Grid(object):
self.width = width
self.height = height
class VerticalGrid(Grid):
def layout(self):
nbr_axes = len(self.items)
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)
class HorizontalGrid(Grid):
def layout(self):
nbr_axes = len(self.items)
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)
self.items[index].set_position(new_frame)
import sys
import pickle
class MplUnpickler(pickle.Unpickler):
def find_class(self, module, name):
# print('MODULE: '+module)
# print('CLASS: '+name)
# print('OWN MODULE: ' + self.__module__)
own_module = self.__module__
own_module = own_module.replace('.mpl_unpickler', '')
modulelist = module.split('.')
# print(modulelist)
if 'myplotlib' in modulelist:
index = modulelist.index('myplotlib')
class_path = '.' + '.'.join(modulelist[index+1:])
module = own_module + class_path
# print('NEW MODULE: ' + module)
return(getattr(sys.modules[module], name))
return(getattr(sys.modules[module], name))
......@@ -50,154 +50,160 @@ from . import rcParams
_D_FRAME = [0.1, 0.1, 0.8, 0.8]
# COMPUTE SMART FRAME -----------------------------------------------
def computeFitRect(fig, ratio, frameRect):
def compute_fit_rect(fig, ratio, frame_rect):
# get the frame allowed
framePosX, framePosY, frameWidth, frameHeight = frameRect
frame_pos_x, frame_pos_y, frame_width, frame_height = frame_rect
# get the size of the figure
figWidth = fig.get_figwidth()
figHeight = fig.get_figheight()
figDpi = fig.get_dpi()
fig_width = fig.get_figwidth()
fig_height = fig.get_figheight()
fig_dpi = fig.get_dpi()
# get the font size in inches
fontsize = rcParams['font.size'] / figDpi
fontsize = rcParams['font.size'] / fig_dpi
# the largest width and height allowed in inches
maxWidth = figWidth * frameWidth - 8. * (figDpi / 75.) * fontsize
maxHeight = figHeight * frameHeight - 4. * (figDpi / 75.) * fontsize
max_width = fig_width * frame_width - 8. * (fig_dpi / 75.) * fontsize
max_height = fig_height * frame_height - 4. * (fig_dpi / 75.) * fontsize
# the hypothetical width and height in inches
# for a given aspect ratio
hypoWidth = maxHeight / ratio
hypoHeight = maxWidth * ratio
hypo_width = max_height / ratio
hypo_height = max_width * ratio
# if the hypothetical width is larger that the
# maximum allowed width (in inches) then chose
# the hypothetical Height
if (hypoWidth > maxWidth):
height = hypoHeight / figHeight # height in percent
width = maxWidth / figWidth # width in percent
posX = framePosX + 4. * (figDpi / 75.) * fontsize / figWidth # posX
posY = framePosY + 3. * (figDpi / 75.) * fontsize / figHeight # posY
if (hypo_width > max_width):
height = hypo_height / fig_height # height in percent
width = max_width / fig_width # width in percent
pos_x = frame_pos_x + 4. * (fig_dpi / 75.) \
* fontsize / fig_width # posX
pos_y = frame_pos_y + 3. * (fig_dpi / 75.) \
* fontsize / fig_height # posY
else:
height = maxHeight / figHeight
width = hypoWidth / figWidth
posX = framePosX + (frameWidth - width) / 2.
posY = framePosY + 3. * (figDpi / 75.) * fontsize / figHeight
rect = [posX, posY, width, height]
height = max_height / fig_height
width = hypo_width / fig_width
pos_x = frame_pos_x + (frame_width - width) / 2.
pos_y = frame_pos_y + 3. * (fig_dpi / 75.) * fontsize / fig_height
rect = [pos_x, pos_y, width, height]
return(rect)
# Class MyAxes Overwriting Matplotlib.figure.Axes
class MyAxes(Axes):
# CONSTRUCTOR --------------------------------------------------------
def __init__(self, fig, frame=_D_FRAME, *args, **kwargs):
self.fig = fig
self.declareKeywords()
rect = self.computeRect(frame, *args, **kwargs)
# clean kwargs
kwargs.pop('ratio', None)
kwargs.pop('forceRatioOnWidth', None)
kwargs.pop('forceRatioOnHeight', None)
kwargs.pop('fitInFrame', None)
# parent constructor
Axes.__init__(self, fig, rect, **kwargs)
# set a default name. Should be individualized by instance
self.name = 'default'
# COMPUTE RECT -------------------------------------------------------
def computeRect(self, frameRect, *args, **kwargs):
def compute_rect(self, frame_rect, *args, **kwargs):
# Get the optional keyword
ratio = kwargs.pop('ratio', None)
forceRatioOnWidth = kwargs.pop('forceRatioOnWidth', None)
forceRatioOnHeight = kwargs.pop('forceRatioOnHeight', None)
fitInFrame = kwargs.pop('fitInFrame', None)
force_ratio_on_width = kwargs.pop('force_ratio_on_width', None)
force_ratio_on_height = kwargs.pop('force_ratio_on_height', None)
fit_in_frame = kwargs.pop('fit_in_frame', None)
# get the frame allowed
framePosX, framePosY, frameWidth, frameHeight = frameRect
frame_pos_x, frame_pos_y, frame_width, frame_height = frame_rect
# get the size of the figure
figWidth = self.fig.get_figwidth()
figHeight = self.fig.get_figheight()
fig_width = self.fig.get_figwidth()
fig_height = self.fig.get_figheight()
if ratio is not None:
if(forceRatioOnWidth):
frameWidth = ratio * figWidth / (frameHeight * figHeight)
elif(forceRatioOnHeight):
frameHeight = ratio * (frameWidth * figWidth) / figHeight
if(force_ratio_on_width):
frame_width = ratio * fig_width / (frame_height * fig_height)
elif(force_ratio_on_height):
frame_height = ratio * (frame_width * fig_width) / fig_height
else:
frameHeight = ratio * (frameWidth * figWidth) / figHeight
rect = [framePosX, framePosY, frameWidth, frameHeight]
if (fitInFrame):
frame_height = ratio * (frame_width * fig_width) / fig_height
rect = [frame_pos_x, frame_pos_y, frame_width, frame_height]
if (fit_in_frame):
if ratio is None:
ratio = figHeight/figWidth
rect = computeFitRect(self.fig, ratio, rect)
ratio = fig_height / fig_width
rect = compute_fit_rect(self.fig, ratio, rect)
return(rect)
# DECLARE KEYWORDS -------------------------------------------------
def declareKeywords(self):
def declare_keywords(self):
self.keywords = {}
# PLOTTING ---------------------------------------------------------
def plotting(self):
raise(NotImplementedError, 'You should have overwrite the plotting function.')
raise(NotImplementedError, 'You should have overwrite the'
' plotting function.')
return(False)
# UNPACKING --------------------------------------------------------
def unpackFormattedData(self, packedData):
'''Get a string return it evaluation. can be overwritten by user.'''
return(eval(packedData))
def unpack_formatted_data(self, packed_data):
'''Get a string return it evaluation.
can be overwritten by user.'''
return(eval(packed_data))
# PACKING ----------------------------------------------------------
def packFormattedData(self, formattedData):
'''Get an object return its representation. can be overwritten by user.'''
return(str(formattedData))
def pack_formatted_data(self, formatted_data):
'''Get an object return its representation.
can be overwritten by user.'''
return(str(formatted_data))
# FORMATTING -------------------------------------------------------
def formatRawData(self, rawdata):
raise(NotImplementedError, 'You should have overwrite the formatRawData function.')
def format_raw_data(self, rawdata):
raise(NotImplementedError, 'You should have overwrite the '
'formatRawData function.')
return(False)
# TESTING THE RAWDATA ----------------------------------------------
def testRawData(self, rawdata):
def test_raw_data(self, rawdata):
return(True)
# UPDATE -----------------------------------------------------------
def update(self, *args, **kwargs):
# Because matplotlib.axes.update expect kwargs and not **kwargs ... (stupid!! no, this is just WRONG!!)
# Because matplotlib.axes.update expect kwargs and not **kwargs
# ... (stupid!! no, this is just WRONG!!)
if args: # catch matplotlib kwargs
# kwargs = args[0]
kwargs.update(args[0])
# kw_for_axes = {key: value for (key, value) in args[0].items() if key not in self.keywords} # Not compatible with python2.6
kw_for_axes = {}
for (key, value) in kwargs.items():
if key not in self.keywords:
kw_for_axes.update({key: value})
Axes.update(self, kw_for_axes) # update matplotlib.Axes
# myplotlib update
# self.keywords.update({key: value for (key, value) in kwargs.items() if key in self.keywords}) # Not compatible with python2.6
for (key, value) in kwargs.items():
if key in self.keywords:
self.keywords.update({key: value})
......@@ -50,74 +50,73 @@ from . import rcParams
# Class MyAxes Overwriting Matplotlib.figure.Axes
class MyAxes_client(Axes):
class MyAxesClient(Axes):
# CONSTRUCTOR --------------------------------------------------------
def __init__(self, fig, ratio, frameRect, *args, **kwargs):
def __init__(self, fig, ratio, frame_rect, *args, **kwargs):
self.fig = fig
self.declareKeywords()
rect = self.computeRect(ratio, frameRect, *args, **kwargs)
kwargs.pop('forceRatioOnWidth', None)
kwargs.pop('forceRatioOnHeight', None)
self.declare_keywords()
rect = self.compute_rect(ratio, frame_rect, *args, **kwargs)
kwargs.pop('force_ratioOn_width', None)
kwargs.pop('force_ratioOn_height', None)
# parent constructor
Axes.__init__(self, fig, rect, **kwargs)
# set a default name. Should be individualized by instance
self.name = 'default'
# COMPUTE RECT -------------------------------------------------------
def computeRect(self, ratio, frameRect, *args, **kwargs):
def compute_rect(self, ratio, frame_rect, *args, **kwargs):
# Get the optional keyword
forceRatioOnWidth = kwargs.pop('forceRatioOnWidth', None)
forceRatioOnHeight = kwargs.pop('forceRatioOnHeight', None)
force_ratio_on_width = kwargs.pop('force_ratio_on_width', None)
force_ratio_on_height = kwargs.pop('force_ratio_on_height', None)
# get the frame allowed
framePosX, framePosY, frameWidth, frameHeight = frameRect
frame_pos_x, frame_pos_y, frame_width, frame_height = frame_rect
# get the size of the figure
figWidth = self.fig.get_figwidth()
figHeight = self.fig.get_figheight()
if(forceRatioOnWidth):
frameWidth = ratio * figWidth / (frameHeight * figHeight)
elif(forceRatioOnHeight):
frameHeight = ratio * (frameWidth * figWidth) / figHeight
rect = [framePosX, framePosY, frameWidth, frameHeight]
fig_width = self.fig.get_figwidth()
fig_height = self.fig.get_figheight()
if(force_ratio_on_width):
frame_width = ratio * fig_width / (frame_height * fig_height)
elif(force_ratio_on_height):
frame_height = ratio * (frame_width * fig_width) / fig_height
rect = [frame_pos_x, frame_pos_y, frame_width, frame_height]
return(rect)
# DECLARE KEYWORDS -------------------------------------------------
def declareKeywords(self):
def declare_keywords(self):
self.keywords = {}
# PLOTTING -----------------------------------------------------------
def plotting(self):
return(True)
# UPDATE -------------------------------------------------------------
def update(self, *args, **kwargs):
# Because matplotlib.axes.update expect kwargs and not **kwargs ... (stupid!!)
# Because matplotlib.axes.update expect kwargs and not **kwargs
if args: # catch matplotlib kwargs
kwargs = args[0]
# kw_for_axes = {key: value for (key, value) in args[0].items() if key not in self.keywords} # Not compatible with python2.6
kw_for_axes = {}
for (key, value) in args[0].items():
if key not in self.keywords:
kw_for_axes.update({key: value})
Axes.update(self, kw_for_axes) # update matplotlib.Axes
# myplotlib update
# self.keywords.update({key: value for (key, value) in kwargs.items() if key in self.keywords}) # Not compatible with python2.6
for (key, value) in kwargs.items():
if key in self.keywords:
self.keywords.update({key: value})
......@@ -47,35 +47,35 @@ from . import SEVR, DBUG
# Class MyAxes Overwriting Matplotlib.figure.Axes
class MyAxes_server(object):
class MyAxesServer(object):
# CONSTRUCTOR --------------------------------------------------------
def __init__(self, fig, ratio, frameRect, *args, **kwargs):
def __init__(self, fig, ratio, frame_rect, *args, **kwargs):
self.fig = fig
self.declareKeywords()
self.declare_keywords()
# set a default name. Should be individualized by instance
self.name = 'default'
# DECLARE KEYWORDS -------------------------------------------------
def declareKeywords(self):
def declare_keywords(self):
self.keywords = {}
# FORMATTING ---------------------------------------------------------
def formatRawData(self, rawdata):
def format_raw_data(self, rawdata):
return(True)
# TESTING THE RAWDATA ------------------------------------------------
def testRawData(self, rawdata):
def test_raw_data(self, rawdata):
return(True)
# UPDATE -------------------------------------------------------------
def update(self, *args, **kwargs):
# myplotlib update
# self.keywords.update({key: value for (key, value) in kwargs.items() if key in self.keywords}) # Not compatible with python2.6
for (key, value) in kwargs.items():
if key in self.keywords:
self.keywords.update({key: value})
......@@ -30,9 +30,10 @@
_D_NAME = 'default'
_D_DATA = None
class MyData():
def __init__(self, name=_D_NAME, data=_D_DATA):
self.name = name
self.data = data
class Signal (object):
def __init__(self,content) :
def __init__(self, content):
# every signal should have a content attribute
self.content = content
self.content = content
class Query(Signal) :
READDATA = 1
NEWSYNCFIGURE = 2
UPDATESYNCFIGURE = 3
class Query(Signal):
READDATA = 1
NEWSYNCFIGURE = 2
UPDATESYNCFIGURE = 3
SYNCFIGFORMATRAWDATA = 4
DELETESYNCFIGURE = 5
LISTDATA = 6
GETDATA = 7
LISTFIG = 8
NBR_OF_QUERY_TYPES = 8
def __init__(self,queryType, content) :
if queryType in range(1,Query.NBR_OF_QUERY_TYPES+1) :
self.queryType = queryType
if queryType == Query.READDATA :
if type(content) == dict :
DELETESYNCFIGURE = 5
LISTDATA = 6
GETDATA = 7
LISTFIG = 8
NBR_OF_QUERY_TYPES = 8
def __init__(self, query_type, content):