The initial code is the same as for the ToolbarButtonExtension example
Here we define two functions, one to handle the "mainchain" command,
and one to handle the "~mainchain" command.
Import the module's workhorse function.
It is imported inside the function definition so that
it does not slow down Chimera startup with extra imports
in the main scope.
Import and use the Midas.midas_text doExtensionFunc procedure
to process typed arguments and call the mainchain() function
appropriately. For a simple function like mainchain(), which
takes no arguments, using doExtensionFunc is probably overkill.
One could instead use the approach applied in the revMainchainCmd
function below and simply test for the presence of any
arguments (raising MidasError if any are found) and directly calling
the mainchain() function otherwise. As implemented here, using
doExtensionFunc, if the user does provide arguments then
doExtensionFunc will raise an error complaining that there
were unknown keyword arguments supplied.
The function for "~mainchain"
We are going to implement ~mainchain as a synonym for "display",
so we import runCommand which simplifies doing that.
Raising MidasError will cause the error message
to show up in the status line as red text
runCommand takes any legal command-line command and executes it.
Now actually register the "mainchain" command with the command interpreter
by using addCommand(). The first argument is the command name and the
second is the callback function for doing the work. The
import chimera.extension
class MainChainEMO(chimera.extension.EMO):
def name(self):
return 'Backbone'
def description(self):
return 'display only protein backbone'
def categories(self):
return ['Utilities']
def icon(self):
return self.path('mainchain.tiff')
def activate(self):
self.module().mainchain()
chimera.extension.manager.registerExtension(MainChainEMO(__file__))
def mainchainCmd(cmdName, args):
from ToolbarButtonCommand import mainchain
from Midas.midas_text import doExtensionFunc
doExtensionFunc(mainchain, args)
def revMainchainCmd(cmdName, args):
from chimera import runCommand
from Midas import MidasError
if args:
raise MidasError("~mainchain takes no arguments")
runCommand("display")
revFunc keyword
specifies the function to implement "~mainchain". The help keyword has
been omitted, therefore no help will be provided.
from Midas.midas_text import addCommand
addCommand("mainchain", mainchainCmd, revFunc=revMainchainCmd)