Commit 548a2b5e authored by Philipp Gast's avatar Philipp Gast
Browse files

merge of yoris work

Merge branch '88-cleanning-pep8-compilance' of gitlab:yfournier/myplotlib into 88-cleanning-pep8-compilance

Conflicts:
	mpl_fig_client.py
	test/network/tests/test_com.py
parents 77baa8cd 1fc7e78e
Pipeline #501 passed with stage
in 6 minutes and 7 seconds
......@@ -23,7 +23,7 @@ myplotlib_test_mytool:
script:
- git name-rev --name-only HEAD
- ls -l
- cd mytool
- cd mpl_toolbox/
- cp ../.configs/tests/config-local.py ../config.py
- python -m tests
- python -m tutorials
......
......@@ -44,7 +44,6 @@ from mpl_unpickler import MplUnpickler
np.set_printoptions(threshold='nan')
# matplotlib import for client/local -----------------------------------
if D_HIERARCHY in ('CLIENT', 'client', 'LOCAL', 'local'):
......@@ -114,29 +113,27 @@ if D_HIERARCHY in ('CLIENT', 'client', 'LOCAL', 'local'):
if D_HIERARCHY in ('CLIENT', 'client'):
# MyAxes: Overlay on matplotlib.Axes class
from .myAxes_client import MyAxesClient as MyAxes
# MplAxes: Overlay on matplotlib.Axes class
from .mpl_axes_client import MplAxesClient as MplAxes
# MyFig: Overlay on matplotlib.Figure class
from .myFig_client import MyFigClient as MyFig
from .mpl_grid import Grid, VerticalGrid, HorizontalGrid
# MplFig: Overlay on matplotlib.Figure class
from .mpl_fig_client import MplFigClient as MplFig
from .progressbar import ProgressBar
from .mplClient2 import MplClient2
from .mpl_client import MplClient
elif(D_HIERARCHY in ('SERVER', 'server')):
# MyAxes: Overlay on matplotlib.Axes class
from .myAxes_server import MyAxesServer as MyAxes
# MyFig: Overlay on matplotlib.Figure class
from .myFig_server import MyFigServer as MyFig
# MplAxes: Overlay on matplotlib.Axes class
from .mpl_axes_server import MplAxesServer as MplAxes
# from .test import FigTestServer
# from .test import FigTest
# for testing purpose
# from .test import readStupidData, readStupidData2
from .mpl_grid import Grid, VerticalGrid, HorizontalGrid
# MplFig: Overlay on matplotlib.Figure class
from .mpl_fig_server import MplFigServer as MplFig
SERVER_IOFUNCTIONS = {
# 'readStupidData': readStupidData,
......@@ -146,14 +143,14 @@ elif(D_HIERARCHY in ('SERVER', 'server')):
#'FigTest': FigTest
}
from .mplServer2 import MplServer2, MplHandler
from .mpl_server import MplServer, MplHandler
elif D_HIERARCHY in ('LOCAL', 'local'):
# MyAxes: Overlay on matplotlib.Axes class
# MplAxes: Overlay on matplotlib.Axes class
from .mpl_axes import MplAxes
# MyFig: Overlay on matplotlib.Figure class
# MplFig: Overlay on matplotlib.Figure class
from .mpl_grid import Grid, VerticalGrid, HorizontalGrid
from .mpl_fig import MplFig
from .empty_fig import EmptyFig
......@@ -183,23 +180,3 @@ if D_HIERARCHY in ('CLIENT', 'client', 'LOCAL', 'local'):
else:
print(SEVR + """The backend you choosed is not
supported interactive mode not available""")
# mpl_tool_box.*: interface functions to use myplotlib interactively
# from .mpl_tool_box import print2file # need to make tools for server ?? or just put them in client/local
#from .mpl_tool_box import FigOneAxes
# if D_HIERARCHY in ('CLIENT', 'client', 'LOCAL', 'local'):
# from .mpl_tool_box import print2file # need to make tools for server ?? or just put them in client/local
# from .mpl_tool_box import FigOneAxes
# from .mpl_tool_box import window_exists, getCurrentWindowIDs
# from .mpl_tool_box import print2file, print2screen, printListCurrentWindows
# from .mpl_tool_box import getWindow, getFigOnWindow, drawFigOnWindow, giveDataToWindow
# from .mpl_tool_box import closeWindow, closeAllWindows
# TESTS ----------------------------------------------------------------
# from .test import myTest
# from .test import testList
# from .test import FigTest
......@@ -50,7 +50,7 @@ from . import rcParams
# Class MyAxes Overwriting Matplotlib.figure.Axes
class MyAxesClient(Axes):
class MplAxesClient(Axes):
# CONSTRUCTOR --------------------------------------------------------
def __init__(self, fig, ratio, frame_rect, *args, **kwargs):
......
......@@ -47,7 +47,7 @@ from . import SEVR, DBUG
# Class MyAxes Overwriting Matplotlib.figure.Axes
class MyAxesServer(object):
class MplAxesServer(object):
# CONSTRUCTOR --------------------------------------------------------
def __init__(self, fig, ratio, frame_rect, *args, **kwargs):
......
......@@ -3,21 +3,20 @@ import pickle
from . import Query, Status, Answer, Signal
from . import DBUG, WARN, SPCE, SEVR, INFO
from . import MplUnpickler
# from . import MyData
from . import D_DEBUG
debug = D_DEBUG
class MplClient2():
class MplClient():
def __init__(self):
self.host, self.port = (None, None)
# just a list of names
self.currentRemoteData = []
self.current_remotedata = []
def connect(self, con):
......@@ -56,12 +55,14 @@ class MplClient2():
def send(self, sig):
""" Sending a Type derived from Signal through the socket
after 'pickling' it"""
print('prepare sending')
wf = self.sock.makefile(mode='wb')
if debug:
print('sending ',
type(sig),
' with content \"',
sig.content, '\"')
print('makefile done')
#~ if debug:
print('Client sending ',
type(sig),
' with content \"',
sig.content, '\"')
try:
pickle.dump(sig, wf)
except Exception:
......@@ -175,7 +176,7 @@ class MplClient2():
if not status:
print('something went wrong with the '
'sending of readData request...')
answer = self.waitForSignal()
answer = self.wait_for_signal()
self.disconnect()
......@@ -204,15 +205,15 @@ class MplClient2():
if not status:
print('something went wrong '
'with the sending of newSincFigure request...')
'with the sending of new_sync_figure request...')
answer = self.wait_for_signal()
self.disconnect()
# try to create a figure of the same class on the client side
if isinstance(answer, Answer):
print('''trying to create a figure of the same
class on the client side''')
print('trying to create a figure of the same '
'class on the client side')
fig = figname(dataname, *args, **kwargs)
# Link the temporary Sync Figure
fig.sync_id = answer.content
......@@ -221,6 +222,7 @@ class MplClient2():
elif isinstance(answer, Status):
self.test_status_sig(query, answer)
print('>>>>>>>>>>>>>>>>>>>>>>>>>> response is not an Answer!!!')
return None
else:
print('an unknown error occured')
......@@ -260,7 +262,7 @@ class MplClient2():
query = Query(Query.DELETESYNCFIGURE, sync_id)
status = self.send(query)
status_sig = self.waitForSignal()
status_sig = self.wait_for_signal()
self.disconnect()
......@@ -287,7 +289,7 @@ class MplClient2():
if not status:
print(INFO + 'Sent Signal')
formated_data = self.waitForSignal()
formated_data = self.wait_for_signal()
self.disconnect()
......@@ -298,7 +300,7 @@ class MplClient2():
if formated_data.value:
print('This should not happen')
else:
print('instead if answer a error was received')
print('instead of answer a error was received')
datas = (None,)
else:
# set the figure data to answerSig.value
......
......@@ -78,7 +78,7 @@ from . import HorizontalGrid
# Class MyFig Overwriting Matplotlib.figure.Figure
class MyFigClient(Figure):
class MplFigClient(Figure):
# Set the size of the Figure in inch
# (private variable can not be updated)
......@@ -116,7 +116,7 @@ class MyFigClient(Figure):
def de_sync_fig(self):
if self.client is not None:
if self.client.deleteSyncFigure(self.sync_id):
if self.client.delete_sync_figure(self.sync_id):
print('The figure was successfully deleted on the server Side')
self.sync_id = -1
else:
......@@ -142,8 +142,8 @@ class MyFigClient(Figure):
# find aliases for this specific axes
masks = dict()
for alias in self.aliases.keys():
axes4alias, keyword = self.aliases[alias]
if axes4alias == ax:
axes_for_alias, keyword = self.aliases[alias]
if axes_for_alias == ax:
masks.update({keyword: alias})
# collect all keywords of the axes and replace the keys with the
......@@ -175,12 +175,12 @@ class MyFigClient(Figure):
state = self.get_state()
# call the client to create a new figure on the server side
newFig = self.client.new_sync_figure(
new_fig = self.client.new_sync_figure(
self.__class__, self.remote_rawdata, **state)
# since the state matches the current instance. only the new sync_id
# is kept.
self.sync_id = newFig.sync_id
self.sync_id = new_fig.sync_id
else:
print(
'The client is not connected to a server yet. '
......@@ -322,7 +322,7 @@ class MyFigClient(Figure):
if (self.client is not None) and (self.sync_id != -1):
if (True):
datas = self.client.sync_fig_format_raw_data(self.sync_id)
datas = self.client.sync_fig_format_rawdata(self.sync_id)
for ax, data in zip(self.get_axes(), datas):
ax.data = data
......
......@@ -72,11 +72,10 @@ 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 MplData
#from . import MyAxes_server
# Class MyFig Overwriting Matplotlib.figure.Figure
class MyFigServer(object):
class MplFigServer(object):
# Set the size of the Figure in inch
# (private variable can not be updated)
......@@ -93,7 +92,7 @@ class MyFigServer(object):
# initialise the attribute default values and remove them from kwargs
# need to be hard coded for interactive mode
self.fignum = kwargs.pop('fignum', MyFigServer.G_FIGNUM)
self.fignum = kwargs.pop('fignum', MplFigServer.G_FIGNUM)
self.reformat = kwargs.pop('reformat', D_REFORMAT)
self.debug = kwargs.pop('debug', D_DEBUG)
self.formatted = kwargs.pop('formatted', D_FORMATTED)
......@@ -107,7 +106,7 @@ class MyFigServer(object):
self.set_rawdata(rawdata)
# count the global counter up by one
MyFigServer.G_FIGNUM += 1
MplFigServer.G_FIGNUM += 1
# INITIALIZE -------------------------------------------------------
def _initialize(self, *args, **kwargs):
......
......@@ -7,7 +7,7 @@ from . import Signal, Status, Query, Answer
from . import SERVER_IOFUNCTIONS
from . import SERVER_FIGURES
from . import MyFig
from . import MplFig
from . import DBUG, WARN, SPCE, SEVR, INFO
from . import MplUnpickler
......@@ -97,7 +97,7 @@ class MplHandler(SocketServer.StreamRequestHandler):
+ str(e.message) + str(e.args))
# add the figure to the global index
self.server._figures[fig.getFigID()] = fig
self.server._figures[fig.get_fig_id()] = fig
if fig.get_fig_id() in self.server._figures :
return Answer(fig.get_fig_id())
......@@ -106,7 +106,7 @@ class MplHandler(SocketServer.StreamRequestHandler):
This function forwards the request to the corresponding figure"""
fig_id, kwargs = content
fig = self.get_fig_by_id(fig_id)
fig = self.server.get_fig_by_id(fig_id)
# if an error occured forward the signal
if isinstance(fig, Signal):
......@@ -121,7 +121,7 @@ class MplHandler(SocketServer.StreamRequestHandler):
return Status(False, 'Kewords of figure ID: '
+ fig_id + ' could not be updated')
def treat_sync_fig_format_raw_data(self, fig_id):
def treat_sync_fig_format_rawdata(self, fig_id):
# Identify the figure
fig = self.server.get_fig_by_id(fig_id)
......@@ -132,15 +132,15 @@ class MplHandler(SocketServer.StreamRequestHandler):
# Format the rawdata
try:
fig.format_raw_data()
fig.format_rawdata()
except Exception as e:
if debug:
print(WARN + "I couldn't format the rawdata.")
print(SPCE + "SERVER: Exception details where:",
e.message,
e.args)
return Status(False, "I couldn't format the rawdata."
" Exception details where:", e.message, e.args)
return Status(False, "I couldn't format the rawdata."\
" Exception details where:" + str(e.message) + str(e.args))
# compose the formated data
datas = tuple(ax.data for ax in fig.get_axes())
......@@ -176,7 +176,7 @@ class MplHandler(SocketServer.StreamRequestHandler):
def handle(self):
print('HANDLING...')
print('Server handling request...')
reply = None
......@@ -187,6 +187,7 @@ class MplHandler(SocketServer.StreamRequestHandler):
try:
unpickler = MplUnpickler(self.rfile)
request = unpickler.load()
print('Server message loaded...')
if isinstance(request, Query):
if request.query_type == request.READDATA:
......@@ -196,7 +197,7 @@ class MplHandler(SocketServer.StreamRequestHandler):
elif request.query_type == request.UPDATESYNCFIGURE:
reply = self.treat_update_sync_figure(request.content)
elif request.query_type == request.SYNCFIGFORMATRAWDATA:
reply = self.treat_sync_fig_format_rawData(request.content)
reply = self.treat_sync_fig_format_rawdata(request.content)
elif request.query_type == request.DELETESYNCFIGURE:
reply = self.treat_delete_sync_figure(request.content)
elif request.query_type == request.LISTDATA:
......@@ -217,14 +218,13 @@ class MplHandler(SocketServer.StreamRequestHandler):
elif isinstance(request, Answer):
# needed for server???
pass
elif isinstance(request, request):
self.serv_print('received unknown requestnal')
reply = Status(False, "received unknown requestnal")
elif isinstance(request, Signal):
self.serv_print('received unknown Signal')
reply = Status(False, "received unknown Signal")
else:
self.serv_print('what is happening here???'
' received Object of type:')
self.serv_print(str(request))
reply = Status(False, "received something totally diffenent")
self.serv_print('Server received unknown object:'
' of type:'+str(type(request)))
reply = Status(False, "Server received unknown object")
if isinstance(reply, Signal):
if debug:
......@@ -232,17 +232,21 @@ class MplHandler(SocketServer.StreamRequestHandler):
except EOFError:
print("could not unpickle, noting in the file")
except Exeption as e:
raise e
finally:
if reply:
pickle.dump(reply, self.wfile)
#~ else:
#~ pickle.dump(Status(False,None), self.wfile)
# these two lines are not needed
self.wfile.close()
self.rfile.close()
class MplServer2(SocketServer.TCPServer):
class MplServer(SocketServer.TCPServer):
allow_reuse_address = True
......@@ -296,7 +300,7 @@ class MplServer2(SocketServer.TCPServer):
print(WARN + "The figure ID: " + fig_id + " does not exist.")
return Status(False, "The figure ID: "
+ fig_id + " does not exist.")
elif isinstance(fig, MyFig):
elif isinstance(fig, MplFig):
if debug:
print('Figure ', fig_id, ' found in database')
return fig
# usage
#
# <in class MySuperFig>
# def addAxes(self):
#
# self.layout = MyGrid()
# self.layout.addAxes(MySuperAxes(self, 6./8, [0.15, 0.15, 0.7, 0.7]), 'superAxes1'))
#
# This is creating an object MyGrid which overwrite the computeRect function
# from MySuperAxes depending on the parameters given to MyGrid.
#
# The example of a equidistant Grid
#
# self.layout = MySuperGrid()
# self.layout.addAxes(MySuperAxes(self, 6./8, [0.15, 0.15, 0.7, 0.7]), 'superAxes1', (0, 0)))
# self.layout.addAxes(MySuperAxes(self, 6./8, [0.15, 0.15, 0.7, 0.7]), 'superAxes2', (0, 1)))
#
# Depending on the last argument the gridOffsetY is going to be computed and the
# computeRect function altered for both Axes. The ratio and frame are still the one within the gridCell.
#
# For the vertical grid I realisez that We may need to fit the layout at the
# end of fig.addAxes when all axes are present.
# Another point is that layout can not be dynamic, because the frame of an Axes
# is static (changing the frame requires to destroy the Axes, because of the canvas and the dpi)
# Therefore we should not allow the user to dynamically use grid.
#
# Maybe at the end of fig._initialize we may call self.grid.fitLayout()
# This suggests that all figure have a grid.
# This suggests that grids are not optional but a must and therefore
# any combinaison are required and that grid containing grid should be
# possible.
class MyGrid():
def __init__(self, fig):
self.fig = fig
def addAxes(self, ax, name, *args, **kwargs):
ax.computeRect = self.generateComputeRect(args, kwargs)
self.fig.add_axes(self, ax, name)
def generateComputeRect(self, *args, **kwargs):
gridOffsetX = 0
gridOffsetY = 0
gridWidth = self.fig.get_figwidth()
gridHeight = self.fig.get_figheight()
def computeRect(self, ratio, frameRect, *args, **kwargs):
# Get the optional keyword
forceRatioOnWidth = kwargs.pop('forceRatioOnWidth', None)
forceRatioOnHeight = kwargs.pop('forceRatioOnHeight', None)
# get the frame allowed
framePosX, framePosY, frameWidth, frameHeight = frameRect
if(forceRatioOnWidth):
frameWidth = ratio * gridWidth / (frameHeight * gridHeight)
elif(forceRatioOnHeight):
frameHeight = ratio * (frameWidth * gridWidth) / gridHeight
rect = [framePosX + gridOffsetX,
framePosY + gridOffsetY,
frameWidth,
frameHeight]
return(rect)
return(computeRect)
class MyVGrid(MyGrid):
def __init__(self, fig):
self.lastOffsetY = 0
MyGrid.__init__(self, fig)
def generateComputeRect(self, *args, **kwargs):
self.axesCount = self.axesCount + 1
gridOffsetX = 0
gridOffsetY =
gridWidth = self.fig.get_figwidth()
gridHeight = self.fig.get_figheight()
def computeRect(self, ratio, frameRect, *args, **kwargs):
# Get the optional keyword
forceRatioOnWidth = kwargs.pop('forceRatioOnWidth', None)
forceRatioOnHeight = kwargs.pop('forceRatioOnHeight', None)
# get the frame allowed
framePosX, framePosY, frameWidth, frameHeight = frameRect
if(forceRatioOnWidth):
frameWidth = ratio * gridWidth / (frameHeight * gridHeight)
elif(forceRatioOnHeight):
frameHeight = ratio * (frameWidth * gridWidth) / gridHeight
rect = [framePosX + gridOffsetX,
framePosY + gridOffsetY,
frameWidth,
frameHeight]
return(rect)
return(computeRect)
......@@ -43,7 +43,7 @@
#
# IMPORT ---------------------------------------------------------------
from myplotlib import MyAxes
from myplotlib import MplAxes
D_XRANGE = None
D_YRANGE = None
......@@ -52,13 +52,13 @@ D_LOGX = False
# Class MyAxes Overwriting Matplotlib.figure.Axes
class AxTest(MyAxes):
class AxTest(MplAxes):
# DECLARE KEYWORDS -------------------------------------------------
def declare_keywords(self):
self.keywords = {'xRange': D_XRANGE,
'yRange': D_YRANGE}
self.keywords = {'x_range': D_XRANGE,
'y_range': D_YRANGE}
return(True)
......@@ -83,8 +83,8 @@ class AxTest(MyAxes):
def plotting(self):
xRange = self.keywords.get('xRange')
yRange = self.keywords.get('yRange')
x_range = self.keywords.get('x_range')
y_range = self.keywords.get('y_range')
try:
self.plot(self.data['xdata'], self.data['ydata'])
......@@ -92,7 +92,7 @@ class AxTest(MyAxes):
print(SEVR + 'The formatting of the data was apparently wrong. --> EXIT')
return(False)
if (xRange): self.set_xlim(xRange)
if (yRange): self.set_ylim(yRange)
if (x_range): self.set_xlim(x_range)
if (y_range): self.set_ylim(y_range)
return(True)
# IMPORT ---------------------------------------------------------------
from myplotlib import MyFig
from axTest import AxTest
from myplotlib import MplFig
from axes_tests import AxTest
class FigTest(MyFig):
class FigTest(MplFig):
FIGSIZE = (8., 6.)
......@@ -13,7 +13,7 @@ class FigTest(MyFig):
self.add_axes(AxTest(self, ratio, frame1), "p1")
class FigTest2(MyFig): # Fig with two Axes
class FigTest2(MplFig): # Fig with two Axes
# Set the size of the Figure in inch
# (private variable can not be updated)
......@@ -25,17 +25,17 @@ class FigTest2(MyFig): # Fig wi
frame1 = [0.1, 0.1, 0.4, 0.8] # part of the fig that is available
frame2 = [0.6, 0.1, 0.4, 0.8] # part of the fig that is available
self.add_axes(AxTest(self, ratio, frame1),"p1")
self.add_axes(AxTest(self, ratio, frame2),"p2")
self.add_axes(AxTest(self, ratio, frame1), "p1")
self.