#!/usr/bin/python # -*- coding: utf-8 -*- # # ================= FILE HEADER ======================================== # # myplotlib v0.0.0, # # @file myTool.py # @author Yori 'AGy' Fournier # @licence CC-BY-SA # # MyTool is a tool box for interactive usage. It allows the user # for a simple usage of its own Figure-like class. The functions # here are meant for interactive data analyse and consistent plotting. # # @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 # the plot within a file. # # @section History # # v 0.0.0 - minimal toolBox for myplotlib, with myfig, setCurrentData, # screen, print2file functions # # ====================================================================== # # IMPORT --------------------------------------------------------------- from . import D_OPATH, D_OFORMAT from . import G_RAWDATAS, _G_WINDOWS from . import INFO, SEVR, WARN, SPCE from . import ion, ioff, is_interactive from . import MyWin from . import np # 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): try: fig = ClassName(inputarg=inputArg, *args, **kwargs) except: print(SEVR + 'The type of figure you gave does not exists.') return(False) try: MyWin(fig, *args, **kwargs) except: print(SEVR + "I couldn't draw the figure on a window... did you test the lib?") return(False) return(True) def printListCurrentWindows(): for window in _G_WINDOWS: if window == _G_WINDOWS[0]: print(INFO + "Figure " + window.num) else: print(SPCE + "Figure " + window.num) def getWindow(ID): for window in _G_WINDOWS: if window.num == ID: return(window) print(WARN + "The window does not exist.") return(False) def getFigOnWindow(ID): for window in _G_WINDOWS: if window.num == ID: return(window.canvas.figure) print(WARN + "The window does not exist.") return(False) def drawFigOnWindow(fig, ID): return(MyWin(fig, fignum=ID)) def giveDataToWindow(data, ID): fig = getFigOnWindow(ID) fig.update(inputarg = data) win = getWindow(ID) win.refresh() return(True) def closeWindow(ID): for window in _G_WINDOWS: if window.num == ID: return(window.close()) def closeAllWindows(): # a for-loop won't work because close() acts on _G_WINDOWS # for window in _G_WINDOWS: while(len(_G_WINDOWS) > 0): window = _G_WINDOWS[0] print(INFO + "window :" + str(window.num)) window.close() if(len(_G_WINDOWS) == 0): return(True) else: return(False) # PRINT TO FILE -------------------------------------------------------- def print2file(ClassName, inputArg, filename, *args, **kwargs): try: fig = ClassName(inputarg=inputArg, *args, **kwargs) except: print(SEVR + 'The type of figure you gave does not exists.') return(False) fig.print2file(filename, *args, **kwargs) # end return(True)