Commit df177576 authored by Philipp Gast's avatar Philipp Gast
Browse files

adapted a simple test case for the new alias system.

Also put get_state() into SHARED METHODS.
parent 108904de
Pipeline #517 failed with stage
in 11 minutes and 53 seconds
from .mpl_Data import MplData from .mpl_data import MplData
from matplotlib import rcParams from matplotlib import rcParams
# FORM ----------------------------------------------------------------- # FORM -----------------------------------------------------------------
...@@ -9,6 +9,8 @@ DBUG = " > dbug-: " ...@@ -9,6 +9,8 @@ DBUG = " > dbug-: "
SPCE = " > -----: " SPCE = " > -----: "
# CONFIGURATION -------------------------------------------------------- # CONFIGURATION --------------------------------------------------------
CONTEXT= 'CLIENT'
# myFig # myFig
D_FIGNUM = 0 # default figure number D_FIGNUM = 0 # default figure number
D_FIGSIZE = (8., 6.) # default figure size D_FIGSIZE = (8., 6.) # default figure size
......
...@@ -274,7 +274,7 @@ class MplFig(): ...@@ -274,7 +274,7 @@ class MplFig():
# Then eventually all collected Keywords are updated in one go # Then eventually all collected Keywords are updated in one go
if (ax_specific_keys) : if (ax_specific_keys) :
if self.debug: if self.debug:
print (DBUG+' fig.update ', ax, 'keywords: ', forax) print (DBUG+' fig.update ', ax, 'keywords: ', ax_specific_keys)
ax.update(**ax_specific_keys) ax.update(**ax_specific_keys)
return(True) return(True)
...@@ -286,7 +286,7 @@ class MplFig(): ...@@ -286,7 +286,7 @@ class MplFig():
applied like so: applied like so:
<axes_name>_<keyword_from_axes_context>""" <axes_name>_<keyword_from_axes_context>"""
for ax in self.axes: for ax in self.axes:
for key,val in ax.keywords.items() for key,val in ax.keywords.items():
self._tagged_keywords.update({ax.name+"_"+key : (ax , key) }) self._tagged_keywords.update({ax.name+"_"+key : (ax , key) })
# GET AXES BY NAME ------------------------------------------------- # GET AXES BY NAME -------------------------------------------------
...@@ -336,7 +336,25 @@ class MplFig(): ...@@ -336,7 +336,25 @@ class MplFig():
# LAYOUT ----------------------------------------------------------- # LAYOUT -----------------------------------------------------------
def layout(self): def layout(self):
self.grid.layout() self.grid.layout()
# GET STATE -----------------------------------------------------------
def get_state(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()
# test for double keywords and print a waring
for tagged_key,key_value in self._tagged_keywords.items():
ax, ax_key = key_value
state.update({tagged_key : ax.keyword[ax_key]})
return state
# === INTERFACE METHODS ============================================ # === INTERFACE METHODS ============================================
# #
# The interfaces methods are the one that the user supposely # The interfaces methods are the one that the user supposely
...@@ -508,16 +526,6 @@ class MplFig(): ...@@ -508,16 +526,6 @@ class MplFig():
""" """
pass pass
# GET STATE --------------------------------------------------------
def get_state(self):
"""Extract the state of the MplFig used to tests synchronisation.
This method make sens only in the client context, and is therefore
implemented in the ClassFactory.
"""
pass
# RE-SYNC FIGURE --------------------------------------------------- # RE-SYNC FIGURE ---------------------------------------------------
def re_sync_fig(self): def re_sync_fig(self):
"""Re-Synchronise a client figure with the server side. """Re-Synchronise a client figure with the server side.
...@@ -927,23 +935,6 @@ class MplFig(): ...@@ -927,23 +935,6 @@ class MplFig():
'The client is not connected to a server yet.' 'The client is not connected to a server yet.'
'Please use the client to set up a sync conection.') 'Please use the client to set up a sync conection.')
def _get_state_client(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()
# test for double keywords and print a waring
for tagged_key,key_value in self._tagged_keywords.items():
ax, ax_key = key_value
state.update({tagged_key : ax.keyword[ax_key]})
return state
def _re_sync_fig_client(self): def _re_sync_fig_client(self):
if self.client is not None: if self.client is not None:
......
from .. import D_HIERARCHY #~ from .. import D_HIERARCHY
from .myIOs import readStupidData, readStupidData2 from .myIOs import readStupidData, readStupidData2
if D_HIERARCHY in ('CLIENT', 'client'): #~ if D_HIERARCHY in ('CLIENT', 'client'):
from .axTestClient import AxTestClient #~ from .axTestClient import AxTestClient
from .figTestClient import FigTestClient as FigTest #~ from .figTestClient import FigTestClient as FigTest
# from .tests_client import myTest # from .tests_client import myTest
# from .tests_client import test100 # from .tests_client import test100
# from .tests import myTest # from .tests import myTest
...@@ -12,50 +12,50 @@ if D_HIERARCHY in ('CLIENT', 'client'): ...@@ -12,50 +12,50 @@ if D_HIERARCHY in ('CLIENT', 'client'):
# testList = [test100, # testList = [test100,
# ] # ]
elif D_HIERARCHY in ('SERVER', 'server'): #~ elif D_HIERARCHY in ('SERVER', 'server'):
from .axTestServer import AxTestServer #~ from .axTestServer import AxTestServer
from .figTestServer import FigTestServer as FigTest #~ from .figTestServer import FigTestServer as FigTest
# from .tests_server import myTest # from .tests_server import myTest
# from .tests_server import test100 # from .tests_server import test100
# testList = [test100, # testList = [test100,
# ] # ]
elif D_HIERARCHY in ('local', 'LOCAL'): #~ elif D_HIERARCHY in ('local', 'LOCAL'):
from .axTest1 import AxTest1 from .axTest1 import AxTest1
from .axTest1 import AxTestPlot2D, AxTestPlots2D #~ from .axTest1 import AxTestPlot2D, AxTestPlots2D
from .figTest import FigTest1, FigTest2 from .figTest import FigTest1, FigTest2
from .tests import myTest #~ from .tests import myTest
# import the tests # import the tests
from .tests import test100 #~ from .tests import test100
from .tests import test200, test201, test202, test203, test204 #~ from .tests import test200, test201, test202, test203, test204
from .tests import test300, test301, test302, test303, test304, test305 #~ from .tests import test300, test301, test302, test303, test304, test305
from .tests import test306, test307, test308, test309, test310, test311 #~ from .tests import test306, test307, test308, test309, test310, test311
from .tests import test312 #~ from .tests import test312
from .tests import test400, test401, test402, test403 #~ from .tests import test400, test401, test402, test403
from .tests import test500, test501, test502, test503, test504 #~ from .tests import test500, test501, test502, test503, test504
from .tests import test505, test506, test507, test508, test509 #~ from .tests import test505, test506, test507, test508, test509
from .tests import test510, test511 #~ from .tests import test510, test511
from .tests import test600 #~ from .tests import test600
#~
# the tests to run #~ # the tests to run
testList = [test100, #~ testList = [test100,
test201, test202, test203, test204, #~ test201, test202, test203, test204,
test300, test301, test302, test303, test304, test305, #~ test300, test301, test302, test303, test304, test305,
test306, test307, test308, test309, test310, test311, #~ test306, test307, test308, test309, test310, test311,
test312, #~ test312,
test400, test401, test402, #~ test400, test401, test402,
test503, test506, test500, test507, test501, test502, #~ test503, test506, test500, test507, test501, test502,
test504, test505, test508, test509, test510, test511, #~ test504, test505, test508, test509, test510, test511,
test600, #~ test600,
] #~ ]
#~
# for the demos #~ # for the demos
from ..mytool import print2screen #~ from ..mytool import print2screen
#~
else: #~ else:
#~
raise ImportError #~ raise ImportError
...@@ -43,8 +43,8 @@ ...@@ -43,8 +43,8 @@
# #
# IMPORT --------------------------------------------------------------- # IMPORT ---------------------------------------------------------------
from .. import SEVR, DBUG, INFO from .. import SEVR, DBUG, INFO
from .. import MyAxes from .. import MplAxes
from ..mytool import AxPlot2D, AxPlots2D #~ from ..mytool import AxPlot2D, AxPlots2D
D_XRANGE = None D_XRANGE = None
D_YRANGE = None D_YRANGE = None
...@@ -53,9 +53,9 @@ D_LOGX = False ...@@ -53,9 +53,9 @@ D_LOGX = False
# Class MyAxes Overwriting Matplotlib.figure.Axes # Class MyAxes Overwriting Matplotlib.figure.Axes
class AxTest1(MyAxes): class AxTest1(MplAxes):
def declareKeywords(self): def declare_keywords(self):
self.keywords = {'xRange': D_XRANGE, self.keywords = {'xRange': D_XRANGE,
'yRange': D_YRANGE} 'yRange': D_YRANGE}
...@@ -63,7 +63,7 @@ class AxTest1(MyAxes): ...@@ -63,7 +63,7 @@ class AxTest1(MyAxes):
return(True) return(True)
# FORMATTING --------------------------------------------------------- # FORMATTING ---------------------------------------------------------
def formatRawData(self, rawdata): def format_rawdata(self, rawdata):
# give value to data a dict # give value to data a dict
# with xdata, ydata1, zdata, ydata2 ... # with xdata, ydata1, zdata, ydata2 ...
...@@ -98,51 +98,51 @@ class AxTest1(MyAxes): ...@@ -98,51 +98,51 @@ class AxTest1(MyAxes):
return(True) return(True)
# Class MyAxes Overwriting Matplotlib.figure.Axes #~ # Class MyAxes Overwriting Matplotlib.figure.Axes
class AxTestPlots2D(AxPlots2D): #~ class AxTestPlots2D(AxPlots2D):
#~
# FORMATTING --------------------------------------------------------- #~ # FORMATTING ---------------------------------------------------------
def formatRawData(self, rawdata): #~ def formatRawData(self, rawdata):
#~
# give value to data a dict #~ # give value to data a dict
# with xdata, ydata1, zdata, ydata2 ... #~ # with xdata, ydata1, zdata, ydata2 ...
try: #~ try:
self.data = {'xdata': [rawdata.data[0], rawdata.data[1]], #~ self.data = {'xdata': [rawdata.data[0], rawdata.data[1]],
'ydatas': ([rawdata.data[2], rawdata.data[3]], #~ 'ydatas': ([rawdata.data[2], rawdata.data[3]],
[rawdata.data[3], rawdata.data[2]]), #~ [rawdata.data[3], rawdata.data[2]]),
'xlabel': 'Some X Label', #~ 'xlabel': 'Some X Label',
'ylabel': 'Some Y Label', #~ 'ylabel': 'Some Y Label',
'labels': ('curve 1', 'curve 2')} #~ 'labels': ('curve 1', 'curve 2')}
#~
except(TypeError, KeyError, IndexError): #~ except(TypeError, KeyError, IndexError):
print(SEVR + 'The Raw Data could not be formatted --> EXIT') #~ print(SEVR + 'The Raw Data could not be formatted --> EXIT')
return(False) #~ return(False)
#~
if(self.fig.debug): #~ if(self.fig.debug):
print(DBUG + 'I formatted the raw data!') #~ print(DBUG + 'I formatted the raw data!')
#~
return(True) #~ return(True)
#~
#~
# Class MyAxes Overwriting Matplotlib.figure.Axes #~ # Class MyAxes Overwriting Matplotlib.figure.Axes
class AxTestPlot2D(AxPlot2D): #~ class AxTestPlot2D(AxPlot2D):
#~
# FORMATTING --------------------------------------------------------- #~ # FORMATTING ---------------------------------------------------------
def formatRawData(self, rawdata): #~ def formatRawData(self, rawdata):
#~
# give value to data a dict #~ # give value to data a dict
# with xdata, ydata1, zdata, ydata2 ... #~ # with xdata, ydata1, zdata, ydata2 ...
try: #~ try:
self.data = {'xdata': [rawdata.data[0], rawdata.data[1]], #~ self.data = {'xdata': [rawdata.data[0], rawdata.data[1]],
'ydata': [rawdata.data[2], rawdata.data[3]], #~ 'ydata': [rawdata.data[2], rawdata.data[3]],
'xlabel': 'Some X Label', #~ 'xlabel': 'Some X Label',
'ylabel': 'Some Y Label'} #~ 'ylabel': 'Some Y Label'}
#~
except(TypeError, KeyError, IndexError): #~ except(TypeError, KeyError, IndexError):
print(SEVR + 'The Raw Data could not be formatted --> EXIT') #~ print(SEVR + 'The Raw Data could not be formatted --> EXIT')
return(False) #~ return(False)
#~
if(self.fig.debug): #~ if(self.fig.debug):
print(DBUG + 'I formatted the raw data!') #~ print(DBUG + 'I formatted the raw data!')
#~
return(True) #~ return(True)
...@@ -67,13 +67,13 @@ ...@@ -67,13 +67,13 @@
# IMPORT --------------------------------------------------------------- # IMPORT ---------------------------------------------------------------
from .. import os from .. import os
from .. import DBUG, SEVR, INFO, SPCE, WARN from .. import DBUG, SEVR, INFO, SPCE, WARN
from .. import MyFig from .. import MplFig
from .axTest1 import AxTest1 from .axTest1 import AxTest1
# Class MyFig Overwriting Matplotlib.figure.Figure # Class MyFig Overwriting Matplotlib.figure.Figure
class FigTest1(MyFig): # Fig with one Axes class FigTest1(MplFig): # Fig with one Axes
# Set the size of the Figure in inch # Set the size of the Figure in inch
# (private variable can not be updated) # (private variable can not be updated)
...@@ -85,7 +85,7 @@ class FigTest1(MyFig): # Fig wi ...@@ -85,7 +85,7 @@ class FigTest1(MyFig): # Fig wi
self.add_axes(AxTest1(self, frame1), "p1") self.add_axes(AxTest1(self, frame1), "p1")
class FigTest2(MyFig): # Fig with two Axes class FigTest2(MplFig): # Fig with two Axes
# Set the size of the Figure in inch # Set the size of the Figure in inch
# (private variable can not be updated) # (private variable can not be updated)
...@@ -99,12 +99,7 @@ class FigTest2(MyFig): # Fig wi ...@@ -99,12 +99,7 @@ class FigTest2(MyFig): # Fig wi
print(self.add_axes(AxTest1(self, frame1), "p1")) print(self.add_axes(AxTest1(self, frame1), "p1"))
print(self.add_axes(AxTest1(self, frame2), "p2")) print(self.add_axes(AxTest1(self, frame2), "p2"))
def declareAliases(self): def declare_aliases(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_xRange","p2_xRange")} self.aliases = {'xRange': ("p1_xRange","p2_xRange")}
......
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