On 12/02/2004 01:03:54 PM, John Stoffel wrote:
> Alex> 1. I made the plugin writing functions the module-level functions.
> Alex> The structure seemed simple enough so that two functions can
> Alex> be used without a class. This is not all that important, just ea=
> Alex> to read if you ask me :-)
> Would it make more sense for each plugin to be required to use it's
> own Class? To make sure there are no conflicts? Or do I remember
> someone telling me that when you do an import, the code gets it's own
> class by default?
There will be no conflicts, and here's why. The Python has a notion of
modules. Every *.py file is a module, although some modules can also
come in other file types (*.so, *.pyc or *.pyo, etc). The module has its
own namespace. So when you say 'import VCG2' then every object
in that modules is accessed as VCG2.object_name (e.g. VCG2.write_vcg()
for the main function that writes the contents).
If and only if you explicitly insist, you can get rid of the module name.
Sometimes this is useful when you have many similar objects providing
similar functionality, adn you may wish to import one or the other under
the same name. Or you may wish to just have shorter names :-) But in
any case, to do that you have to use a different import statement:
>>> from VCG2 import write_vcg
Then write_vcg will be available without the "VCG2." prefix.
We are not doing that with plugins. Each plugin is imported as a module
with its own namespace. Everything is sealed, so the only function
available to the Gramps' core is the one that you register at the end of
the plugin. When the user selects the plugin from the menu or from
the list in the Reports/Tools window, Gramps simply runs the registered
function with database and person of the moment. Everything else is
completely the matter of the plugin.
Now, the plugin knows about the gramps' internals, but not the other
way around. Neither do plugins know about each other. Since each
plugin is a module, the namespaces are sealed from each other. For all
your pleasure, you may use same object names as the other guy and
nobody gets to know :-)
Hope this helps to sort things out,
Alexander Roitman http://ebner.neuroscience.umn.edu/people/alex.html
Dept. of Neuroscience, Lions Research Building
2001 6th Street SE, Minneapolis, MN 55455
Tel (612) 625-7566 FAX (612) 626-9201