Marble/MarblePython: Difference between revisions

    From KDE TechBase
    (New page: {{Template:I18n/Language Navigation Bar|Editing Projects/Marble/MarblePython}} {{TutorialBrowser| series=Marble Python Tutorial| name=Hello Marble| pre=[http://docs.python.org/tutorial/...)
     
    No edit summary
    Line 13: Line 13:


    == Hello Marble! ==
    == Hello Marble! ==
    Marble offers Python bindings. A small hello world example is available as part of the Marble sources at
    Marble offers KDE-Python bindings. A small hello world example is available as part of the Marble sources at


    <code>
    <code>

    Revision as of 16:31, 11 February 2009


    Editing Projects/Marble/MarblePython

    Hello Marble
    Tutorial Series   Marble Python Tutorial
    Previous   Python, Qt
    What's Next   Tutorial 2 - Marble's GeoPainter
    Further Reading   n/a


    Hello Marble!

    Marble offers KDE-Python bindings. A small hello world example is available as part of the Marble sources at

    marble/examples/python/simple_marble.py

    The Marble API allows a very easy integration of a map widget into your application. Let's prove that with some python code:

    1. !env python
    2. Copyright 2008 Simon Edwards <[email protected]>
    3. This program is free software; you can redistribute it and/or
    4. modify it under the terms of the GNU General Public License as
    5. published by the Free Software Foundation; either version 2 of
    6. the License, or (at your option) any later version.
    7. This program is distributed in the hope that it will be useful,
    8. but WITHOUT ANY WARRANTY; without even the implied warranty of
    9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    10. GNU General Public License for more details.
    11. You should have received a copy of the GNU General Public License
    12. along with this program. If not, see <http://www.gnu.org/licenses/>.
    13. A very simple example of how to use the marble widget.

    from PyQt4.QtCore import * from PyKDE4.kdeui import * from PyKDE4.kdecore import * from PyKDE4.marble import * import sys

    class MainWin (KMainWindow):

       def __init__ (self, *args):
           KMainWindow.__init__ (self)
           self.resize(640, 480)
    
           self.marble = Marble.MarbleWidget(self)
           self.marble.setMapThemeId("earth/bluemarble/bluemarble.dgml")
           self.setCentralWidget(self.marble)
           self.marble.centerOn(5.8333, 51.8333)
           self.marble.zoomView(2000)
    

    def main():

       appName     = "simple_marble"
       catalog     = ""
       programName = ki18n ("default")
       version     = "1.0"
       description = ki18n ("Simple Python Marble Example")
       license     = KAboutData.License_GPL
       copyright   = ki18n ("(c) 2008 Simon Edwards")
       text        = ki18n ("none")
       homePage    = "www.simonzone.com"
       bugEmail    = "[email protected]"
    
       aboutData   = KAboutData (appName, catalog, programName, version, description,
                                 license, copyright, text, homePage, bugEmail)
    
       aboutData.addAuthor (ki18n("Simon Edwards"), ki18n("Developer"))
       
       KCmdLineArgs.init(sys.argv, aboutData)
       
       app = KApplication()
       mainWindow = MainWin(None, "main window")
       mainWindow.show()
       app.connect(app, SIGNAL ("lastWindowClosed ()"), app.quit)
       app.exec_()
    

    main()