Package Pmv :: Module colorCommands :: Class ColorByExpression
[hide private]
[frames] | no frames]

Class ColorByExpression

source code

ViewerFramework.VFCommand.Command --+            
                                    |            
                  mvCommand.MVCommand --+        
                                        |        
                             ColorCommand --+    
                                            |    
                            ColorByProperties --+
                                                |
                                               ColorByExpression

The colorByExpression command allows the user to color the given geometries representing the given nodes evaluated by  python function or lambda function.
    
Package : Pmv
    
Module  : colorCommands
    
Class   : ColorByInstance
    
Command : colorByInstance
    
Synopsis:

     None <- colorByExpression(nodes, geomsToColor, function,lambdaFunc, ramp=None, min=None, max=Non)
        
nodes --- TreeNodeSet holding the current selection
        
geomsToColor --- the list of the name geometries to be colored
        
function --- python function or lambda function that will be evaluated with the given nodes
        
lambdaFunc --- flag specifying if the given function is a lambda function or a regular function
        
colormap ---  can either be a string which is the name of a loaded colormap or a DejaVu.colorMap.ColorMap instance.
  



Instance Methods [hide private]
  __init__(self, func=None)
  onAddCmdToViewer(self)
method called when an instance of this command is added to the viewer.
  loadCM_cb(self, event=None)
Callback to load a new color map file.
  updateCM(self, event=None)
  updateMiniMaxi(self, cmName, event=None)
  buildFormDescr(self, formName)
descr <- buildFormDescr(self, formName): this virtual method is implemented in the classes derived from Command.
  eval_cb(self)
  setupUndoBefore(self, nodes, geomsToColor, function='lambda x: x._uniqIndex', lambdaFunc=1, colormap='RGBARamp')
This method builds the self.undoCmds string.
  cmGUI_cb(self, geomsToColor, function, lambdaFunc, colormap)
  guiCallback(self)
  __call__(self, nodes, geomsToColor='all', function='lambda x: x._uniqIndex', lambdaFunc=1, colormap='RGBARamp', **kw)
None <- colorByExpression(nodes, geomsToColor, function,lambdaFunc, ramp=None,min=None, max=None, **kw)
  getPropValues(self, nodes, function, lambdaFunc)
  doit(self, nodes, geomsToColor, function='lambda x: x._uniqIndex', lambdaFunc=1, colormap='RGBARamp')
virtual method.

Inherited from ColorByProperties: colorProp, entryValidate, updateChooser, updateLevel_cb, updateValMinMax

Inherited from ColorCommand: addNewEntries, cleanup, color_cb, deselectall_cb, dismiss_cb, getAvailableGeoms, getChildrenGeomsName, getNodes, selectall_cb, showForm, showUndisplayed_cb

Inherited from mvCommand.MVCommand: strArg

Inherited from mvCommand.MVCommand (private): _strArg

Inherited from ViewerFramework.VFCommand.Command: __repr__, addCallbackAfter, addCallbackBefore, addUndoCall, afterDoit, beforeDoit, buildLogArgList, checkDependencies, customizeGUI, doitWrapper, getArguments, getHelp, getLastUsedValues, getLogArgs, getValNamedArgs, log, logString, onAddNewCmd, onCmdRun, setLastUsedValues, setupUndoAfter, tkCb, updateGeom, warningMsg


Class Variables [hide private]
  mapLabel = 'Define a function or a lambda function to be applie...
  mapText = '#This function returns the value of the attribute _...
  funcLabel = 'Define a function to be applied to\nthe current sel...
  funcText = '#def foo(selection):\n#\tvalues = []\n#\t#loop on t...

Inherited from ColorByProperties: levelOrder

Inherited from ViewerFramework.VFCommand.Command: negateKw, objArgOnly


Method Details [hide private]

__init__(self, func=None)
(Constructor)

source code 
None
Overrides: ColorByProperties.__init__

onAddCmdToViewer(self)

source code 
method called when an instance of this command is added to the viewer. This enable viewer-addition time initializations
Overrides: ColorByProperties.onAddCmdToViewer

loadCM_cb(self, event=None)

source code 
Callback to load a new color map file.
Overrides: ColorByProperties.loadCM_cb

updateCM(self, event=None)

source code 
None
Overrides: ColorByProperties.updateCM

updateMiniMaxi(self, cmName, event=None)

source code 
None
Overrides: ColorByProperties.updateMiniMaxi

buildFormDescr(self, formName)

source code 
descr <- buildFormDescr(self, formName): this virtual method is implemented in the classes derived from Command. This is where the inputFormDescr is created and the description of the widgets appended. If a command has several inputForm buildFormDescr should build all the inputFormDescr and you do a if / elif check to know which one to create. formName : string name of the form corresponding to this descr.
Overrides: ColorByProperties.buildFormDescr

eval_cb(self)

source code 
None

setupUndoBefore(self, nodes, geomsToColor, function='lambda x: x._uniqIndex', lambdaFunc=1, colormap='RGBARamp')

source code 
This method builds the self.undoCmds string. This method should have the same signature than the __call__. When this string is executed it should undo the actions of this command. This string will be appended to the undoCmdStack list if the command is successfuly carried out. This method handles only commands with the negateKw. Other commands have to overwrite it.
Overrides: ColorByProperties.setupUndoBefore

cmGUI_cb(self, geomsToColor, function, lambdaFunc, colormap)

source code 
None
Overrides: ColorByProperties.cmGUI_cb

guiCallback(self)

source code 
None
Overrides: ColorByProperties.guiCallback

__call__(self, nodes, geomsToColor='all', function='lambda x: x._uniqIndex', lambdaFunc=1, colormap='RGBARamp', **kw)
(Call operator)

source code 

None <- colorByExpression(nodes, geomsToColor, function,lambdaFunc, ramp=None,min=None, max=None, **kw)

nodes --- TreeNodeSet holding the current selection

geomsToColor --- the list of the name geometries to be colored

function --- python function or lambda function that will be evaluated with the given nodes

lambdaFunc --- flag specifying if the given function is a lambda function or a regular function

colormap --- can either be a string which is the name of a loaded colormap or a DejaVu.colorMap.ColorMap instance.
Overrides: ColorByProperties.__call__

getPropValues(self, nodes, function, lambdaFunc)

source code 
None
Overrides: ColorByProperties.getPropValues

doit(self, nodes, geomsToColor, function='lambda x: x._uniqIndex', lambdaFunc=1, colormap='RGBARamp')

source code 
virtual method. Has to be implemented by the sub classes
Overrides: ColorByProperties.doit

Class Variable Details [hide private]

mapLabel

None
Value:
'''Define a function or a lambda function to be applied
on each node of the current selection: '''                             
      

mapText

None
Value:
'''#This function returns the value of the attribute _charges["gasteig
er"] if
#it exists otherwise returns 0.
#def foo(object):
#\tif hasattr(object, "_charges") and object._charges.has_key("gasteig
er"):
#\t\treturn object._charges["gasteiger"]
#\telse:
...                                                                    
      

funcLabel

None
Value:
'''Define a function to be applied to
the current selection:'''                                              
      

funcText

None
Value:
'''#def foo(selection):
#\tvalues = []
#\t#loop on the current selection
#\tfor i in xrange(len(selection)):
#\t\t#build a list of values to color the current selection.
#\t\tif selection[i].number > 20:
#\t\t\tvalues.append(selection[i].number*2)
#\t\telse:
...