[Marble-devel] Python Plugin Support (proposal)

Benjamin Kaiser benjaminjkaiser at gmail.com
Sun Dec 29 13:34:45 UTC 2013


Hi All,

As part of GCI I have been tasked with researching what is needed for 
Python plugin integration into Marble. The result of this research was 
the attached txt (also available on Google Docs here 
<https://docs.google.com/document/d/1v4Unpq-kfEK3QgggXJ1IHqF5UFyurWbEvdy0sZ-k7v4/edit?usp=sharing>) 
document containing my findings on how this could be implemented. The 
goal of adding support for Python plugin integration for Marble is to 
allow people to create Python plugins for their projects for easy 
integration with Marble.

If anyone has any suggestions on improvements to this proposal, please 
let me know.

Kind regards,
Ben Kaiser
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/marble-devel/attachments/20131230/83014129/attachment.html>
-------------- next part --------------
Currently in Marble, the PluginManager (src/lib/PluginManager.{cpp,h}) class is used to load C++ plugin files (which are classes compiled as .so files). Currently there is no way to run Python plugins inside of Marble (as they do not compile to C++ plugin files). In order to allow for Python plugins to be written for Marble, Marble's C++ library must be able to interact with the python files.

A possible way to integrate the Python plugins into C++ is to create a new Class in Marble that communicates between Marble C++ and the plugin, but should remain transparent about the plugin being written in python (so the majority of other code in Marble does not require changing). This class should depend on the python c-api[1] and create a python environment that instantiates the python plugin. The class should also pass a reference interface (that may need to be written) to Python, this can be passed as a pointer and then instantiated in python using SIP's wrapinstance method[2]. The instance should be made accessible by the Python plugin so it may interact with Marble's window, data, etc.

This could be implemented in several steps like so:

  1. Writing a C++ class that wraps the python environment and loads a *.py plugin file that is passed (a new object of this class would be created for each plugin that is to be loaded).
  2. Picking up the *.py plugin files in the PluginManagerPrivate::loadPlugins() function, and creating instances of the above class for each *.py file found.
  3. Writing a simple Python plugin to test support.

Some examply C++ pseudocode:

<code>
run_command( "MarbleInterface.setInterface(" << interface_ptr << ")" )
</code>

Some example Python pseudocode:

<code>
def setInterface(pointer):
    self.m_interface = sip.wrapinstance(pointer, MarbleInterface)

def getInterface():
    return self.m_interface
</code>

Reference List:
[1] http://docs.python.org/2/c-api/init.html
[2] http://pyqt.sourceforge.net/Docs/sip4/python_api.html#sip.wrapinstance



More information about the Marble-devel mailing list