Commit 5962c7f5 authored by Yori 'AGy' Fournier's avatar Yori 'AGy' Fournier
Browse files

Now I can import myplotlib as server

But not yet MyAxes and MyFig because need the server version
parent 946c3c02
......@@ -34,72 +34,98 @@
#
# IMPORT ---------------------------------------------------------------
from .config import INFO, WARN, SEVR, DBUG, SPCE
from .config import D_HIERARCHY
import os as os
import numpy as np
# Test mpl version:
from matplotlib import __version__ as mplvers
# matplotlib import for client/local -----------------------------------
if D_HIERARCHY in ('CLIENT', 'client', 'LOCAL', 'local'):
if int(mplvers.replace('.','')[:3]) < 143 :
print('\n\n' + WARN + 72*'=' + '\n' + SPCE + 'The matplotlib version you are using is not supported.\n' + SPCE + 'Most of myplotlib should work, but some stuff may not.\n' + SPCE + 'ex: expect an error with test203\n' + SPCE + 72*'=' + '\n\n')
if D_HIERARCHY in ('CLIENT', 'client'):
print(INFO+'Import myplotlib as a client.')
else:
print(INFO+'Import myplotlib for local use.')
# Test mpl version:
from matplotlib import __version__ as mplvers
# matplotlib
from matplotlib.pyplot import figure
from matplotlib.pyplot import rc
from matplotlib.pyplot import show, draw, ion, ioff, clf
from matplotlib.pyplot import close as mpclose
from matplotlib.pyplot import fignum_exists, savefig
from matplotlib.axes import Axes
from matplotlib.figure import Figure
from matplotlib import is_interactive
#from matplotlib import rcParams
from matplotlib import use
if int(mplvers.replace('.','')[:3]) < 143 :
print('\n\n' + WARN + 72*'=' + '\n' + SPCE + 'The matplotlib version you are using is not supported.\n' + SPCE + 'Most of myplotlib should work, but some stuff may not.\n' + SPCE + 'ex: expect an error with test203\n' + SPCE + 72*'=' + '\n\n')
# matplotlib
from matplotlib.pyplot import figure
from matplotlib.pyplot import rc
from matplotlib.pyplot import show, draw, ion, ioff, clf
from matplotlib.pyplot import close as mpclose
from matplotlib.pyplot import fignum_exists, savefig
from matplotlib.axes import Axes
from matplotlib.figure import Figure
from matplotlib import is_interactive
from matplotlib import use
elif D_HIERARCHY in ('SERVER', 'server'):
print(INFO+'Import myplotlib as a server.')
else:
print(SEVR+'the value of D_HIERARCHY has to be SERVER or CLIENT')
raise ImportError
# myplotlib
from .myData import MyData
# GLOBAL VARIABLE ------------------------------------------------------
G_RAWDATAS = {'current': MyData()} # raw data Object
_G_WINDOWS = []
# CONFIGURATION --------------------------------------------------------
from .config import D_FIGNUM, D_FIGSIZE, D_REFORMAT, D_FORMATTED
from .config import D_RAWDATA, D_INPUTARG
from .config import D_IPATH
from .config import D_OPATH, D_OFORMAT
from .config import D_DEBUG
from .config import rcParams
if D_HIERARCHY in ('CLIENT', 'client', 'LOCAL', 'local'):
from .rconfig import rcParams
# BACKEND: u'TKAgg', u'GTKAgg', u'WXAgg', u'Qt4Agg', u'MacOSX'
rcParams['backend'] = u'GTKAgg'
# FUNCTIONS ------------------------------------------------------------
# MyAxes: Overlay on matplotlib.Axes class
from .myAxes import MyAxes
#from .myAxes import MyAxes
# MyFig: Overlay on matplotlib.Figure class
from .myFig import MyFig
# MyFig: Overlay on matplotlib.FigureManager class
if rcParams['backend'] == u'TkAgg':
from .myWin_TkAgg import MyWin_TkAgg as MyWin
elif rcParams['backend'] == u'GTKAgg':
from .myWin_GTKAgg import MyWin_GTKAgg as MyWin
elif rcParams['backend'] == u'WXAgg':
from .myWin_WXAgg import MyWin_WXAgg as MyWin
elif rcParams['backend'] == u'Qt4Agg':
from .myWin_Qt4Agg import MyWin_Qt4Agg as MyWin
elif rcParams['backend'] == u'MacOSX':
from .myWin_MacOSx import MyWin_MacOSx as MyWin
else:
print(SEVR + "The backend you choosed is not supported interactive mode not available")
#from .myFig import MyFig
if D_HIERARCHY in ('CLIENT', 'client', 'LOCAL', 'local'):
_G_WINDOWS = []
# MyWin: Overlay on matplotlib.FigureManager class
if rcParams['backend'] == u'TkAgg':
from .myWin_TkAgg import MyWin_TkAgg as MyWin
elif rcParams['backend'] == u'GTKAgg':
from .myWin_GTKAgg import MyWin_GTKAgg as MyWin
elif rcParams['backend'] == u'WXAgg':
from .myWin_WXAgg import MyWin_WXAgg as MyWin
elif rcParams['backend'] == u'Qt4Agg':
from .myWin_Qt4Agg import MyWin_Qt4Agg as MyWin
elif rcParams['backend'] == u'MacOSX':
from .myWin_MacOSx import MyWin_MacOSx as MyWin
else:
print(SEVR + "The backend you choosed is not supported interactive mode not available")
# myTool.*: interface functions to use myplotlib interactively
from .mytool import window_exists, getCurrentWindowIDs
from .mytool import print2file, print2screen, printListCurrentWindows
from .mytool import getWindow, getFigOnWindow, drawFigOnWindow, giveDataToWindow
from .mytool import closeWindow, closeAllWindows
from .mytool import FigOneAxes
#from .mytool import print2file # need to make tools for server ?? or just put them in client/local
#from .mytool import FigOneAxes
if D_HIERARCHY in ('CLIENT', 'client', 'LOCAL', 'local'):
from .mytool import window_exists, getCurrentWindowIDs
from .mytool import print2file, print2screen, printListCurrentWindows
from .mytool import getWindow, getFigOnWindow, drawFigOnWindow, giveDataToWindow
from .mytool import closeWindow, closeAllWindows
from .test import myTest
# TESTS ----------------------------------------------------------------
# import the tests
from .test import testList
if D_HIERARCHY in ('CLIENT', 'client', 'LOCAL', 'local'):
from .test import myTest
from .test import testList
......@@ -19,7 +19,6 @@
# @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.
......@@ -72,7 +71,6 @@ from . import os
from . import D_FIGSIZE, D_INPUTARG, D_DEBUG, D_REFORMAT, D_FORMATTED
from . import D_OFORMAT, D_OPATH
from . import DBUG, SEVR, INFO, SPCE, WARN
from . import G_RAWDATAS
from . import MyData
from . import MyAxes
from . import Figure
......
......@@ -6,7 +6,6 @@ from .myTool import getFigOnWindow
from .myTool import getWindow
from .myTool import printListCurrentWindows
from .myTool import window_exists
from .myTool import setCurrentData
from .myTool import giveDataToWindow
from .myTool import drawFigOnWindow
from .myTool import closeAllWindows
......
......@@ -15,12 +15,6 @@
#
# @functions
#
# - setCurrentData: This tool is meant for interactive work,
# it set the given data identifier as being
# the current one such that it can be called
# with its identifier and the default
# one: G_RAWDATA['current'].
#
# - print2file: This function is meant to be used in script
# mode of myplotlib, more than in interactive mode,
# eventhough it can be used in both. It will save
......@@ -35,7 +29,7 @@
#
# IMPORT ---------------------------------------------------------------
from .. import D_OPATH, D_OFORMAT
from .. import G_RAWDATAS, _G_WINDOWS
from .. import _G_WINDOWS
from .. import INFO, SEVR, WARN, SPCE
from .. import ion, ioff, is_interactive
......@@ -229,20 +223,6 @@ AVAILABLE FUNCTIONS:
return(True)
# TOOL FUNCTION FOR READING EXISTING DATA ------------------------------
def setCurrentData(name):
# RQ: grawdatas is a global variable
try:
G_RAWDATAS['current'] = G_RAWDATAS[name]
except KeyError:
print(SEVR + 'The data does not exist. --> EXIT')
return(False)
return(True)
# PRINT TO SCREEN ------------------------------------------------------
def print2screen(ClassName, inputArg, *args, **kwargs):
......
from matplotlib import rcParams
# FONT
rcParams['font.family'] = 'serif'
rcParams['font.size'] = '22'
try:
rcParams['text.usetex'] = True # need dvipng, ghostscript, and Agg
except:
print(WARN + "I couls not set the LaTeX font sorry...")
# LINES
rcParams['lines.linewidth'] = 1.5
rcParams['lines.markersize'] = 6
# AXES
rcParams['axes.linewidth'] = 1.5
# TICKS
rcParams['xtick.major.pad'] = 10.
rcParams['xtick.major.size'] = 10.
rcParams['ytick.major.pad'] = 8.
rcParams['ytick.major.size'] = 10.
rcParams['xtick.minor.size'] = 5.
rcParams['ytick.minor.size'] = 5.
# Not compatible with old version of matplotlib
try:
rcParams['xtick.major.width'] = 1.5
rcParams['ytick.major.width'] = 1.5
rcParams['xtick.minor.width'] = 1.5
rcParams['ytick.minor.width'] = 1.5
rcParams['xtick.minor.visible'] = False
rcParams['ytick.minor.visible'] = False
except:
pass
# DPI
rcParams['figure.dpi'] = 75.0
......@@ -32,7 +32,6 @@
from .. import DBUG
from .. import D_IPATH
from .. import MyData
from .. import G_RAWDATAS
# READ STUPID DATA -----------------------------------------------------
......@@ -43,12 +42,9 @@ def readStupidData(ipath=D_IPATH, *args, **kwargs):
lrawdata = MyData()
lrawdata.name = str(ipath)
lrawdata.data = [-1., 1., 1, -1.]
G_RAWDATAS.update({lrawdata.name: lrawdata})
G_RAWDATAS['current'] = lrawdata
if(debug):
print(DBUG + 'I read the raw data with readStupidData')
print(DBUG + str(G_RAWDATAS['current'].name))
return(lrawdata)
......@@ -61,12 +57,9 @@ def readStupidData2(ipath=D_IPATH, *args, **kwargs):
lrawdata = MyData()
lrawdata.name = str(ipath)
lrawdata.data = [-1., 1., -2., 2.]
G_RAWDATAS.update({lrawdata.name: lrawdata})
G_RAWDATAS['current'] = lrawdata
if(debug):
print(DBUG + 'I read the raw data with readStupidData2')
print(DBUG + str(G_RAWDATAS['current'].name))
return(lrawdata)
......@@ -3,7 +3,7 @@ from .. import D_OFORMAT, D_OPATH
from .. import rcParams
from .. import MyData, MyAxes, MyFig, MyWin
from .. import SEVR, WARN, DBUG, SPCE
from .. import G_RAWDATAS, _G_WINDOWS
from .. import _G_WINDOWS
from . import readStupidData, readStupidData2
from . import FigTest1,FigTest2, AxTest1
......@@ -165,21 +165,20 @@ def test200(debug):
# TEST 2.01: Testing the function formatRawData
def test201(debug):
# add some empty data in G_RAWDATAS
G_RAWDATAS.update({'data': MyData()})
mydata = MyData()
# create the environment
fig = FigTest1((G_RAWDATAS['data'],))
fig = FigTest1((mydata,))
# create the axis
ax = AxTest1(fig, 6. / 8., [0, 0, 1, 1])
# Set the data (emulate some myIO function)
G_RAWDATAS['data'].data = [-1, 1, 1, -1]
mydata.data = [-1, 1, 1, -1]
# formatRawData
ax.formatRawData(G_RAWDATAS['data'])
ax.formatRawData(mydata)
# test if results compatible with inputs.
if(ax.data['xdata'] == [-1, 1] and ax.data['ydata'] == [1, -1]):
......@@ -194,8 +193,8 @@ def test201(debug):
def test202(debug):
# create the environment
G_RAWDATAS.update({'data': MyData()})
fig = FigTest1((G_RAWDATAS['data'],))
mydata = MyData()
fig = FigTest1((mydata,))
# create the axis
ax = AxTest1(fig, 6. / 8., [0, 0, 1, 1])
......@@ -473,11 +472,11 @@ def test308(debug):
print(DBUG + "test without data: " + str(status))
fig.debug = debug
mydata = MyData()
mydata.data = [1, -1, -1, 1]
G_RAWDATAS.update({'data': MyData()})
G_RAWDATAS['data'].data = [1, -1, -1, 1]
fig.update(rawdata=(G_RAWDATAS['data'],))
fig.update(rawdata=(mydata,))
fig.plot()
if len(fig.get_axes()) > 0:
......
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