Commit b807b619 authored by Yori 'AGy' Fournier's avatar Yori 'AGy' Fournier
Browse files

this version is clean. no more bugs and should allow full potential. The...

this version is clean. no more bugs and should allow full potential. The remaining problem is that it is not object oriented. should not be a big deal.
parent 3c5f7a59
......@@ -47,6 +47,9 @@ from matplotlib.figure import Figure
from matplotlib import is_interactive
from matplotlib import rcParams
# For interactive usage (require GTKAgg !) NOT YET COMPATIBLE WITH OTHER BACKENDS
from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvas
# myplotlib
from myData import MyData
......@@ -91,6 +94,7 @@ rc('xtick.major', width=1.5, pad=10., size=10.)
rc('ytick.major', width=1.5, pad=8., size=10.)
rc('xtick.minor', width=1.5, size=5.)
rc('ytick.minor', width=1.5, size=5.)
rc('figure', dpi = 75.0)
# FUNCTIONS ------------------------------------------------------------
# MyAxes: Overlay on matplotlib.Axes class
......@@ -103,7 +107,7 @@ from myIOs import readStupidData, readStupidData2
from myFig import MyFig
# myTool.*: interface functions to use myplotlib interactively
from myTool import createWindow, refreshWindow, closeWindow
from myTool import createWindow, refreshWindow, closeWindow, updateFig
from myTool import print2file
# MyFig4Test: Overlay of Figure for testing
......
......@@ -54,7 +54,7 @@ from myplotlib import D_FIGSIZE, D_INPUTARG, D_DEBUG, D_REFORMAT, D_FIGNUM, D_FO
from myplotlib import DBUG, SEVR, INFO, SPCE, WARN
from myplotlib import G_RAWDATAS
from myplotlib import Figure, MyAxes
from myplotlib import Figure, FigureCanvas, MyAxes
# Class MyFig Overwriting Matplotlib.fure.Figure
......@@ -87,6 +87,11 @@ class MyFig(Figure):
# parent constructor
Figure.__init__(self, *args, **kwargs)
# create the canvas (interface between window and figure)
# FigureCanvas(self) # This set figure.canvas properly for window usage (it does not work...)
self.boundedToWin = False
# DEBUG --------------------------------------------------------------
def printDebug(self):
......
......@@ -67,17 +67,74 @@ def refreshWindow(window):
window.canvas.figure.clf()
window.canvas.figure.plot()
window.canvas.draw()
# window.canvas.draw()
window.canvas.figure.canvas.draw()
return(True)
# create windows without testing... be careful using that may lead to memory leakage
def _createWindow_(fig, *args, **kwargs):
# interactive off
if is_interactive():
ioff()
# Check the figure number (same as window number)
fignum = kwargs.get('fignum', 0)
from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvas
from matplotlib.backends.backend_gtkagg import FigureManagerGTKAgg as FigureManager
# ADD Window in the Managers List
print(INFO + "I add the window in G_MANAGERS.")
G_MANAGERS.append(FigureManager(FigureCanvas(fig), fignum))
# G_MANAGERS.append(FigureManager(fig.canvas, fignum))
if fig.dpi != 75:
fig.dpi = 75
fig.boundedToWin = True
fig.keywords['fignum'] = fignum
fig.clf()
fig.plot()
G_MANAGERS[-1].canvas.draw()
G_MANAGERS[-1].show()
win = G_MANAGERS[-1]
return(win)
def updateFig(win, fig):
# unbound the current fig of the window
win.canvas.figure.boundedToWin = False # unbound the figure to the window
win.canvas.figure.keywords['fignum'] = -1 # setup a non existing fignum to avoid problems.
# fig is already bounded close its former frame
if fig.boundedToWin:
closeWindow(fig.keywords['fignum'])
fig.canvas = win.canvas
win.canvas.figure = fig
fig.boundedToWin = True
fig.keywords['fignum'] = win.num
refreshWindow(win)
return(True)
def createWindow(fig, *args, **kwargs):
# interactive off
if is_interactive():
ioff()
if fig.dpi != 75:
fig.dpi = 75
# Check the figure number (same as window number)
fignum = kwargs.get('fignum', 0)
......@@ -87,36 +144,45 @@ def createWindow(fig, *args, **kwargs):
# Verify in G_MANAGERS if the window exists
for window in G_MANAGERS:
# if it exists just refresh it (ATTENTION NOT YET WITH ACTUALISATION OF FIG)
# if it exists just refresh it
if(window.num == fignum):
print(WARN + "The window already exists, I'll just refresh it")
if fig.dpi != 75:
fig.dpi = 75
refreshWindow(window)
win = window
alreadyExists = True
index = G_MANAGERS.index(window)
# if it does not exists create the window
if not alreadyExists:
from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvas
from matplotlib.backends.backend_gtkagg import FigureManagerGTKAgg as FigureManager
# if window exists warn and refresh
if alreadyExists:
# ADD Window in the Managers List
print(INFO + "I add the window in G_MANAGERS.")
G_MANAGERS.append(FigureManager(FigureCanvas(fig), fignum))
win = G_MANAGERS[index]
if fig.dpi != 75:
fig.dpi = 75
fig.clf()
fig.plot()
G_MANAGERS[-1].canvas.draw()
G_MANAGERS[-1].show()
win = G_MANAGERS[-1]
if(win.canvas.figure == fig):
print(WARN + "The window already exists, I'll just refresh it.")
refreshWindow(win)
else:
print(WARN + "The window already exists, and figure is different, I'll close and recreate it.")
# if fig not yet bounded
if not fig.boundedToWin:
closeWindow(win.num)
win = _createWindow_(fig, *args, **kwargs)
# if fig bounded then close the former frame and switch to new one.
else:
print(WARN + "The figure is already plotted, I'll close and recreate it in the new window.")
# if yes then first close and recreate
print(INFO + str(fig.keywords['fignum']))
closeWindow(fig.keywords['fignum'])
win = _createWindow_(fig, *args, **kwargs)
# if it does not exists
else:
# check if the figure is already bounded to a window
if not fig.boundedToWin:
win = _createWindow_(fig, *args, **kwargs)
else:
print(WARN + "The fihure is already used, I'll close its window and recreate it.")
# if yes then first close and recreate
print(INFO + str(fig.keywords['fignum']))
closeWindow(fig.keywords['fignum'])
win = _createWindow_(fig, *args, **kwargs)
return(win)
......@@ -133,6 +199,8 @@ def closeWindow(num):
status = False
if index is not None:
G_MANAGERS[index].canvas.figure.boundedToWin = False
G_MANAGERS[index].canvas.figure.keywords['fignum'] = -1
G_MANAGERS[index].destroy()
del G_MANAGERS[index]
......
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