Projects/Marble/MarblePythonHello

Jump to: navigation, search
Hello Marble
Tutorial Series   Marble Python Tutorial
Previous   None
What's Next   Tutorial 2 - MarbleWidget: Changing basic map properties
Further Reading   n/a


Hello Marble!

The API of the Marble library allows for a very easy integration of a map widget into your application.

Let's prove that with a tiny Hello world-like example. For a start we just create a KApplication object and a MarbleWidget object which serves as a window. By default the MarbleWidget uses the Atlas map theme. However for our first example we choose to display streets. So we set the maptheme id to OpenStreetMap. Then we call QWidget.show(self) to show the map widget and we call QApplication.exec_() to start the application's event loop. That's all!

from PyQt4.QtGui import *
from PyKDE4.marble import *
import sys
 
def main():
  # Initialize QApplication
  app = QApplication(sys.argv)
 
  # Create a Marble QWidget
  m = Marble.MarbleWidget()
 
  # Load the OpenStreeMap map
  m.setMapThemeId("earth/openstreetmap/openstreetmap.dgml")
 
  # Show the window
  m.show()
 
  # Run the app
  app.exec_()
 
main()

Copy and paste the code above into a text editor. Then save it as my_marble.py and run it by entering the following command on the command line:

python my_marble.py

You end up with a fully usable OpenStreetMap application:

My hello py.png

Ktip.png
 
Tip
You need PyQt, PyKDE and Marble development packages for Python (or comparable git installations)
noframe
 
Note
If you provide maps in your application please check the Terms of Use of the map material. The map material that is shipped with Marble is licensed in the spirit of Free Software. This usually means at least that the authors should be credited and that the license is mentioned. E.g. for OpenStreetMap the license is CC-BY-SA. Other map data shipped with Marble is either public domain or licensed in the spirit of the BSD license.

This page was last modified on 25 November 2013, at 19:03. This page has been accessed 419 times. Content is available under Creative Commons License SA 3.0 as well as the GNU Free Documentation License 1.2.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V.Legal