]> err.no Git - libchamplain/commitdiff
Add DemoMarkerLayer for creating demo markers
authorMike Sheldon <mike@mikeasoft.com>
Sun, 3 May 2009 12:58:20 +0000 (13:58 +0100)
committerPierre-Luc Beaudoin <pierre-luc@pierlux.com>
Sun, 3 May 2009 19:27:54 +0000 (15:27 -0400)
Make GTK Launcher a proper Python object

bindings/python/demos/demomarkers.py [new file with mode: 0644]
bindings/python/demos/launcher-gtk.py

diff --git a/bindings/python/demos/demomarkers.py b/bindings/python/demos/demomarkers.py
new file mode 100644 (file)
index 0000000..992357a
--- /dev/null
@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+import clutter
+import champlain
+
+class DemoMarkerLayer(champlain.Layer):
+
+       def __init__(self):
+               champlain.Layer.__init__(self)
+
+               orange = clutter.Color(0xf3, 0x94, 0x07, 0xbb)
+               white = clutter.Color(0xff, 0xff, 0xff, 0xff)
+               black = clutter.Color(0x00, 0x00, 0x00, 0xff)
+               marker = champlain.marker_new_with_text("MontrĂ©al", "Airmole 14", black, orange)
+               marker.set_position(45.528178, -73.563788)
+               self.add(marker)
+
+               marker = champlain.marker_new_with_text("New York", "Sans 25", white, orange);
+               marker.set_position(40.77, -73.98);
+               self.add(marker)
+
+               marker = champlain.marker_new_with_text("Saint-Tite-des-Caps", "Serif 12", black, orange);
+               marker.set_position(47.130885, -70.764141);
+               self.add(marker)
+
+               self.hide()
index 83a2ba73dcae72a99f9457a2d94fa244706f59af..0ddf5838bb2c3b3a5f2ed6be303abcb24d2d644f 100755 (executable)
@@ -6,130 +6,108 @@ import gobject
 import gtk
 import champlain
 import champlaingtk
+from demomarkers import DemoMarkerLayer
 
-class champlainDemo:
-       def zoom_in(widget, view):
-               view.zoom_in()
+class LauncherGTK:
 
-       def zoom_out(widget, view):
-               view.zoom_out()
+       def __init__(self):
+               self.window = gtk.Window()
+               self.window.set_border_width(10)
+               self.window.set_title("The world seen through the eyes of a Python")
 
-       def toggle_layer(widget, layer):
-               if widget.get_active():
-                       layer.show_all()
-               else:
-                       layer.hide()
-
-       def zoom_changed(spinbutton, view):
-               view.set_property("zoom-level", spinbutton.get_value_as_int())
-
-       def map_source_changed(widget, view):
-               selection = widget.get_active_text()
-               if selection == "Open Street Map":
-                       view.set_property("map-source", champlain.map_source_new_osm_mapnik())
-               elif selection == "Open Arial Map":
-                       view.set_property("map-source", champlain.map_source_new_oam())
-               elif selection == "Maps for free - Relief":
-                       view.set_property("map-source", champlain.map_source_new_mff_relief())
-               elif selection == "OSM Cycle Map":
-                       view.set_property("map-source", champlain.map_source_new_osm_cyclemap())
-               elif selection == "OSM Osmarender":
-                       view.set_property("map-source", champlain.map_source_new_osm_osmarender())
-               else:
-                       raise RuntimeException("Illegal state: active text of combobox invalid")
-
-       def map_zoom_changed(view, obj, spinbutton):
-               spinbutton.set_value(view.get_property("zoom-level"))
-
-       def create_marker_layer():
-               layer = champlain.Layer()
-
-               orange = clutter.Color(0xf3, 0x94, 0x07, 0xbb)
-               white = clutter.Color(0xff, 0xff, 0xff, 0xff)
-               black = clutter.Color(0x00, 0x00, 0x00, 0xff)
-               marker = champlain.marker_new_with_text("MontrĂ©al", "Airmole 14", black, orange)
-               marker.set_position(45.528178, -73.563788)
-               layer.add(marker)
+               self.window.connect("destroy", lambda w: gtk.main_quit)
 
-               marker = champlain.marker_new_with_text("New York", "Sans 25", white, orange);
-               marker.set_position(40.77, -73.98);
-               layer.add(marker)
+               vbox = gtk.VBox(False, 12)
 
-               marker = champlain.marker_new_with_text("Saint-Tite-des-Caps", "Serif 12", black, orange);
-               marker.set_position(47.130885, -70.764141);
-               layer.add(marker)
+               self.view = champlain.View()
+               self.view.set_property("scroll-mode", champlain.SCROLL_MODE_KINETIC)
+               self.view.set_property("zoom-level", 5)
+       
+               self.layer = DemoMarkerLayer()
+               self.view.add_layer(self.layer)
 
-               layer.hide()
+               embed = cluttergtk.Embed()
+               embed.set_size_request(640, 480)
 
-               return layer
+               bbox = gtk.HBox(False, 6)
+               button = gtk.Button(stock=gtk.STOCK_ZOOM_IN)
+               button.connect("clicked", self.zoom_in)
+               bbox.add(button)
 
-       gobject.threads_init()
-       clutter.init()
+               button = gtk.Button(stock=gtk.STOCK_ZOOM_OUT)
+               button.connect("clicked", self.zoom_out)
+               bbox.add(button)
 
-       window = gtk.Window()
-       window.set_border_width(10)
-       window.set_title("The world seen through the eyes of a Python")
+               button = gtk.ToggleButton(label="Markers")
+               button.connect("toggled", self.toggle_layer)
+               bbox.add(button)
 
-       window.connect("destroy", lambda w: gtk.main_quit)
+               combo = gtk.combo_box_new_text()
+               combo.append_text("Open Street Map")
+               combo.append_text("Open Arial Map")
+               combo.append_text("Maps for free - Relief")
+               combo.append_text("OSM Cycle Map")
+               combo.append_text("OSM Osmarender")
+               combo.set_active(0)
+               combo.connect("changed", self.map_source_changed)
+               bbox.add(combo)
 
-       vbox = gtk.VBox(False, 12)
+               self.spinbutton = gtk.SpinButton(gtk.Adjustment(lower=0, upper=20, value=1, step_incr=1))
+               self.spinbutton.connect("changed", self.zoom_changed)
+               self.view.connect("notify::zoom-level", self.map_zoom_changed)
+               bbox.add(self.spinbutton)
 
-       view = champlain.View()
-       view.set_property("scroll-mode", champlain.SCROLL_MODE_KINETIC)
-       view.set_property("zoom-level", 5)
+               vbox.pack_start(bbox, expand=False, fill=False)
+               vbox.add(embed)
 
-       layer = create_marker_layer()
-       view.add_layer(layer)
+               self.window.add(vbox)
+               # we need to realize the widget before we get the stage
+               embed.realize()
 
-       embed = cluttergtk.Embed()
-       embed.set_size_request(640, 480)
+               stage = embed.get_stage()
+               self.view.set_size(640, 480)
+               stage.add(self.view)
 
-       bbox = gtk.HBox(False, 6)
-       button = gtk.Button(stock=gtk.STOCK_ZOOM_IN)
-       button.connect("clicked", zoom_in, view)
-       bbox.add(button)
+               self.window.show_all()
+               self.view.center_on(45.466, -73.75)
 
-       button = gtk.Button(stock=gtk.STOCK_ZOOM_OUT)
-       button.connect("clicked", zoom_out, view)
-       bbox.add(button)
 
-       button = gtk.ToggleButton(label="Markers")
-       button.connect("toggled", toggle_layer, layer)
-       bbox.add(button)
+       def zoom_in(self, widget):
+               self.view.zoom_in()
 
-       combo = gtk.combo_box_new_text()
-       combo.append_text("Open Street Map")
-       combo.append_text("Open Arial Map")
-       combo.append_text("Maps for free - Relief")
-       combo.append_text("OSM Cycle Map")
-       combo.append_text("OSM Osmarender")
-       combo.set_active(0)
-       combo.connect("changed", map_source_changed, view)
-       bbox.add(combo)
+       def zoom_out(self, widget):
+               self.view.zoom_out()
 
-       button = gtk.SpinButton(gtk.Adjustment(lower=0, upper=20, value=1, step_incr=1))
-       button.connect("changed", zoom_changed, view)
-       view.connect("notify::zoom-level", map_zoom_changed, button)
-       bbox.add(button)
-
-       vbox.pack_start(bbox, expand=False, fill=False)
-       vbox.add(embed)
+       def toggle_layer(self, widget):
+               if widget.get_active():
+                       self.layer.show_all()
+               else:
+                       self.layer.hide()
 
-       window.add(vbox)
-       # we need to realize the widget before we get the stage
-       embed.realize()
+       def zoom_changed(self, widget):
+               self.view.set_property("zoom-level", self.spinbutton.get_value_as_int())
 
-       stage = embed.get_stage()
-       view.set_size(640, 480)
-       stage.add(view)
+       def map_source_changed(self, widget):
+               selection = widget.get_active_text()
+               if selection == "Open Street Map":
+                       self.view.set_property("map-source", champlain.map_source_new_osm_mapnik())
+               elif selection == "Open Arial Map":
+                       self.view.set_property("map-source", champlain.map_source_new_oam())
+               elif selection == "Maps for free - Relief":
+                       self.view.set_property("map-source", champlain.map_source_new_mff_relief())
+               elif selection == "OSM Cycle Map":
+                       self.view.set_property("map-source", champlain.map_source_new_osm_cyclemap())
+               elif selection == "OSM Osmarender":
+                       self.view.set_property("map-source", champlain.map_source_new_osm_osmarender())
+               else:
+                       raise RuntimeException("Illegal state: active text of combobox invalid")
 
-       window.show_all()
-       view.center_on(45.466, -73.75)
+       def map_zoom_changed(self, widget, value):
+               self.spinbutton.set_value(self.view.get_property("zoom-level"))
 
-def main():
-    gtk.main()
-    return 0
 
 if __name__ == "__main__":
-    champlainDemo()
-    main()
+       gobject.threads_init()
+       clutter.init()
+       LauncherGTK()
+       gtk.main()