Commit 5549873a authored by Philipp Gast's avatar Philipp Gast
Browse files

getting the status now works. Also client.listRemoteData() and...

getting the status now works. Also client.listRemoteData() and client.getData() are added. Possible problem see Issue.
parent 35162722
Pipeline #430 failed with stage
in 3 minutes and 2 seconds
......@@ -104,9 +104,32 @@ class MplClient2():
def listRemoteData(self):
""" The server retuns a list with the content of its G_RAWDATA
not implemented yet.
"""
pass
query = Query(Query.LISTDATA,None)
status = self.send(query)
if not status :
print('something went wrong with the sending of readData request...')
answer = self.waitForSignal()
if isinstance(answer,Answer) :
return answer.content
elif isinstance(answer,Status):
print(answer.content)
return None
def getData(self, dataname) :
""" The server returns the actual data known under "dataname" warning: this can possibly be HUGE
"""
query = Query(Query.GETDATA,dataname)
status = self.send(query)
if not status :
print('something went wrong with the sending of readData request...')
answer = self.waitForSignal()
if isinstance(answer,Answer) :
return answer.content
elif isinstance(answer,Status):
print(answer.content)
return None
def newSyncFigure(self, figname, dataname, *args, **kwargs) :
'''
......
......@@ -154,7 +154,17 @@ class MplHandler(SocketServer.StreamRequestHandler):
return Status(True,'Figure with ID '+str(figID)+' deleted from server.')
else :
return Status(False,'Figure with ID '+str(figID)+' not found on server side.')
def treatListData(self,content) :
""" list the keys (and possibly (later) the location from G_RAWDATA """
return Answer(G_RAWDATA.keys())
def treatGetData(self,content) :
""" from G_FIGURES """
if content in G_RAWDATA:
return Answer(G_RAWDATA[content])
else :
return Status(False,'Dataname not found in index of the server side...')
def send(self,sig):
# pickel the signal
......@@ -204,6 +214,10 @@ class MplHandler(SocketServer.StreamRequestHandler):
return self.treatSyncFigFormatRawData(sig.content)
elif sig.queryType == sig.DELETESYNCFIGURE :
return self.treatDeleteSyncFigure(sig.content)
elif sig.queryType == sig.LISTDATA :
return self.treatListData(sig.content)
elif sig.queryType == sig.GETDATA :
return self.treatGetData(sig.content)
else :
self.servPrint('received unknown query type')
return Status(False,"received unknown query type")
......
......@@ -119,8 +119,50 @@ class MyFig_client(Figure):
else :
print('The figure could not be deleted on the server Side')
else:
print('The client is not connected to a server yet')
print('The client is not connected to a server yet. Please use the client to set up a sync conection.')
def getState(self) :
""" this function collects the current state of in the figure by creating a dict that holds all keyword,value pairs (taking the aliases into account)
Warning: myplotlib allows in a transparent manner to modify the axes directly. Those changes can not be covert.
"""
state = dict()
for ax in self.axes:
# find aliases for this specific axes
masks = dict()
for alias in self.aliases.keys() :
axes4alias,keyword = self.aliases[alias]
if axes4alias == ax :
masks.update({keyword : alias})
# collect all keywords of the axes and replace the keys with the aliases
axKeywords = ax.keywords.copy()
for mask in masks :
if mask in axKeywords :
axKeywords[masks[mask]] = axKeywords.pop(mask)
# update the global keyword index
state.update(axKeywords)
return state
def reSyncFig(self):
if self.client is not None :
# collect the current state of the figure
state = self.getState()
# call the client to recreate the figure on the server side and analyse the status.
if self.client.reSyncFig(self.syncID,state) :
print('The figure was successfully recreated on the server side')
self.syncID = -1
else :
print('The figure could not be recreated on the server side')
else:
print('The client is not connected to a server yet. Please use the client to set up a sync conection.')
# INITIALIZE -------------------------------------------------------
def _initialize(self, *args, **kwargs):
......
......@@ -10,9 +10,11 @@ class Query(Signal) :
UPDATESYNCFIGURE = 3
SYNCFIGFORMATRAWDATA = 4
DELETESYNCFIGURE = 5
LISTDATA = 6
GETDATA = 7
def __init__(self,queryType, content) :
if queryType in [Query.READDATA,Query.NEWSYNCFIGURE,Query.UPDATESYNCFIGURE,Query.SYNCFIGFORMATRAWDATA,Query.DELETESYNCFIGURE] :
if queryType in range(1,8) :
self.queryType = queryType
if queryType == Query.READDATA :
if type(content) == dict :
......@@ -35,6 +37,10 @@ class Query(Signal) :
elif queryType == Query.DELETESYNCFIGURE :
self.content = content
elif queryType == Query.LISTDATA :
self.content = content
elif queryType == Query.GETDATA :
self.content = content
else :
print('unknown query type!')
raise
......
......@@ -12,3 +12,30 @@ class FigTest(MyFig):
frame1 = [0.1, 0.1, 0.8, 0.8] # part of the fig that is available
self.add_axes(AxTest(self, ratio, frame1), "p1")
class FigTest2(MyFig): # Fig with two Axes
# Set the size of the Figure in inch
# (private variable can not be updated)
FIGSIZE = (8., 6.)
def addAxes(self):
ratio = 6. / 8. # height/width of the axes (in inch)
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
print(self.add_axes(AxTest(self, ratio, frame1),"p1"))
print(self.add_axes(AxTest(self, ratio, frame2),"p2"))
def declareAliases(self):
# it is important to not hold additional references to an axes in the figure to avoid memory leaks. use the this function
# get the plot added above
p1 = self.getAxesByName("p1")
p2 = self.getAxesByName("p2")
self.aliases = {'xRange_p1': (p1, "xRange"),
'xRange_p2': (p2, "xRange")}
return(True)
......@@ -12,3 +12,30 @@ class FigTest(MyFig):
frame1 = [0.1, 0.1, 0.8, 0.8] # part of the fig that is available
self.add_axes(AxTest(self, ratio, frame1), "p1")
class FigTest2(MyFig): # Fig with two Axes
# Set the size of the Figure in inch
# (private variable can not be updated)
FIGSIZE = (8., 6.)
def addAxes(self):
ratio = 6. / 8. # height/width of the axes (in inch)
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
print(self.add_axes(AxTest(self, ratio, frame1),"p1"))
print(self.add_axes(AxTest(self, ratio, frame2),"p2"))
def declareAliases(self):
# it is important to not hold additional references to an axes in the figure to avoid memory leaks. use the this function
# get the plot added above
p1 = self.getAxesByName("p1")
p2 = self.getAxesByName("p2")
self.aliases = {'xRange_p1': (p1, "xRange"),
'xRange_p2': (p2, "xRange")}
return(True)
......@@ -2,11 +2,16 @@ import threading
from time import sleep
from serverside.myIOs import readStupidData
from serverside.myIOs import readStupidData2
from serverside.figTest import FigTest as FigTests
from clientside.figTest import FigTest as FigTestc
SERVER_IOFUNCTIONS = {'readStupidData': readStupidData}
SERVER_FIGURES = {'FigTest': FigTests}
# This is for the double figure
from serverside.figTest import FigTest2 as FigTests2
from clientside.figTest import FigTest2 as FigTestc2
SERVER_IOFUNCTIONS = {'readStupidData': readStupidData,'readStupidData2': readStupidData2}
SERVER_FIGURES = {'FigTest': FigTests,'FigTest2': FigTests}
import serverside.myplotlib as mpl_server
import clientside.myplotlib as mpl_client
......@@ -27,19 +32,24 @@ client.connect(('localhost', 12345))
client.readData('readStupidData', 'data1')
fig1 = client.newSyncFigure(FigTestc, ('data1',))
win=mpl_client.MyWin(fig1)
sleep(2)
#~ win=mpl_client.MyWin(fig1)
#~ sleep(2)
# update test
fig1.update(xRange=[-2, 2],yRange=[-2, 2])
win.refresh()
sleep(2)
# multiple figures
fig2 = client.newSyncFigure(FigTestc, ('data1',), xRange=[-1.5, 1.5], yRange=[-1.5, 1.5])
win=mpl_client.MyWin(fig2)
fig1.deSyncFig()
fig2.deSyncFig()
#~ win.refresh()
#~ sleep(2)
# multiple figures with multiple data
client.readData('readStupidData2', 'data2')
print("known datasets: ",client.listRemoteData())
fig2 = client.newSyncFigure(FigTestc2, ('data1','data2'), xRange=[-1.5, 1.5], yRange=[-1.5, 1.5])
#~ fig2 = client.newSyncFigure(FigTestc2, ('data1',), xRange=[-1.5, 1.5], yRange=[-1.5, 1.5])
print('current state:::',fig2.getState())
#~ win=mpl_client.MyWin(fig2)
#~
#~
#~ fig1.deSyncFig()
#~ fig2.deSyncFig()
sleep(2)
Supports Markdown
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