|
PySh - Writing ScriptsAll you've got to do is write a simple Python class that adheres to a basic interface, and PySh does the rest. Here's the interface that PySh requires for your Python classes: class Example:
description = "Description...";
def Exec( self, dte ):
pass;
Here's a real example of a command that flips between .cpp and .h files: import pysh;
# Microsoft Development Environment 8.0
pysh.MakeAlias(
"_dte",
"{80CC9F66-E7D8-4DDD-85B6-D9E6CD0E93E2}",
8, 0, 1 );
import _dte;
class HeaderFlip:
description = "Flip between .cpp & .h files";
def Exec( self, dte ):
doc = dte.ActiveDocument;
if( not doc ):
return;
path = os.path.splitext( doc.FullName );
flipPath = str( path[ 0 ] ).lower();
if( path[ 1 ] == '.cpp' ):
flipPath += '.h';
elif( path[ 1 ] == '.h' ):
flipPath += '.cpp';
else:
return;
dte.ItemOperations.OpenFile(
flipPath, _dte.constants.vsViewKindAny );
This example, and others just like it, can be found in <installdir>\examples.py See also
|
||||||