]> err.no Git - libchamplain/commitdiff
Add support for wrapping champlain_map_source_factory_get_list()
authorMike Sheldon <mike@mikeasoft.com>
Sun, 3 May 2009 16:51:02 +0000 (17:51 +0100)
committerPierre-Luc Beaudoin <pierre-luc@pierlux.com>
Sun, 3 May 2009 19:27:54 +0000 (15:27 -0400)
Update launcher-gtk.py to use new map source factory API

bindings/python/champlain/pychamplain.override
bindings/python/demos/launcher-gtk.py

index fc508531bf68767a358bd1d45ed8b2e1dc776984..ee6388a5ed5e78145f9b6fa4c967fed992235ea4 100644 (file)
@@ -20,3 +20,28 @@ ignore-glob
 ignore
        champlain_zoom_level_set_actor
 %%
+override champlain_map_source_factory_get_list kwargs
+static PyObject *
+_wrap_champlain_map_source_factory_get_list(PyGObject *self) {
+       gchar **list;
+       gchar *item;
+       PyObject *ret;
+       int i = 0;
+
+       list = champlain_map_source_factory_get_list(CHAMPLAIN_MAP_SOURCE_FACTORY(self->obj));
+       
+       ret = PyList_New(0);
+       item = list[i];
+       while (item != NULL) {
+               PyList_Append (ret, PyString_FromString(item));
+               item = list[++i];
+       }
+
+       if (!list) {
+               Py_INCREF (Py_None);
+               return Py_None;
+       }
+       
+       return ret;
+}
+%%
index 0ddf5838bb2c3b3a5f2ed6be303abcb24d2d644f..8c6d266a5daeaf2f2db854f0ea48e76ff819b041 100755 (executable)
@@ -21,7 +21,6 @@ class LauncherGTK:
 
                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)
@@ -43,11 +42,9 @@ class LauncherGTK:
                bbox.add(button)
 
                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")
+               self.map_source_factory = champlain.map_source_factory_get_default()
+               for source in self.map_source_factory.get_list():
+                       combo.append_text(source)
                combo.set_active(0)
                combo.connect("changed", self.map_source_changed)
                bbox.add(combo)
@@ -55,6 +52,7 @@ class LauncherGTK:
                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)
+               self.spinbutton.set_value(5)
                bbox.add(self.spinbutton)
 
                vbox.pack_start(bbox, expand=False, fill=False)
@@ -89,18 +87,8 @@ class LauncherGTK:
 
        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")
+               source = self.map_source_factory.create(selection);
+               self.view.set_property("map-source", source)
 
        def map_zoom_changed(self, widget, value):
                self.spinbutton.set_value(self.view.get_property("zoom-level"))