<s> from PyQt4 import QtCore , QtGui <EOL> from core . modules . vistrails_module import Module , ModuleError , NotCacheable <EOL> from core . modules . basic_modules import Constant <EOL> from packages . spreadsheet . spreadsheet_controller import spreadsheetController <EOL> from packages . spreadsheet . spreadsheet_cell import QCellWidget , QCellToolBar <EOL> from packages . spreadsheet . basic_widgets import SpreadsheetCell , CellLocation <EOL> from packages . spreadsheet . spreadsheet_event import DisplayCellEvent <EOL> import vcs <EOL> import genutil <EOL> import cdutil <EOL> import time <EOL> import api <EOL> import re <EOL> import MV2 <EOL> """<STR_LIT>""" <EOL> windowIndex = <NUM_LIT:1> <EOL> class Variable ( Module ) : <EOL> """<STR_LIT>""" <EOL> def compute ( self ) : <EOL> if not self . has_input ( '<STR_LIT>' ) : <EOL> raise ModuleError ( self , "<STR_LIT>" ) <EOL> if not self . has_input ( '<STR_LIT:id>' ) : <EOL> raise ModuleError ( self , "<STR_LIT>" ) <EOL> cdmsfile = self . get_input ( '<STR_LIT>' ) <EOL> id = self . get_input ( '<STR_LIT:id>' ) <EOL> axes = self . force_get_input ( '<STR_LIT>' ) <EOL> axesOperations = self . force_get_input ( '<STR_LIT>' ) <EOL> varType = self . getVarType ( id , cdmsfile ) <EOL> if ( varType == '<STR_LIT>' ) : <EOL> var = cdmsfile . __call__ ( id ) <EOL> elif ( varType == '<STR_LIT>' ) : <EOL> varID = self . getAxisID ( id ) <EOL> axis = getattr ( cdmsfile , '<STR_LIT>' ) [ varID ] <EOL> var = MV2 . array ( axis ) <EOL> var . setAxis ( <NUM_LIT:0> , axis ) <EOL> elif ( varType == '<STR_LIT>' ) : <EOL> varID , axisID = self . getVarAndAxisID ( id ) <EOL> var = cdmsfile . __call__ ( varID ) <EOL> var = genutil . getAxisWeightByName ( var , axisID ) <EOL> var . id = varID + '<STR_LIT:_>' + axisID + '<STR_LIT>' <EOL> else : <EOL> var = None <EOL> if axes is not None and var is not None : <EOL> try : <EOL> kwargs = eval ( axes ) <EOL> var = var ( ** kwargs ) <EOL> except : <EOL> raise ModuleError ( self , "<STR_LIT>" , axes ) <EOL> if axesOperations is not None : <EOL> var = self . applyAxesOperations ( var , axesOperations ) <EOL> self . set_output ( '<STR_LIT>' , var ) <EOL> def applyAxesOperations ( self , var , axesOperations ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> axesOperations = eval ( axesOperations ) <EOL> except : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> for axis in list ( axesOperations ) : <EOL> if axesOperations [ axis ] == '<STR_LIT>' : <EOL> var = cdutil . averager ( var , axis = "<STR_LIT>" % axis , weight = '<STR_LIT>' , <EOL> action = '<STR_LIT>' ) <EOL> elif axesOperations [ axis ] == '<STR_LIT>' : <EOL> var = cdutil . averager ( var , axis = "<STR_LIT>" % axis , weight = '<STR_LIT>' ) <EOL> elif axesOperations [ axis ] == '<STR_LIT>' : <EOL> var = cdutil . averager ( var , axis = "<STR_LIT>" % axis ) <EOL> elif axesOperations [ axis ] == '<STR_LIT>' : <EOL> var = genutil . statistics . geometricmean ( var , axis = "<STR_LIT>" % axis ) <EOL> elif axesOperations [ axis ] == '<STR_LIT>' : <EOL> var = genutil . statistics . std ( var , axis = "<STR_LIT>" % axis ) <EOL> return var <EOL> def getVarType ( self , varID , file ) : <EOL> if varID in list ( getattr ( file , '<STR_LIT>' ) ) : <EOL> return '<STR_LIT>' <EOL> elif varID in list ( getattr ( file , '<STR_LIT>' ) ) : <EOL> return '<STR_LIT>' <EOL> elif re . compile ( '<STR_LIT>' ) . match ( varID ) : <EOL> return '<STR_LIT>' <EOL> elif re . compile ( '<STR_LIT>' ) . match ( varID ) : <EOL> return '<STR_LIT>' <EOL> def getVarAndAxisID ( self , varID ) : <EOL> """<STR_LIT>""" <EOL> match = re . compile ( '<STR_LIT>' ) . match ( varID ) <EOL> if match : <EOL> return ( match . group ( <NUM_LIT:1> ) , match . group ( <NUM_LIT:3> ) ) <EOL> return None <EOL> def getAxisID ( self , varID ) : <EOL> """<STR_LIT>""" <EOL> match = re . compile ( '<STR_LIT>' ) . match ( varID ) <EOL> if match : <EOL> return match . group ( <NUM_LIT:3> ) <EOL> return varID <EOL> class Quickplot ( Variable ) : <EOL> """<STR_LIT>""" <EOL> def foo ( self ) : <EOL> return <EOL> class GraphicsMethod ( Module , NotCacheable ) : <EOL> """<STR_LIT>""" <EOL> def compute ( self ) : <EOL> if not self . has_input ( '<STR_LIT>' ) : <EOL> return <EOL> if not self . has_input ( '<STR_LIT>' ) : <EOL> return <EOL> if not self . has_input ( '<STR_LIT>' ) : <EOL> return <EOL> gmName = self . get_input ( '<STR_LIT>' ) <EOL> plotType = self . get_input ( '<STR_LIT>' ) <EOL> slab1 = self . get_input ( '<STR_LIT>' ) <EOL> if self . has_input ( '<STR_LIT>' ) : <EOL> self . set_output ( '<STR_LIT>' , self . get_input ( '<STR_LIT>' ) ) <EOL> canvas = vcs . init ( ) <EOL> gm = canvas . get_gm ( plotType . lower ( ) , gmName ) <EOL> if self . has_input ( '<STR_LIT>' ) : <EOL> gm . color_1 = self . get_input ( '<STR_LIT>' ) <EOL> if self . has_input ( '<STR_LIT>' ) : <EOL> gm . color_2 = self . get_input ( '<STR_LIT>' ) <EOL> if self . has_input ( '<STR_LIT>' ) : <EOL> gm . level_1 = self . get_input ( '<STR_LIT>' ) <EOL> if self . has_input ( '<STR_LIT>' ) : <EOL> gm . level_2 = self . get_input ( '<STR_LIT>' ) <EOL> self . set_output ( '<STR_LIT>' , slab1 ) <EOL> self . set_output ( '<STR_LIT>' , canvas ) <EOL> class CDATCell ( SpreadsheetCell , NotCacheable ) : <EOL> def __init__ ( self ) : <EOL> SpreadsheetCell . __init__ ( self ) <EOL> self . cellWidget = None <EOL> def compute ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . has_input ( '<STR_LIT>' ) : <EOL> canvas = self . get_input ( '<STR_LIT>' ) <EOL> else : <EOL> self . cellWidget = self . displayAndWait ( QCDATWidget , ( None , ) ) <EOL> self . set_output ( '<STR_LIT>' , self . cellWidget . canvas ) <EOL> return <EOL> self . set_output ( '<STR_LIT>' , canvas ) <EOL> if not self . has_input ( '<STR_LIT>' ) : <EOL> return <EOL> if not self . has_input ( '<STR_LIT>' ) : <EOL> return <EOL> if not self . has_input ( '<STR_LIT>' ) : <EOL> return <EOL> if not self . has_input ( '<STR_LIT>' ) : <EOL> return <EOL> args = [ ] <EOL> slab1 = self . get_input ( '<STR_LIT>' ) <EOL> args . append ( self . get_input ( '<STR_LIT>' ) ) <EOL> if self . has_input ( '<STR_LIT>' ) : <EOL> args . append ( self . get_input ( '<STR_LIT>' ) ) <EOL> args . append ( self . get_input ( '<STR_LIT>' ) ) <EOL> args . append ( self . get_input ( '<STR_LIT>' ) ) <EOL> args . append ( self . get_input ( '<STR_LIT>' ) ) <EOL> kwargs = { } <EOL> if self . has_input ( '<STR_LIT>' ) : <EOL> kwargs [ '<STR_LIT>' ] = self . get_input ( '<STR_LIT>' ) <EOL> self . location = CellLocation ( ) <EOL> if self . has_input ( '<STR_LIT>' ) : <EOL> self . location . row = self . get_input ( '<STR_LIT>' ) <EOL> if self . has_input ( '<STR_LIT>' ) : <EOL> self . location . col = self . get_input ( '<STR_LIT>' ) <EOL> inputPorts = ( canvas , args , kwargs ) <EOL> self . displayAndWait ( QCDATWidget , inputPorts ) <EOL> class QCDATWidget ( QCellWidget ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , parent = None ) : <EOL> QCellWidget . __init__ ( self , parent ) <EOL> self . window = None <EOL> self . canvas = None <EOL> self . windowIndex = self . getWindowIndex ( ) <EOL> def getWindowIndex ( self ) : <EOL> """<STR_LIT>""" <EOL> global windowIndex <EOL> windowIndex += <NUM_LIT:1> <EOL> maxWindows = <NUM_LIT:8> <EOL> if windowIndex > maxWindows : <EOL> windowIndex = <NUM_LIT:1> <EOL> return windowIndex <EOL> def updateContents ( self , inputPorts ) : <EOL> """<STR_LIT>""" <EOL> spreadsheetWindow = spreadsheetController . findSpreadsheetWindow ( ) <EOL> spreadsheetWindow . setUpdatesEnabled ( False ) <EOL> self . canvas = inputPorts [ <NUM_LIT:0> ] <EOL> if self . canvas is None : <EOL> self . canvas = vcs . init ( ) <EOL> self . canvas . clear ( ) <EOL> self . window = VCSQtManager . window ( self . windowIndex ) <EOL> layout = QtGui . QVBoxLayout ( ) <EOL> layout . addWidget ( self . window ) <EOL> self . setLayout ( layout ) <EOL> if len ( inputPorts ) > <NUM_LIT:2> : <EOL> args = inputPorts [ <NUM_LIT:1> ] <EOL> kwargs = inputPorts [ <NUM_LIT:2> ] <EOL> self . canvas . plot ( * args , ** kwargs ) <EOL> spreadsheetWindow . setUpdatesEnabled ( True ) <EOL> def deleteLater ( self ) : <EOL> """<STR_LIT>""" <EOL> self . canvas = None <EOL> QCellWidget . deleteLater ( self ) </s>
