Commit 160d326e authored by Yori Fournier's avatar Yori Fournier
Browse files

Now the arguents given to the figure during creation are also taken into account on the clientside

needed to creat a private update function to update the keywords eventhough
the figure is not yet synchronized and the fig.client attribute is still None.
parent 556f8e6a
Pipeline #421 failed with stage
in 1 minute and 22 seconds
......@@ -108,7 +108,7 @@ class MplClient2():
"""
pass
def newSyncFigure(self, figname, dataname,*args,**kwargs) :
def newSyncFigure(self, figname, dataname, *args, **kwargs) :
'''
Send a query NEWSYNCFIGURE to the server
wait for the status.
......@@ -125,7 +125,7 @@ class MplClient2():
# 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')
fig = figname((MyData(),),*args,**kwargs)
fig = figname( MyData(), *args, **kwargs)
# Link the temporary Sync Figure
fig.syncID = answer.content
fig.client = self
......
......@@ -265,7 +265,7 @@ class MplServer2(SocketServer.TCPServer):
self.defineKnownFunctions(knownFunctions)
self.defineKnownFigures(knownFigures)
SocketServer.TCPServer.__init__(self, (ip, port), handler)
self.running = False
self.initialized = True
def run(self, as_daemon=True):
......@@ -275,8 +275,8 @@ class MplServer2(SocketServer.TCPServer):
self.running = True
def stop(self):
def stop(self): # not yet working
print('STOPING...')
self.server_thread.stop()
# self.server_thread.stop()
self.running = False
......@@ -131,60 +131,65 @@ class MyFig_client(Figure):
self.declareAliases()
# update the attributes and keywords
self.update(**kwargs)
# UPDATE ----------------------------------------------------------
def update(self, **kwargs):
# send the keywords to the server
if self.client is not None :
status = self.client.updateSyncFigure(self.syncID,kwargs)
# if the server reported no errors apply the keywords on client side also:
if status :
# check attributes in keywords
for keyword in kwargs.keys():
self._update(**kwargs)
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])
# 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():
# For each axes update the keywords
for ax in self.get_axes():
forax = {}
forax = {}
for keyword in kwargs.keys():
for keyword in kwargs.keys():
# ignore figure attributes
if keyword in self._attributesToUpdateKeys :
pass
# 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]
# 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]})
# 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]})
# 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)
# 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)
# UPDATE ----------------------------------------------------------
def update(self, **kwargs):
# send the keywords to the server
if self.client is not None :
status = self.client.updateSyncFigure(self.syncID,kwargs)
# if the server reported no errors apply the keywords on client side also:
if status :
self._update(**kwargs)
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')
print(WARN+'The figure is not yet connected to a client')
self._update(**kwargs)
return(False)
# DECLARE ALIASES -------------------------------------------------
......
......@@ -11,18 +11,19 @@ SERVER_FIGURES = {'FigTest': FigTests}
import serverside.myplotlib as mpl_server
import clientside.myplotlib as mpl_client
server = mpl_server.MplServer2(port=50803, knownFunctions=SERVER_IOFUNCTIONS, knownFigures=SERVER_FIGURES)
server = mpl_server.MplServer2(port=12345, knownFunctions=SERVER_IOFUNCTIONS, knownFigures=SERVER_FIGURES)
client = mpl_client.MplClient2()
# Start a thread with the server -- that thread will then start one
# more thread for each request
server_thread = threading.Thread(target=server.serve_forever)
# server_thread = threading.Thread(target=server.serve_forever)
# Exit the server thread when the main thread terminates
server_thread.daemon = True
server_thread.start()
print "Server loop running in thread:", server_thread.name
# server_thread.daemon = True
# server_thread.start()
server.run()
print "Server loop running in thread:", server.server_thread.name
client.connect(('', 50803))
client.connect(('localhost', 12345))
client.readData('readStupidData', 'data1')
fig1 = client.newSyncFigure(FigTestc, ('data1',))
......@@ -35,8 +36,10 @@ win.refresh()
sleep(2)
# multiple figures
fig2 = client.newSyncFigure(FigTestc, ('data1',))
fig2 = client.newSyncFigure(FigTestc, ('data1',), xRange=[-1.5, 1.5], yRange=[-1.5, 1.5])
win=mpl_client.MyWin(fig2)
fig1.deSyncFig()
fig2.deSyncFig()
sleep(2)
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