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

add comment in myWin and header. correct the header of myFig

parent a9e17f4e
......@@ -3,7 +3,7 @@
#
# ================= FILE HEADER ========================================
#
# myplotlib v0.0.0,
# myplotlib v1.0.1,
#
# @file myFig.py
# @author Yori 'AGy' Fournier
......@@ -19,7 +19,7 @@
# @Constructor
#
# fignum: number of the Figure.
# rawdata: identifier of the raw data in G_RAWDATA.
# inputarg: identifier of the raw data in G_RAWDATA.
# reformat: flag for reComputing plotted data
# from rawData.
# debug: flag for debugging, more verbatile.
......@@ -28,7 +28,7 @@
# @section Functions
#
# - printDebug: print some debug information.
#
#
# - plot: overlay of Figure.plot() function,
# should be overwrited by the user.
# Consists of
......@@ -36,28 +36,46 @@
# - formating the data,
# - adding the axis to the figure
# - plotting the axis
#
# - update: This is done to update the figure
# in case of redraw to make sure that
# the attributes are up-to-date.
# Important for interactive work.
#
# - update: update the parameters in the
# keywords dictionary.
#
# @section History
#
# v 0.0.2 - MyFig class for the myplotlib module.
# 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 myplotlib import D_FIGSIZE, D_INPUTARG, D_DEBUG, D_REFORMAT, D_FIGNUM, D_FORMATTED
# Default values
from myplotlib import D_FIGSIZE, D_INPUTARG, D_DEBUG, D_REFORMAT, D_FORMATTED
# Forms
from myplotlib import DBUG, SEVR, INFO, SPCE, WARN
# Global variables
from myplotlib import G_RAWDATAS
# Classes
from myplotlib import Figure, FigureCanvas, MyAxes
# Class MyFig Overwriting Matplotlib.fure.Figure
# Class MyFig Overwriting Matplotlib.figure.Figure
class MyFig(Figure):
# Set the size of the Figure in inch
......@@ -67,29 +85,30 @@ class MyFig(Figure):
# CONSTRUCTOR --------------------------------------------------------
def __init__(self, *args, **kwargs):
self.keywords = {'fignum': D_FIGNUM,
self.keywords = {'fignum': -1, # need to be hard coded for interactive mode
'inputarg': D_INPUTARG,
'reformat': D_REFORMAT,
'debug': D_DEBUG,
'reformatted': D_FORMATTED}
'formatted': D_FORMATTED}
# check keywords
for keyword in self.keywords.keys():
# if already in kwargs
# if already in kwargs
if keyword in kwargs.keys():
# overwrite default value
self.keywords[keyword] = kwargs[keyword]
# suppress keyword from kwargs for Figure.__init__
del kwargs[keyword]
# inputarg, reformat, debug, fignum
# add figsize in the kwargs for Figure.__init__
kwargs['figsize'] = self.FIGSIZE
# 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...)
# This is required for the interactive mode
# it ensures that a figure can not be bounded
# to several windows and prevent the loss of canvas.
self.boundedToWin = False
......
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# ================= FILE HEADER ========================================
#
# myplotlib v1.0.1,
#
# @file myWin.py
# @author Yori 'AGy' Fournier
# @licence CC-BY-SA
#
# MyWin class: Overlay of matplotlib FigureManager
# class. It allows a cleaner and more confortable
# usage of windows.
#
# @Class MyWin
#
# @Constructor
#
# fig: the MyFig object that need to be drawn
# show: a flag to show the window just after
# creation. (default: True)
# fignum: number of both the Window and the Figure.
# debug: flag for debugging, more verbatile.
# (kw)args: user defined arguments and keywords.
#
# @section Functions
#
# @section History
#
# v 1.0.1 - MyWin class for the myplotlib module.
#
# ======================================================================
#
# IMPORT ---------------------------------------------------------------
# Forms
from myplotlib import INFO, SEVR, WARN, DBUG, SPCE
# Classes
from myplotlib import FigureManager, FigureCanvas
# Global variables
from myplotlib import _G_WINDOWS
from myplotlib import np
# Module
from myplotlib.np import where
# Class MyWin Overwriting the disgusting Matplotlib.FigureManager class
class MyWin(FigureManager):
# CONSTRUCTOR ------------------------------------------------------
def __init__(self, fig, show=True, *args, **kwargs):
# set the dpi to 75 (correct value for screen)
if(fig.dpi != 75.):
fig.dpi = 75.
num = kwargs.get('fignum', 0)
# Get the user specified ID of the window of setit to -1
num = kwargs.get('fignum', -1)
# Get the debug value
debug = kwargs.get('debug', False)
# before creating anything verify that the fig is not already
# bounded to another window
if fig.boundedToWin:
win = _G_WINDOWS[np.where([(window.num == fig.keywords['fignum']) for window in _G_WINDOWS])[0][0]]
# if it is the case close the bounded window.
win = _G_WINDOWS[where([(window.num == fig.keywords['fignum']) for window in _G_WINDOWS])[0][0]]
win.close()
# Call the ugly FigureManager class
# (already wondering if this is not a mistake...)
FigureManager.__init__(self, FigureCanvas(fig), num)
# bound the figure to the window
self.canvas.figure.boundedToWin = True
self.canvas.figure.keywords['fignum'] = num
# add the window in the global variable _G_WINDOWS
# this guarenty that you never loose a window
# (see myTool.py getWindow(num))
_G_WINDOWS.append(self)
# if show is on, then show the window
if show:
self.refresh()
self.show()
# BOUND ------------------------------------------------------------
def _boundFigure_(self, fig):
fig.canvas = self.canvas
......@@ -35,35 +93,59 @@ class MyWin(FigureManager):
self.canvas.figure.boundedToWin = True
self.canvas.figure.keywords['fignum'] = self.num
# UNBOUND ----------------------------------------------------------
def _unboundFigure_(self):
self.canvas.figure.boundedToWin = False
self.canvas.figure.keywords['fignum'] = -1
# SETTERS ----------------------------------------------------------
# SET FIGURE -------------------------------------------------------
def set_figure(self, fig):
# first unbound the former figure
self._unboundFigure_()
# if the new figure is already bounded close
# its former container.
if fig.boundedToWin:
win = _G_WINDOWS[np.where([(window.num == fig.keywords['fignum']) for window in _G_WINDOWS])[0][0]]
win = _G_WINDOWS[where([(window.num == fig.keywords['fignum']) for window in _G_WINDOWS])[0][0]]
win.close()
# bound the new figure
self._boundFigure_(fig)
# REFRESH ----------------------------------------------------------
def refresh(self):
self.canvas.figure.clf()
self.canvas.figure.plot()
self.canvas.draw()
# DRAW -------------------------------------------------------------
def drawFigure(self, fig):
# if the figure is not the current one
if(fig.keywords['fignum'] != self.num):
# cleanly set the new figure
self.set_figure(fig)
# and refresh
self.refresh()
# CLOSE ------------------------------------------------------------
def close(self):
self._unboundFigure_()
self.destroy()
del _G_WINDOWS[np.where([(window == self) for window in _G_WINDOWS])[0][0]]
del _G_WINDOWS[where([(window == self) for window in _G_WINDOWS])[0][0]]
# remark if you create the window like:
# win = MyWin(fig)
# then win is still refering the self
# and therefore not yet freed
# del win would free it entirely.
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