Python GME (PyGME) Component Generator| Overview |
| Component Specification |
<?xml version="1.0" encoding="UTF-8"?>
<component name="MyPython" version="1.0" type="Interpreter" paradigm="MetaGME">
<iconpath value="Icons/pygme.ico" />
<tooltip value="My Python Component" />
</component>
The attributes on the <component> tag are all mandatory.
| name | Gives an identity to the component. This name will be used to form the COM class that implements the component. For example, name="Foo" yields a COM class with the name "MGA.PythonInterpreter.Foo" for an interpreter and "MGA.PythonAddon.Foo" for an addon. |
| version | Assigns a version designator to the COM class. |
| type | Determines the kind of component generated, "Interpreter" for interpreters and "Addon" for addons. Other values result in a specification error. |
| paradigm | Name of the GME paradigm for which the generated Python component will be registered. |
The <iconpath> and <tooltip> tags are optional and only relevant to interpreter components.
| iconpath | Path to a component icon presented in the toolbar for the component's paradigm. If a relative path, it is considered relative to the folder containing the XML specification file. (Icons are always registered as absolute paths.) The file must be a .ico (Windows icon) 32x32 file. |
| tooltip | A string that is shown when the user mouses over the component's icon in the toolbar, if an icon is defined. |
| Running the Generator |
> PyGME.py [-register[=<system|user>]] [xmlfile]
Switches:
| -register | Requests that the component be registered with COM and GME after generation. If the value given the switch is user, or if no value is given, then the component is registered in the current user's registry; otherwise, if the value is system, then the component is registed in the system-wide registry. Administrative priviledges are required for the latter. |
Arguments:
| xmlfile | Path to a file that contains an XML specification for the component (see above). The default is the file 'component.xml' in the same folder as PyGME.py. |
| Post-Generation |
To unregister the component after registration, start a Python shell. Enter the following (assuming a component named 'Foo'):
> from Foo import Foo
> Foo.UnregisterSelf(systemwide)
The systemwide parameter should be 2 (REGACCESS_SYSTEM) if the component was registered in the System registry (LocalMachine)
and 1 (REGACCESS_USER) if the component was registered in the user registry (CurrentUser).
The constants are defined in MgaUtil.idl.
To re-register the component, from a Python shell enter:
> from Foo import Foo
> Foo.RegisterSelf(systemwide, iconfolder)
The systemwide parameter is as defined above for UnregisterSelf.
The iconfolder parameter is the full path to the folder that contains the component's icon.
This parameter should be omitted for addons and interpreters that do not define an icon.
| Implementation Notes |
Care must be taken when using the COM interface pointers that PythonCOM has wrapped as objects. For example, if an interface returns an IMgaFCO object and the underlying object is an IMgaModel, then this object must be cast before members of the IMgaModel interface are accessed. The base class from which all Python components created by the framework are derived provides two members that can be used to access the typelib modules generated by PythonCOM: mga and meta. These correspond to the mga.idl and meta.idl, respectively. To perform the cast described above, one would say:
> someModel = self.mga.IMgaModel(someFCO)
As a convenience, the GMEComComponent base class also provides a Logger member. This method can be used to write messages to the GME console.
Interpreter components need only implement the component's InvokeEX method to be fully implemented. Addons must register their interest in object events in their Initialize method and then implement service routines for global and objects events. The framework provides boilerplate for these implementations.