Home | Trees | Indices | Help |
|
---|
|
ViewerFramework.VFCommand.Command --+ | MVCommand
Base class for command objects for a molecule viewer. Base class for command objects for a molecule viewer This command class derives from the ViewerFramework.VFCommand.Command class. Classes derived from that class can be added to a MoleculeViewer using the addCommand method. To write a command the programmer has to create a class MyCmd derived from the MVCommand class and should overwrite the following methods when relevant. Information on how to write an inputForm is also available at http://www.scripps.edu/~sanner/software/python/inputform/tableOfContent.html __init__(self, func=None) The constructor has to be overwritten to set the self.flag attribute properly. self.objArgOnly is turned on when the doit only has one required argument which is the current selection. This will automatically make this command a Picking command self.negateKw is turned on when the doit method takes a boolean flag negate which makes this command undoable. see Pmv.colorCommands.color command class for an example __call__(self, *args, **kw): Entrypoint to the command from the command line. It overloads calling the object (command) as a function, which enables calling an instance of a command as a method of a viewer once it it has been loaded. Typically, this method checks the arguments supplied and calls the doitWrapper method with the arguments supplied. This method needs to have the same signature than the doit. A documentation string supplying the following information will be displayed in a tooltip when calling the command from the python idle shell. This documentation string should provide the synopsis of the command and a description of the arguments. See Pmv.colorCommands.py, Pmv.displayCommands.py for good example of documentation string. guiCallback(self, event=None, *args, **kw): This method is bound by default as the callback of the GUI item associated with the command. It is the entrypoint of the command through the GUI. It typically creates an inputform allowing the user to specify any argument required for the command. The command method showForm is typically called with the name of the form to be created and a bunch of optional argument described later. Once all the parameters are known, the doitWrapper method is called to carry out the command. The old behavior was to call self.vf.getUserInput. The showForm method is a command method and replace the getUserInput method of the ViewerFramework. Although some commands still implement the getUserInput mechanism. buildFormDescr(self, formName): This method typically creates the inputform descriptor used by the guiCallback method to get user input for the command. The formName is a string which will be used as a key in the cmdForms dictionary to store the form information. This method is called by self.showForm This method returns an instance of an InputFormDescr which is the object describing a inputform in ViewerFramework. More information can be found in mglutil/gui/InputForm/Tk/gui.py For an example see: Pmv.secondaryStructureCommands.py module Almost all the PMV command implement an inputform. doit(self, *args, **kw): This method does the actual work. It should not implement any functionality that should be available outside the application for scripting purposes. This method should call such functions or object. setUpUndo(self, *args, **kw): Typically this method should be implemented if the command is undoable. It should have the same signature than the doit and the __call__ method. See displayCommands and colorCommands for a good example Of course, one is free to overwrite any of these methods and for instance rename doit using a more appropriate name. But, when doing so, the programmer has to overwrite both __call__ and guiCallback to call the right method to carry out the work. Besides these methods which are required to be implemented in a command there are the following optional methods: strArg(self, arg): Method to turn a command argument into a string. Used by the log method to generate a log string for the command. This method can be overwritten or extended by classes subclassing Command in order to handle properly instances of objects defined by the application when not handled properly by the base class. This method has been overwritten to be 'Molecule' aware. If you need to handle an argument a particular way this method should be overwritten. checkDependencies(): This method called when command is loaded. It typically checks for dependencies and if all the dependencies are not found the command won't be loaded. See msmsCommands for an example onAddCmdToViewer(): (previously initCommand) onAddCmdToViewer is called once when a command is loaded into a Viewer. Typically, this method : takes care of dependencies (i.e. load other commands that might be required) creates/initializes variables. see Pmv.traceCommands.py, Pmv.secondaryStructureCommands.py etc... customizeGUI(self): (obsolete) method allowing to modify the GUI associated with a command onAddObjectToViewer(self, obj): (previously named initGeom) When a command is loaded that implements an onAddObjectToViewer function,this function id called for every object present in the application. Once the command is loaded, this function will be called for every new object added to the application. In general, onAddObjectToViewer is used by a command to add a new geometry to the geometry container of an object. It is also where picking events and building arrays of colors specific to each geometry can be registered. See secondaryStructureCommands, msmsCommadns etc.. for an example onRemoveObjectFromViewer(self, obj): In python if all references to an object are not deleted, memory space occupied by that object even after its deletion is not freed. This function will be called for every object removed (deleted) from the application. When references to an object are created inside a command which are not related to the geomContainer of the object, in order to prevent memory leak this command has to implement an onRemoveObjectFromViewer to delete those references. See secondaryStructureCommands for an example The following methods are helper methods. log(self, *args, **kw): Method to log a command. args provides a list of positional arguments and kw is a dictionary of named arguments. This method loops over both args and kw and builds a string representation of their values. When a class is passed as one the arguments, an additional command is logged to load that class. This method also sets the command's lastCmdLog member. showForm(self, *args, **kw): If the inputForm object associated with the given formName already exists than it just deiconify the forms unless the force argument is set to true. Otherwise, showForm calls buildFormDescr with the given formName, then it creates an instance of InputForm with the given parameters and stores this object in the cmdForms dictionary, where the key is the formName and the value the InputForm object. (see the showForm documentation string for the description of the arguments) showForm will return the dictionary containing the values of the widgets if modal or blocking other it will return the form object. If a command generates geometries to be displayed in the camera, it is expected to create the geometry objects and add them to the appropriate GeometryContainer. A Python module implementing commands should implement the following at the end of the file so the commands are loadable in the application using the browseCommands command. commandList -- which is a list of dictionaries containing the following: 'name': command name (string) used as an alias to invoke the command from the commandline. 'cmd' : Command Class 'gui' : Typically is a commandGUI object but can be None if no GUI is associated with the Command An initModule method def initModule(viewer): for dict in commandList: viewer.addCommand(dict['cmd'], dict['name'], dict['gui']) This method will be used by the browseCommands command to load the given module into the application but also to determine which modules implement commands.
|
|||
| __init__(self, func=None) | ||
|
guiCallback(self,
event=None,
log=None,
redraw=None) Default callback function called by the gui |
||
|
_strArg(self,
arg) Method to turn a command argument into a string for logging purposes Add support for TreeNodes and TreeNodeSets |
||
|
strArg(self,
arg) Method to turn a command argument into a string for logging purposes Add support for TreeNodes and TreeNodeSets |
||
Inherited from |
|
|||
Inherited from |
|
|
|
|
|
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0alpha3 on Fri Nov 2 14:14:34 2007 | http://epydoc.sourceforge.net |