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
# FORM -----------------------------------------------------------------
......@@ -9,6 +9,8 @@ DBUG = " > dbug-: "
SPCE = " > -----: "
# CONFIGURATION --------------------------------------------------------
CONTEXT= 'CLIENT'
# myFig
D_FIGNUM = 0 # default figure number
D_FIGSIZE = (8., 6.) # default figure size
......
......@@ -274,7 +274,7 @@ class MplFig():
# Then eventually all collected Keywords are updated in one go
if (ax_specific_keys) :
if self.debug:
print (DBUG+' fig.update ', ax, 'keywords: ', forax)
print (DBUG+' fig.update ', ax, 'keywords: ', ax_specific_keys)
ax.update(**ax_specific_keys)
return(True)
......@@ -286,7 +286,7 @@ class MplFig():
applied like so:
<axes_name>_<keyword_from_axes_context>"""
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) })
# GET AXES BY NAME -------------------------------------------------
......@@ -336,7 +336,25 @@ class MplFig():
# LAYOUT -----------------------------------------------------------
def layout(self):
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 ============================================
#
# The interfaces methods are the one that the user supposely
......@@ -508,16 +526,6 @@ class MplFig():
"""
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 ---------------------------------------------------
def re_sync_fig(self):
"""Re-Synchronise a client figure with the server side.
......@@ -927,23 +935,6 @@ class MplFig():
'The client is not connected to a server yet.'
'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):
if self.client is not None:
......
from .. import D_HIERARCHY
#~ from .. import D_HIERARCHY
from .myIOs import readStupidData, readStupidData2
if D_HIERARCHY in ('CLIENT', 'client'):
#~ if D_HIERARCHY in ('CLIENT', 'client'):
from .axTestClient import AxTestClient
from .figTestClient import FigTestClient as FigTest
#~ from .axTestClient import AxTestClient
#~ from .figTestClient import FigTestClient as FigTest
# from .tests_client import myTest
# from .tests_client import test100
# from .tests import myTest
......@@ -12,50 +12,50 @@ if D_HIERARCHY in ('CLIENT', 'client'):
# testList = [test100,
# ]
elif D_HIERARCHY in ('SERVER', 'server'):
from .axTestServer import AxTestServer
from .figTestServer import FigTestServer as FigTest
#~ elif D_HIERARCHY in ('SERVER', 'server'):
#~ from .axTestServer import AxTestServer
#~ from .figTestServer import FigTestServer as FigTest
# from .tests_server import myTest
# from .tests_server import test100
# testList = [test100,
# ]
elif D_HIERARCHY in ('local', 'LOCAL'):
#~ elif D_HIERARCHY in ('local', 'LOCAL'):
from .axTest1 import AxTest1
from .axTest1 import AxTestPlot2D, AxTestPlots2D
from .figTest import FigTest1, FigTest2
from .axTest1 import AxTest1
#~ from .axTest1 import AxTestPlot2D, AxTestPlots2D
from .figTest import FigTest1, FigTest2
from .tests import myTest
#~ from .tests import myTest
# import the tests
from .tests import test100
from .tests import test200, test201, test202, test203, test204
from .tests import test300, test301, test302, test303, test304, test305
from .tests import test306, test307, test308, test309, test310, test311
from .tests import test312
from .tests import test400, test401, test402, test403
from .tests import test500, test501, test502, test503, test504
from .tests import test505, test506, test507, test508, test509
from .tests import test510, test511
from .tests import test600
# the tests to run
testList = [test100,
test201, test202, test203, test204,
test300, test301, test302, test303, test304, test305,
test306, test307, test308, test309, test310, test311,
test312,
test400, test401, test402,
test503, test506, test500, test507, test501, test502,
test504, test505, test508, test509, test510, test511,
test600,
]
# for the demos
from ..mytool import print2screen
else:
raise ImportError
#~ from .tests import test100
#~ from .tests import test200, test201, test202, test203, test204
#~ from .tests import test300, test301, test302, test303, test304, test305
#~ from .tests import test306, test307, test308, test309, test310, test311
#~ from .tests import test312
#~ from .tests import test400, test401, test402, test403
#~ from .tests import test500, test501, test502, test503, test504
#~ from .tests import test505, test506, test507, test508, test509
#~ from .tests import test510, test511
#~ from .tests import test600
#~
#~ # the tests to run
#~ testList = [test100,
#~ test201, test202, test203, test204,
#~ test300, test301, test302, test303, test304, test305,
#~ test306, test307, test308, test309, test310, test311,
#~ test312,
#~ test400, test401, test402,
#~ test503, test506, test500, test507, test501, test502,
#~ test504, test505, test508, test509, test510, test511,
#~ test600,
#~ ]
#~
#~ # for the demos
#~ from ..mytool import print2screen
#~
#~ else:
#~
#~ raise ImportError
......@@ -43,8 +43,8 @@
#
# IMPORT ---------------------------------------------------------------
from .. import SEVR, DBUG, INFO
from .. import MyAxes
from ..mytool import AxPlot2D, AxPlots2D
from .. import MplAxes
#~ from ..mytool import AxPlot2D, AxPlots2D
D_XRANGE = None
D_YRANGE = None
......@@ -53,9 +53,9 @@ D_LOGX = False
# Class MyAxes Overwriting Matplotlib.figure.Axes
class AxTest1(MyAxes):
class AxTest1(MplAxes):
def declareKeywords(self):
def declare_keywords(self):
self.keywords = {'xRange': D_XRANGE,
'yRange': D_YRANGE}
......@@ -63,7 +63,7 @@ class AxTest1(MyAxes):
return(True)
# FORMATTING ---------------------------------------------------------
def formatRawData(self, rawdata):
def format_rawdata(self, rawdata):
# give value to data a dict
# with xdata, ydata1, zdata, ydata2 ...
......@@ -98,51 +98,51 @@ class AxTest1(MyAxes):
return(True)
# Class MyAxes Overwriting Matplotlib.figure.Axes
class AxTestPlots2D(AxPlots2D):
# FORMATTING ---------------------------------------------------------
def formatRawData(self, rawdata):
# give value to data a dict
# with xdata, ydata1, zdata, ydata2 ...
try:
self.data = {'xdata': [rawdata.data[0], rawdata.data[1]],
'ydatas': ([rawdata.data[2], rawdata.data[3]],
[rawdata.data[3], rawdata.data[2]]),
'xlabel': 'Some X Label',
'ylabel': 'Some Y Label',
'labels': ('curve 1', 'curve 2')}
except(TypeError, KeyError, IndexError):
print(SEVR + 'The Raw Data could not be formatted --> EXIT')
return(False)
if(self.fig.debug):
print(DBUG + 'I formatted the raw data!')
return(True)
# Class MyAxes Overwriting Matplotlib.figure.Axes
class AxTestPlot2D(AxPlot2D):
# FORMATTING ---------------------------------------------------------
def formatRawData(self, rawdata):
# give value to data a dict
# with xdata, ydata1, zdata, ydata2 ...
try:
self.data = {'xdata': [rawdata.data[0], rawdata.data[1]],
'ydata': [rawdata.data[2], rawdata.data[3]],
'xlabel': 'Some X Label',
'ylabel': 'Some Y Label'}
except(TypeError, KeyError, IndexError):
print(SEVR + 'The Raw Data could not be formatted --> EXIT')
return(False)
if(self.fig.debug):
print(DBUG + 'I formatted the raw data!')
return(True)
#~ # Class MyAxes Overwriting Matplotlib.figure.Axes
#~ class AxTestPlots2D(AxPlots2D):
#~
#~ # FORMATTING ---------------------------------------------------------
#~ def formatRawData(self, rawdata):
#~
#~ # give value to data a dict
#~ # with xdata, ydata1, zdata, ydata2 ...
#~ try:
#~ self.data = {'xdata': [rawdata.data[0], rawdata.data[1]],
#~ 'ydatas': ([rawdata.data[2], rawdata.data[3]],
#~ [rawdata.data[3], rawdata.data[2]]),
#~ 'xlabel': 'Some X Label',
#~ 'ylabel': 'Some Y Label',
#~ 'labels': ('curve 1', 'curve 2')}
#~
#~ except(TypeError, KeyError, IndexError):
#~ print(SEVR + 'The Raw Data could not be formatted --> EXIT')
#~ return(False)
#~
#~ if(self.fig.debug):
#~ print(DBUG + 'I formatted the raw data!')
#~
#~ return(True)
#~
#~
#~ # Class MyAxes Overwriting Matplotlib.figure.Axes
#~ class AxTestPlot2D(AxPlot2D):
#~
#~ # FORMATTING ---------------------------------------------------------
#~ def formatRawData(self, rawdata):
#~
#~ # give value to data a dict
#~ # with xdata, ydata1, zdata, ydata2 ...
#~ try:
#~ self.data = {'xdata': [rawdata.data[0], rawdata.data[1]],
#~ 'ydata': [rawdata.data[2], rawdata.data[3]],
#~ 'xlabel': 'Some X Label',
#~ 'ylabel': 'Some Y Label'}
#~
#~ except(TypeError, KeyError, IndexError):
#~ print(SEVR + 'The Raw Data could not be formatted --> EXIT')
#~ return(False)
#~
#~ if(self.fig.debug):
#~ print(DBUG + 'I formatted the raw data!')
#~
#~ return(True)
......@@ -67,13 +67,13 @@
# IMPORT ---------------------------------------------------------------
from .. import os
from .. import DBUG, SEVR, INFO, SPCE, WARN
from .. import MyFig
from .. import MplFig
from .axTest1 import AxTest1
# 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
# (private variable can not be updated)
......@@ -85,7 +85,7 @@ class FigTest1(MyFig): # Fig wi
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
# (private variable can not be updated)
......@@ -99,12 +99,7 @@ class FigTest2(MyFig): # Fig wi
print(self.add_axes(AxTest1(self, frame1), "p1"))
print(self.add_axes(AxTest1(self, 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")
def declare_aliases(self):
self.aliases = {'xRange': ("p1_xRange","p2_xRange")}
......
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