Difference between revisions of "Marble/MarblePythonMarbleWidget"

Jump to: navigation, search
m (Add link forward to third Tutorial)
 
(5 intermediate revisions by one other user not shown)
Line 8: Line 8:
 
pre=[[Projects/Marble/MarblePythonHello|Tutorial 1 - Hello World]]|
 
pre=[[Projects/Marble/MarblePythonHello|Tutorial 1 - Hello World]]|
  
next=[[Basic interaction with MarbleWidget|Tutorial 3 - Basic Interaction with MarbleWidget]]|
+
next=[[Projects/Marble/MarblePythonSignalsSlots|Tutorial 3 - Basic Interaction with MarbleWidget]]|
 
}}
 
}}
  
Line 20: Line 20:
  
 
<source lang="python">
 
<source lang="python">
 +
#!/usr/bin/env python
 
from PyQt4.QtCore import *
 
from PyQt4.QtCore import *
from PyKDE4.kdeui import *
+
from PyQt4.QtGui import *
from PyKDE4.kdecore import *
 
 
from PyKDE4.marble import *
 
from PyKDE4.marble import *
 
import sys
 
import sys
  
class MainWin (KMainWindow):
 
    def __init__ (self, *args):
 
        KMainWindow.__init__ (self)
 
        self.resize(600, 400)
 
 
# create the marble widget
 
        self.marble = Marble.MarbleWidget(self)
 
       
 
        # Load the OpenStreetMap map
 
        self.marble.setMapThemeId("earth/bluemarble/bluemarble.dgml")
 
       
 
        # make the map flat, not spherical
 
        self.marble.setProjection(Marble.Mercator)
 
       
 
        # Enable the cloud cover and enable the country borders
 
        self.marble.setShowClouds(True)
 
        self.marble.setShowBorders(True)
 
       
 
        # Hide the FloatItems: Compass and StatusBar
 
        self.marble.setShowOverviewMap(False)
 
        self.marble.setShowScaleBar(False)
 
       
 
        # add the widget to the KMainWindow
 
        self.setCentralWidget(self.marble)
 
  
 
def main():
 
def main():
     # defaults needed for the KApplication to be initialized
+
     app = QApplication(sys.argv)
    appName    = "marble_weather_map"
 
    catalog    = ""
 
    programName = ki18n ("Marble Weather Map")
 
    version    = "1.0"
 
    description = ki18n ("Using Marble to display a Weather Map")
 
    license    = KAboutData.License_GPL
 
    copyright  = ki18n ("(c) 2008 Your Name")
 
    text        = ki18n ("none")
 
    homePage    = "www.example.com"
 
    bugEmail    = "[email protected]"
 
  
     aboutData  = KAboutData (appName, catalog, programName, version, description,
+
     # create the marble widget
                              license, copyright, text, homePage, bugEmail)
+
    marble = Marble.MarbleWidget()
 +
 
 +
    # resize the widget and add a window title
 +
    marble.resize(600, 400)
 +
    marble.setWindowTitle("Marble Weather Map")
 +
 
 +
    # Load the OpenStreetMap map
 +
    marble.setMapThemeId("earth/bluemarble/bluemarble.dgml")
 +
 
 +
    # make the map flat, not spherical
 +
    marble.setProjection(Marble.Mercator)
 +
 
 +
    # zoom in further
 +
    marble.setZoom(1300)
 +
 
 +
    # Enable the cloud cover and enable the country borders
 +
    marble.setShowClouds(True)
 +
    marble.setShowBorders(True)
 +
 
 +
    # Hide the FloatItems: Compass and StatusBar
 +
    marble.setShowOverviewMap(False)
 +
    marble.setShowScaleBar(False)
 +
 
 +
    # add the widget to the KMainWindow
 +
    marble.show()
  
    KCmdLineArgs.init(sys.argv, aboutData)
 
   
 
    app = KApplication()
 
    # initialize our window, which will call the MainWindow.__init__ function above
 
    mainWindow = MainWin(None, "main window")
 
    mainWindow.show()
 
    # quit the application when the last window closes
 
    app.connect(app, SIGNAL ("lastWindowClosed ()"), app.quit)
 
 
     # run the app
 
     # run the app
 
     app.exec_()
 
     app.exec_()

Latest revision as of 21:01, 10 March 2016

MarbleWidget: Changing basic map properties
Tutorial Series   Marble Python Tutorial
Previous   Tutorial 1 - Hello World
What's Next   Tutorial 3 - Basic Interaction with MarbleWidget
Further Reading   n/a


Creating a weather map

We'd like to display a small weather map. So we need to modify the map. And we need to turn on the satellite view, enable the clouds and enable the country border lines.

The MarbleWidget class provides a convenient way to make these changes to the overall look and feel of the map. The documentation for this class can be found in the marble source at src/bindings/python/html/marble/Marble.html.

By default Marble shows a few info boxes: Overview Map, Compass and ScaleBar. But the size for the widget is very limited. Therefore we want to get rid of all the clutter, so we turn off the Overview Map and the ScaleBar.

#!/usr/bin/env python
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyKDE4.marble import *
import sys


def main():
    app = QApplication(sys.argv)

    # create the marble widget
    marble = Marble.MarbleWidget()

    # resize the widget and add a window title
    marble.resize(600, 400)
    marble.setWindowTitle("Marble Weather Map")

    # Load the OpenStreetMap map
    marble.setMapThemeId("earth/bluemarble/bluemarble.dgml")

    # make the map flat, not spherical
    marble.setProjection(Marble.Mercator)

    # zoom in further
    marble.setZoom(1300)

    # Enable the cloud cover and enable the country borders
    marble.setShowClouds(True)
    marble.setShowBorders(True)

    # Hide the FloatItems: Compass and StatusBar
    marble.setShowOverviewMap(False)
    marble.setShowScaleBar(False)

    # add the widget to the KMainWindow
    marble.show()

    # run the app
    app.exec_()

main()

Save the code above as marble_weather.py and run it:

python marble_weather.py

If things go fine, you end up with a map application that displays clouds on top of a flat map with clouds over it (you may need to zoom out):

Kde-python-tut2-screenshot.png


This page was last edited on 10 March 2016, at 21:01. Content is available under Creative Commons License SA 4.0 unless otherwise noted.