Commit e5524e1d authored by Yori Fournier's avatar Yori Fournier
Browse files

Merge branch 'someTesting-for-myguilib' into 'dev'

Some testing for myguilib

See merge request !8
parents b8100ee8 567d4b84
...@@ -48,7 +48,7 @@ from matplotlib import is_interactive ...@@ -48,7 +48,7 @@ from matplotlib import is_interactive
from matplotlib import rcParams from matplotlib import rcParams
from matplotlib import use from matplotlib import use
rcParams['backend'] = u'TkAgg' rcParams['backend'] = u'GTKAgg'
# myplotlib # myplotlib
from myData import MyData from myData import MyData
...@@ -100,9 +100,6 @@ rc('figure', dpi = 75.0) ...@@ -100,9 +100,6 @@ rc('figure', dpi = 75.0)
# MyAxes: Overlay on matplotlib.Axes class # MyAxes: Overlay on matplotlib.Axes class
from .myAxes import MyAxes from .myAxes import MyAxes
# MyIOs.*: input/output function for testing
from .myIOs import readStupidData, readStupidData2
# MyFig: Overlay on matplotlib.Figure class # MyFig: Overlay on matplotlib.Figure class
from .myFig import MyFig from .myFig import MyFig
...@@ -121,12 +118,6 @@ from .myTool import print2file, print2screen, printListCurrentWindows ...@@ -121,12 +118,6 @@ from .myTool import print2file, print2screen, printListCurrentWindows
from .myTool import getWindow, getFigOnWindow, drawFigOnWindow, giveDataToWindow from .myTool import getWindow, getFigOnWindow, drawFigOnWindow, giveDataToWindow
from .myTool import closeWindow, closeAllWindows from .myTool import closeWindow, closeAllWindows
# MyFig4Test: Overlay of Figure for testing
from .myFig4Test import MyFig4Test
# some plotting routine for testing
from .myPlot4Test import somePlottingRoutine
from .test import myTest from .test import myTest
from .test import test400, test300, test301, test302, test303, test304, test305, test306, test401, test402, test403 from .test import test400, test300, test301, test302, test303, test304, test305, test306, test401, test402, test403
......
...@@ -51,9 +51,7 @@ from . import rcParams ...@@ -51,9 +51,7 @@ from . import rcParams
class MyAxes(Axes): class MyAxes(Axes):
# CONSTRUCTOR -------------------------------------------------------- # CONSTRUCTOR --------------------------------------------------------
def __init__(self, fig, ratio, frameRect, **kwargs): def __init__(self, fig, ratio, frameRect, *args, **kwargs):
self.debug = kwargs.get('debug', 0)
# get the frame allowed # get the frame allowed
framePosX, framePosY, frameWidth, frameHeight = frameRect framePosX, framePosY, frameWidth, frameHeight = frameRect
...@@ -96,29 +94,8 @@ class MyAxes(Axes): ...@@ -96,29 +94,8 @@ class MyAxes(Axes):
# PLOTTING ----------------------------------------------------------- # PLOTTING -----------------------------------------------------------
# the plotting function (need to be overwrite from child # the plotting function (need to be overwrite from child
def plotting(self): def plotting(self):
try: pass
self.plot(self.data['xdata'], self.data['ydata'])
except KeyError:
print(SEVR + 'The formatting of the data was apparently wrong. --> EXIT')
return(False)
return(True)
# FORMATTING --------------------------------------------------------- # FORMATTING ---------------------------------------------------------
def formatRawData(self, rawdata): def formatRawData(self, rawdata):
pass
# 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]]}
except (TypeError, KeyError):
print(SEVR + 'The Raw Data could not be formatted --> EXIT')
return(False)
if(self.debug):
print(DBUG + 'I formatted the raw data!\n')
print(DBUG + 'formatted data:\n' + str(self.formattedDatas))
return(True)
...@@ -70,7 +70,7 @@ from . import D_FIGSIZE, D_INPUTARG, D_DEBUG, D_REFORMAT, D_FORMATTED ...@@ -70,7 +70,7 @@ from . import D_FIGSIZE, D_INPUTARG, D_DEBUG, D_REFORMAT, D_FORMATTED
from . import D_OFORMAT, D_OPATH from . import D_OFORMAT, D_OPATH
from . import DBUG, SEVR, INFO, SPCE, WARN from . import DBUG, SEVR, INFO, SPCE, WARN
from . import G_RAWDATAS from . import G_RAWDATAS
from . import Figure, MyAxes from . import Figure
# Class MyFig Overwriting Matplotlib.figure.Figure # Class MyFig Overwriting Matplotlib.figure.Figure
...@@ -118,6 +118,7 @@ class MyFig(Figure): ...@@ -118,6 +118,7 @@ class MyFig(Figure):
print(SPCE + " ID the figure: " + str(self.keywords['fignum'])) print(SPCE + " ID the figure: " + str(self.keywords['fignum']))
print(SPCE + "Size of the figure: " + str(self.FIGSIZE) + ' [inch] \n') print(SPCE + "Size of the figure: " + str(self.FIGSIZE) + ' [inch] \n')
# PLOT --------------------------------------------------------------- # PLOT ---------------------------------------------------------------
def plot(self): def plot(self):
...@@ -127,14 +128,12 @@ class MyFig(Figure): ...@@ -127,14 +128,12 @@ class MyFig(Figure):
print(SEVR + "The dataset {dataName} does not exist. --> FALSE".format(dataName=self.keywords['inputarg'])) print(SEVR + "The dataset {dataName} does not exist. --> FALSE".format(dataName=self.keywords['inputarg']))
return(False) return(False)
ratio = 6. / 8. # height/width of the axes (in inch) # For all axes in the figure reformat if needed and plot
frame = [0.0, 0.0, 1.0, 1.0] # part of the fig that is available for ax in self.get_axes():
# create an axes MyAxes with a given rect
ax = MyAxes(self, ratio, frame)
# reformat the data if needed (default True) # reformat the data if needed (default True)
if((self.keywords['reformat']) or (not self.keywords['formatted'])): if((self.keywords['reformat']) or (not self.keywords['formatted'])):
try: try:
status = ax.formatRawData(self.rawdata) status = ax.formatRawData(self.rawdata)
self.keywords['formatted'] = True self.keywords['formatted'] = True
...@@ -142,17 +141,15 @@ class MyFig(Figure): ...@@ -142,17 +141,15 @@ class MyFig(Figure):
print(SEVR + 'The formatting of the data was apparently wrong. --> EXIT') print(SEVR + 'The formatting of the data was apparently wrong. --> EXIT')
return(False) return(False)
if(not status): return(False) # clean
ax.cla()
# add the axis to the figure # plot
self.add_axes(ax)
# try to plot the Axes
status = ax.plotting() status = ax.plotting()
if(not status): return(False) if(not status): return(False)
return(True) return(True)
# UPDATE ------------------------------------------------------------- # UPDATE -------------------------------------------------------------
def update(self, **kwargs): def update(self, **kwargs):
......
...@@ -40,7 +40,7 @@ from . import INFO, SEVR, WARN, SPCE ...@@ -40,7 +40,7 @@ from . import INFO, SEVR, WARN, SPCE
from . import ion, ioff, is_interactive from . import ion, ioff, is_interactive
from . import MyWin, MyFig from . import MyWin
from . import np from . import np
......
...@@ -173,7 +173,6 @@ class MyWin_GTKAgg(FigureManagerGTKAgg): ...@@ -173,7 +173,6 @@ class MyWin_GTKAgg(FigureManagerGTKAgg):
self.set_figure(self.canvas.figure) self.set_figure(self.canvas.figure)
# refresh # refresh
self.canvas.figure.clf()
self.canvas.figure.plot() self.canvas.figure.plot()
self.canvas.draw() self.canvas.draw()
......
...@@ -58,8 +58,15 @@ from . import np ...@@ -58,8 +58,15 @@ from . import np
# For the backend # For the backend
from matplotlib.backends.backend_tkagg import FigureManagerTkAgg, FigureCanvasTkAgg from matplotlib.backends.backend_tkagg import FigureManagerTkAgg, FigureCanvasTkAgg
from matplotlib.externals import six
from matplotlib.externals.six.moves import tkinter as Tk # Test mpl version:
from matplotlib import __version__ as mplvers
if int(mplvers.replace('.','')) < 150 :
import six
from six.moves import tkinter as Tk
else :
from matplotlib.externals import six
from matplotlib.externals.six.moves import tkinter as Tk
# Class MyWin Overwriting the disgusting Matplotlib.FigureManager class # Class MyWin Overwriting the disgusting Matplotlib.FigureManager class
...@@ -182,7 +189,6 @@ class MyWin_TkAgg(FigureManagerTkAgg): ...@@ -182,7 +189,6 @@ class MyWin_TkAgg(FigureManagerTkAgg):
self.set_figure(self.canvas.figure) self.set_figure(self.canvas.figure)
# refresh # refresh
self.canvas.figure.clf()
self.canvas.figure.plot() self.canvas.figure.plot()
self.canvas.draw() self.canvas.draw()
......
...@@ -138,7 +138,6 @@ class MyWin_WXAgg(FigureManagerWx): ...@@ -138,7 +138,6 @@ class MyWin_WXAgg(FigureManagerWx):
# if show is on, then show the window # if show is on, then show the window
if show: if show:
self.canvas.figure.clf()
self.canvas.figure.plot() self.canvas.figure.plot()
self.show() self.show()
self.canvas.draw() self.canvas.draw()
...@@ -187,7 +186,6 @@ class MyWin_WXAgg(FigureManagerWx): ...@@ -187,7 +186,6 @@ class MyWin_WXAgg(FigureManagerWx):
self.set_figure(self.canvas.figure) self.set_figure(self.canvas.figure)
#refresh #refresh
self.canvas.figure.clf()
self.canvas.figure.plot() self.canvas.figure.plot()
self.canvas.draw() self.canvas.draw()
self.canvas.figure.plot() self.canvas.figure.plot()
......
from myIOs import readStupidData, readStupidData2
from axTest1 import AxTest1
from figTest1 import FigTest1
from tests import myTest
from tests import test400, test300, test301, test302, test303, test304, test305, test306, test401, test402, test403
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# ================= FILE HEADER ========================================
#
# myplotlib v0.0.0,
#
# @file myAxes.py
# @author Yori 'AGy' Fournier
# @licence CC-BY-SA
#
# MyAxes class: Overlay of matplotlib Axes class
# It is done such that the user can concentrate on
# the important aspect of the figure and not the
# technical part. It consists of a constructor,
# that requires a Figure, the ratio of the xaxis over
# the yaxis, and the frame in which the figure
# should be plotted.
#
# @Class MyAxes
#
# @Constructor(self, fig, ratio, frame, +user defined kw):
#
# @section Functions
#
# - plotting: this is the overwritten function
# from Axes. It is called by it's
# parent-figure's function .plot()
#
# - formatRawData: it computes out of the rawData
# given as argument some quantities that
# are returned as a dictionary and
# become accessable for plotting.
#
# @section History
#
# v 0.0.0 - MyAxes class for the myplotlib module, consists
# of a constructor, a pltting function and
# formatRawData.
#
# ======================================================================
#
#
# IMPORT ---------------------------------------------------------------
from .. import SEVR, DBUG
from .. import MyAxes
# Class MyAxes Overwriting Matplotlib.figure.Axes
class AxTest1(MyAxes):
# CONSTRUCTOR --------------------------------------------------------
def __init__(self, fig, ratio, frameRect, *args, **kwargs):
self.fig = fig
# parent constructor
MyAxes.__init__(self, fig, ratio, frameRect, *args, **kwargs)
# PLOTTING -----------------------------------------------------------
# the plotting function (need to be overwrite from child
def plotting(self):
try:
self.plot(self.data['xdata'], self.data['ydata'])
except KeyError:
print(SEVR + 'The formatting of the data was apparently wrong. --> EXIT')
return(False)
return(True)
# 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]]}
except (TypeError, KeyError):
print(SEVR + 'The Raw Data could not be formatted --> EXIT')
return(False)
if(self.fig.keywords['debug']):
print(DBUG + 'I formatted the raw data!\n')
print(DBUG + 'formatted data:\n' + str(self.fig.keywords['formatted']))
return(True)
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# ================= FILE HEADER ========================================
#
# myplotlib v1.0.1,
#
# @file myFig.py
# @author Yori 'AGy' Fournier
# @licence CC-BY-SA
#
# MyFig class: Overlay of matplotlib Figure class
# It is done such that the user can concentrate on
# the important aspect of the figure and not the
# technical part.
#
# @Class MyFig
#
# @Constructor
#
# fignum: number of the Figure.
# inputarg: identifier of the raw data in G_RAWDATA.
# reformat: flag for reComputing plotted data
# from rawData.
# debug: flag for debugging, more verbatile.
# (kw)args: user defined arguments and keywords.
#
# @section Functions
#
# - printDebug: print some debug information.
#
# - plot: overlay of Figure.plot() function,
# should be overwrited by the user.
# Consists of
# - creating axes,
# - formating the data,
# - adding the axis to the figure
# - plotting the axis
#
# - update: update the parameters in the
# keywords dictionary.
#
# @section History
#
# v 0.1.1 - MyFig class for the myplotlib module.
#
# v 1.0.0 - Changed rawdata with inputarg to allows any type
# of rawdata, can be an array.
#
# replace the attribute format (reserved word) with
# formatted.
#
# v 1.0.1 - Suppress the explicit definitions of the keywords.
# by the introduction of the keywords dictionary.
# All parameters in this dictionary are automatically
# updated.
#
# suppress the default value of fignum and hardcode it
# to be -1.
#
# add the attribute boundedToWin required for the
# interactive mode of myplotlib.
#
# ======================================================================
#
#
# IMPORT ---------------------------------------------------------------
from .. import os
from .. import DBUG, SEVR, INFO, SPCE, WARN
from .. import MyFig
from .axTest1 import AxTest1
D_XRANGE = [-1, 1]
D_YRANGE = [-2, 2]
# Class MyFig Overwriting Matplotlib.figure.Figure
class FigTest1(MyFig):
# Set the size of the Figure in inch
# (private variable can not be updated)
FIGSIZE = (8., 6.)
# CONSTRUCTOR --------------------------------------------------------
def __init__(self, *args, **kwargs):
# parent constructor
MyFig.__init__(self, *args, **kwargs)
self.keywords.update({'xRange': D_XRANGE,
'yRange': D_YRANGE})
ratio = 6. / 8. # height/width of the axes (in inch)
frame = [0.0, 0.0, 1.0, 1.0] # part of the fig that is available
self.add_axes(AxTest1(self, ratio, frame, *args, **kwargs))
...@@ -29,10 +29,10 @@ ...@@ -29,10 +29,10 @@
# #
# #
# IMPORT --------------------------------------------------------------- # IMPORT ---------------------------------------------------------------
from . import DBUG from .. import DBUG
from . import D_IPATH from .. import D_IPATH
from . import MyData from .. import MyData
from . import G_RAWDATAS from .. import G_RAWDATAS
# READ STUPID DATA ----------------------------------------------------- # READ STUPID DATA -----------------------------------------------------
......
from . import os from .. import os
from . import D_OFORMAT, D_OPATH from .. import D_OFORMAT, D_OPATH
from . import readStupidData, readStupidData2 from .. import MyFig, MyWin
from . import MyFig, MyWin from .. import SEVR, WARN, DBUG, SPCE
from . import SEVR, WARN, DBUG, SPCE from .. import _G_WINDOWS
from . import _G_WINDOWS
from . import readStupidData, readStupidData2
# TESTER # TESTER
def myTest(function, expected, failed, debug): def myTest(function, expected, failed, debug):
......
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