Commit 776c62eb authored by Yori 'AGy' Fournier's avatar Yori 'AGy' Fournier
Browse files

add the axes-level pack and unpack function in the MyAxes class

add the fig-level pack in server.py
add the fig-level unpack in MyFig_client.py
parent c5029a34
......@@ -96,19 +96,29 @@ class MyAxes(Axes):
def declareKeywords(self):
self.keywords = {}
# PLOTTING -----------------------------------------------------------
# PLOTTING ---------------------------------------------------------
def plotting(self):
return(True)
# FORMATTING ---------------------------------------------------------
# UNPACKING --------------------------------------------------------
def unpackFormattedData(self, packedData):
'''Get a string return it evaluation. can be overwritten by user.'''
return(eval(packedData))
# PACKING ----------------------------------------------------------
def packFormattedData(self, formattedData):
'''Get an object return its representation. can be overwritten by user.'''
return(str(formattedData))
# FORMATTING -------------------------------------------------------
def formatRawData(self, rawdata):
return(True)
# TESTING THE RAWDATA ------------------------------------------------
# TESTING THE RAWDATA ----------------------------------------------
def testRawData(self, rawdata):
return(True)
# UPDATE -------------------------------------------------------------
# UPDATE -----------------------------------------------------------
def update(self, *args, **kwargs):
# Because matplotlib.axes.update expect kwargs and not **kwargs ... (stupid!!)
......
......@@ -216,16 +216,17 @@ class MyFig_client(Figure):
# except:
# print(SEVR+'The server-side figure could not format the data...')
# return(False)
for ax, data in zip(self.get_axes(), datas):
ax.data = data
# each data is a string that can be unpacked by axes itself
ax.data = ax.unpackFormattedData(data)
else:
print(SEVR+'The figure is not properly synchronized.')
return(False)
return(True)
# PLOT -------------------------------------------------------------
def plot(self):
......
......@@ -54,6 +54,20 @@ class Server():
else:
pass
# PACKING ----------------------------------------------------------
def packFormattedData(self, formattedData):
'''formattedData is a tuple of as many strings as
the figure has Axes. the packedData is the
string representation of it to be later evaluated.'''
packedData = '('
for string in formattedData:
packedData = packedData + "\"" + str(string) + "\"" + ', '
packedData = packedData + ")"
return(packedData)
def treatAnswer(self, signal):
answer = None
......@@ -151,9 +165,14 @@ class Server():
datas = []
for ax in fig.get_axes():
datas.append(ax.data)
answer = ('syncFigFormatRawData', datas, '')
# ax.data is any user defined object
# ax.packFormattedData returns it's string representation
# to be unpacked by ax.unpackFormattedData
datas.append(ax.packFormattedData(ax.data))
packedData = self.packFormattedData(datas)
answer = ('syncFigFormatRawData', packedData, '')
else:
print(WARN+"I don't know ths signal, sorry")
......
......@@ -58,24 +58,61 @@ class ServerInterface(object):
return(syncFigure)
def syncFigFormatRawData(self, syncID):
'''the returned datas should be a tuple of strings'''
content = "['"+str(syncID)+"']"
signal = "("+"'syncFigFormatRawData'"+", "+str(content)+")"
sock = self.sendSignal(signal)
answer = self.waitForAnswer(sock)
header, content, errmsg = eval(answer)
# header, content, errmsg = eval(answer)
header, content, errmsg = unpackFormattedData(answer)
if content is not None:
data = content
datas = content
else:
print(WARN + 'The server could not format the rawdata.')
print(errmsg)
data = None
return(data)
datas = None
return(datas)
# UNPACKING --------------------------------------------------------
def unpackFormattedData(self, packedData):
'''The packedData should be the string representation
of a tuple of 3 strings.
"(signalID, content, errmsg)"
It's evaluation returns a tuple of 3 strings.
content is a tuple of as many strings as Axes.
It's evaluation returns a tuple of strings.'''
# the tuple of three strings
try:
header, content, errmsg = eval(packedData)
except:
print(WARN+'The data sent by the server could not be evaluated')
return((None, None, None))
# The tuple of as many strings as axes
try:
evaluatedContent = eval(content)
except:
print(WARN+'The content sent by the server could not be evaluated')
return((header, None, errmsg))
# check is format is correct
if not isinstance(content, tuple):
print(WARN+'The content sent by the server should be a tuple of strings.')
return((header, None, errmsg))
# create the final tuple
partlyUnpackedData = (header, evaluatedContent, errmsg)
return(partlyUnpackedData)
def sendSignal(self, signal):
sock = socket(AF_INET, SOCK_STREAM)
sock.connect((self.ip, self.port))
......
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