Commit 87c8541d authored by Philipp Gast's avatar Philipp Gast
Browse files

updating a synced figure now works

parent c5fb8044
Pipeline #418 failed with stage
in 1 minute and 25 seconds
......@@ -131,30 +131,22 @@ class MplClient2():
fig.client = self
return fig
#~ def updateSyncFigure()
#~ '''
#~ Send a UPDATE_SYNC_FIGURE query to the server.
#~ wait for the status
#~ if status ok then sync.
#~ '''
#~ # create a signal with args
#~ query = Query(Query.UPDATE_SYNC_FIGURE)
#~ sendSignal(query)
#~ statusSig = waitForSignal()
#~
#~ if statusSig.value :
#~ # update Figure with args
#~ if updated
#~ # create a signal of type status (True)
#~ status = Status(True)
#~ else:
#~ # create a signal of type status (False)
#~ status = Status(False)
#~ sendSignal(status)
#~ else:
#~ # do not update the figure.
#~ print statusSig.error
#~
def updateSyncFigure(self,syncID,kwargs) :
''' Send a UPDATE_SYNC_FIGURE query to the server.
wait for the status
if status ok then sync.
'''
# create a signal with args
query = Query(Query.UPDATESYNCFIGURE,(syncID,kwargs))
self.send(query)
statusSig = self.waitForSignal()
if statusSig.value :
return True
else:
return False
def deleteSyncFigure(self,syncID):
'''
Send a DELETESYNCFIGURE query to the server.
......
......@@ -85,10 +85,8 @@ class MplHandler(SocketServer.StreamRequestHandler):
if FigID in G_FIGURES :
return Status(True,"SERVER: I created the requested Figure with following instructions"+str(FigClass.__name__)+str(datas)+'('+str(args)+', '+str(kwargs)+')')
def treatUpdateSyncFigure(self,content) :
pass
def treatSyncFigFormatRawData(self,figID):
def getFigByID(self,figID) :
""" Identify the figure by ID and return it. On error it will return a Status Signal"""
# Identify the figure
fig = G_FIGURES.get(figID,None)
......@@ -99,6 +97,33 @@ class MplHandler(SocketServer.StreamRequestHandler):
elif isinstance(fig,MyFig) :
if DEBUG :
print('Figure ',figID,' found in database')
return fig
def treatUpdateSyncFigure(self,content) :
""" If client request an update of the keywords of a figure. This function forwards the request to the corresponding figure"""
figID,kwargs = content
fig = self.getFigByID(figID)
# if an error occured forward the signal
if isinstance(fig,Signal) :
return fig
status = fig.update(**kwargs)
if status :
return Status(True,'Kewords of figure ID: '+figID+' successfully updated')
else :
return Status(False,'Kewords of figure ID: '+figID+' could not be updated')
def treatSyncFigFormatRawData(self,figID):
# Identify the figure
fig = self.getFigByID(figID)
# if an error occured forward the signal
if isinstance(fig,Signal) :
return fig
# Format the rawdata
try:
......
......@@ -83,6 +83,7 @@ class MyFig_client(Figure):
# (private variable can not be updated)
FIGSIZE = D_FIGSIZE
# CONSTRUCTOR --------------------------------------------------------
# CONSTRUCTOR --------------------------------------------------------
def __init__(self, rawdata, *args, **kwargs):
......@@ -109,7 +110,7 @@ class MyFig_client(Figure):
# initialise
self._initialize(*args, **kwargs)
def deSyncFig(self):
if self.client is not None :
if self.client.deleteSyncFigure(self.syncID) :
......@@ -135,44 +136,56 @@ class MyFig_client(Figure):
# UPDATE ----------------------------------------------------------
def update(self, **kwargs):
# check attributes in keywords
for keyword in kwargs.keys():
# if it is an attribute
if keyword in self._attributesToUpdateKeys:
# update value
setattr(self, keyword, kwargs[keyword])
# send the keywords to the server
if self.client is not None :
status = self.client.updateSyncFigure(self.syncID,kwargs)
# For each axes update the keywords
for ax in self.get_axes():
forax = {}
for keyword in kwargs.keys():
# ignore figure attributes
if keyword in self._attributesToUpdateKeys :
pass
# Check if a key of kwargs has an alias for this axes
elif keyword in self.aliases.keys():
alax, alkey = self.aliases[keyword]
# if the server reported no errors apply the keywords on client side also:
if status :
# If an alias is found then update axkwargs
if ax == alax:
forax.update(**{alkey: kwargs[keyword]})
# use keyword as it is for the axes
else :
forax.update(**{keyword : kwargs[keyword]})
# Then eventually all collected Keywords are updated in one go
if (forax) :
if self.debug:
print (DBUG+' fig.update ', ax, 'keywords: ', forax)
ax.update(**forax)
return(True)
# check attributes in keywords
for keyword in kwargs.keys():
# if it is an attribute
if keyword in self._attributesToUpdateKeys:
# update value
setattr(self, keyword, kwargs[keyword])
# For each axes update the keywords
for ax in self.get_axes():
forax = {}
for keyword in kwargs.keys():
# ignore figure attributes
if keyword in self._attributesToUpdateKeys :
pass
# Check if a key of kwargs has an alias for this axes
elif keyword in self.aliases.keys():
alax, alkey = self.aliases[keyword]
# If an alias is found then update axkwargs
if ax == alax:
forax.update(**{alkey: kwargs[keyword]})
# use keyword as it is for the axes
else :
forax.update(**{keyword : kwargs[keyword]})
# Then eventually all collected Keywords are updated in one go
if (forax) :
if self.debug:
print (DBUG+' fig.update ', ax, 'keywords: ', forax)
ax.update(**forax)
return(True)
else :
print('The server reported of an error in setting the keywords')
return(False)
else :
print('The figure is not yet connected to a client')
return(False)
# DECLARE ALIASES -------------------------------------------------
def declareAliases(self):
......
......@@ -81,10 +81,15 @@ class MyFig_server(object):
# Set the size of the Figure in inch
# (private variable can not be updated)
FIGSIZE = D_FIGSIZE
G_FIGNUM = 0 # This is to become global counter for myFig Instances to prevent ID collision
# CONSTRUCTOR --------------------------------------------------------
def __init__(self, rawdata, *args, **kwargs):
# count the global counter up by one
MyFig_server.G_FIGNUM += 1
# for the update function
self._attributesToUpdateKeys = ['fignum', 'reformat', 'debug', 'formatted', 'aliases']
......@@ -160,6 +165,10 @@ class MyFig_server(object):
return(True)
# GET FIG ID AS STRING --------------------------------------------
def getFigID(self) :
return str(self.fignum)
# DECLARE ALIASES -------------------------------------------------
def declareAliases(self):
pass
......
......@@ -29,4 +29,9 @@ fig = client.newSyncFigure(FigTestc, ('data1',))
win=mpl_client.MyWin(fig)
sleep(2)
# update test
fig.update(xRange=[-2, 2],yRange=[-2, 2])
win.refresh()
sleep(2)
fig.deSyncFig()
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