| 1 | # vim: set expandtab shiftwidth=4 softtabstop=4:
|
|---|
| 2 |
|
|---|
| 3 | from chimerax.core.toolshed import BundleAPI
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 | # Subclass from chimerax.core.toolshed.BundleAPI and
|
|---|
| 7 | # override the method for registering commands,
|
|---|
| 8 | # inheriting all other methods from the base class.
|
|---|
| 9 | class _MyAPI(BundleAPI):
|
|---|
| 10 |
|
|---|
| 11 | api_version = 1 # register_command called with BundleInfo and
|
|---|
| 12 | # CommandInfo instance instead of command name
|
|---|
| 13 | # (when api_version==0)
|
|---|
| 14 |
|
|---|
| 15 | # Override method
|
|---|
| 16 | @staticmethod
|
|---|
| 17 | def register_command(bi, ci, logger):
|
|---|
| 18 | # bi is an instance of chimerax.core.toolshed.BundleInfo
|
|---|
| 19 | # ci is an instance of chimerax.core.toolshed.CommandInfo
|
|---|
| 20 | # logger is an instance of chimerax.core.logger.Logger
|
|---|
| 21 |
|
|---|
| 22 | # This method is called once for each command listed
|
|---|
| 23 | # in bundle_info.xml. Since we only listed one command,
|
|---|
| 24 | # we expect only a single call to this method.
|
|---|
| 25 |
|
|---|
| 26 | # We import the function to call and its argument
|
|---|
| 27 | # description from the ``cmd`` module, adding a
|
|---|
| 28 | # synopsis from bundle_info.xml if none is supplied
|
|---|
| 29 | # by the code.
|
|---|
| 30 | from . import cmd
|
|---|
| 31 | desc = cmd.hello_world_desc
|
|---|
| 32 | if desc.synopsis is None:
|
|---|
| 33 | desc.synopsis = ci.synopsis
|
|---|
| 34 |
|
|---|
| 35 | # We then register the function as the command callback
|
|---|
| 36 | # with the chimerax.core.commands module.
|
|---|
| 37 | # Note that the command name registered is not hardwired,
|
|---|
| 38 | # but actually comes from bundle_info.xml. In this example,
|
|---|
| 39 | # the command name is "hello", not "hello world".
|
|---|
| 40 | from chimerax.core.commands import register
|
|---|
| 41 | register(ci.name, desc, cmd.hello_world)
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 | # Create the ``bundle_api`` object that ChimeraX expects.
|
|---|
| 45 | bundle_api = _MyAPI()
|
|---|
| 46 |
|
|---|