From: Denk Padje Date: Fri, 27 Feb 2009 13:13:02 +0000 (+0000) Subject: Add launcher-gtk.py (python implementation of demos/launcher-gtk.c) X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4231156da0f0998cfcaeec088e3f03af742f88d1;p=libchamplain Add launcher-gtk.py (python implementation of demos/launcher-gtk.c) --- diff --git a/bindings/python/demos/launcher-gtk.py b/bindings/python/demos/launcher-gtk.py new file mode 100755 index 0000000..67f41d4 --- /dev/null +++ b/bindings/python/demos/launcher-gtk.py @@ -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() +