]> err.no Git - libchamplain/commitdiff
Add launcher-gtk.py (python implementation of demos/launcher-gtk.c)
authorDenk Padje <denkpadje@gmail.com>
Fri, 27 Feb 2009 13:13:02 +0000 (13:13 +0000)
committerPierre-Luc Beaudoin <pierre-luc@pierlux.com>
Sun, 1 Mar 2009 20:53:19 +0000 (22:53 +0200)
bindings/python/demos/launcher-gtk.py [new file with mode: 0755]

diff --git a/bindings/python/demos/launcher-gtk.py b/bindings/python/demos/launcher-gtk.py
new file mode 100755 (executable)
index 0000000..67f41d4
--- /dev/null
@@ -0,0 +1,107 @@
+#!/usr/bin/env python
+import clutter
+import cluttergtk
+import gtk
+import champlain
+import champlaingtk
+
+def zoom_in(widget, view):
+    view.zoom_in()
+
+def zoom_out(widget, view):
+    view.zoom_out()
+
+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", "openstreetmap")  # champlain.MAP_SOURCE_OPENSTREETMAP)
+    elif selection == "Open Arial Map":
+        view.set_property("map-source", "openarialmap")  # champlain.MAP_SOURCE_OPENARIALMAP)
+    elif selection == "Maps for free - Relief":
+        view.set_property("map-source", "mapsforfree-relief")  # champlain.MAP_SOURCE_MAPSFORFREE_RELIEF)
+    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()
+
+    marker = champlain.Marker()
+    marker.set_position(45.528178, -73.563788)
+    layer.add(marker)
+
+    layer.hide()
+
+    return layer
+
+clutter.init()
+
+window = gtk.Window()
+window.set_border_width(10)
+window.set_title("The world seen through the eyes of a Python")
+
+window.connect("destroy", lambda w: gtk.main_quit)
+
+vbox = gtk.VBox(False, 12)
+
+view = champlain.View()
+view.set_property("scroll-mode", "kinetic")  # champlain.SCROLL_MODE_KINETIC)
+view.set_property("zoom-level", 5)
+
+#layer = create_marker_layer()
+#view.add_layer(layer)
+
+embed = cluttergtk.Embed()
+embed.set_size_request(640, 480)
+
+bbox = gtk.HBox(False, 6)
+button = gtk.Button(stock=gtk.STOCK_ZOOM_IN)
+button.connect("clicked", zoom_in, view)
+bbox.add(button)
+
+button = gtk.Button(stock=gtk.STOCK_ZOOM_OUT)
+button.connect("clicked", zoom_out, view)
+bbox.add(button)
+
+#button = gtk.Button(label="Markers")
+#button.connect("toggled", toggle_layer, layer)
+#bbox.add(button)
+
+button = gtk.combo_box_new_text()
+button.append_text("Open Street Map")
+button.append_text("Open Arial Map")
+button.append_text("Maps for free - Relief")
+button.connect("changed", map_source_changed, view)
+bbox.add(button)
+
+button = gtk.SpinButton(gtk.Adjustment(lower=0, upper=20, value=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)
+
+window.add(vbox)
+# we need to realize the widget before we get the stage
+embed.realize()
+
+stage = embed.get_stage()
+view.set_size(640, 480)
+stage.add(view)
+
+window.show_all()
+view.center_on(45.466, -73.75)
+gtk.main()
+