From aaf1b5fa1a7e32bff00a826de361213d455ce4a6 Mon Sep 17 00:00:00 2001 From: Mike Sheldon Date: Tue, 5 May 2009 14:32:02 +0100 Subject: [PATCH] Update python bindings to support new ChamplainMapSourceDesc API Update launcher-gtk.py example to use new ChamplainMapSourceDesc API --- bindings/python/champlain/pychamplain.defs | 9 ++++--- .../python/champlain/pychamplain.override | 24 +++++++++---------- bindings/python/demos/launcher-gtk.py | 12 +++++++--- bindings/python/update-binding.sh | 1 + 4 files changed, 28 insertions(+), 18 deletions(-) diff --git a/bindings/python/champlain/pychamplain.defs b/bindings/python/champlain/pychamplain.defs index e10dfa6..50de7d8 100644 --- a/bindings/python/champlain/pychamplain.defs +++ b/bindings/python/champlain/pychamplain.defs @@ -550,6 +550,10 @@ +;; From champlain-map-source-desc.h + + + ;; From champlain-map-source-factory.h (define-function map_source_factory_get_type @@ -565,7 +569,7 @@ (define-method get_list (of-object "ChamplainMapSourceFactory") (c-name "champlain_map_source_factory_get_list") - (return-type "gchar**") + (return-type "GSList*") ) (define-method create @@ -582,8 +586,7 @@ (c-name "champlain_map_source_factory_register") (return-type "gboolean") (parameters - '("const-gchar*" "id") - '("ChamplainMapSourceConstructor" "callback") + '("ChamplainMapSourceDesc*" "desc") ) ) diff --git a/bindings/python/champlain/pychamplain.override b/bindings/python/champlain/pychamplain.override index ee6388a..c2eb25d 100644 --- a/bindings/python/champlain/pychamplain.override +++ b/bindings/python/champlain/pychamplain.override @@ -23,25 +23,25 @@ ignore override champlain_map_source_factory_get_list kwargs static PyObject * _wrap_champlain_map_source_factory_get_list(PyGObject *self) { - gchar **list; - gchar *item; + GSList *iter, *list; 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]; + for(iter = list; iter != NULL; iter = iter->next) { + PyObject *item = PyDict_New(); + ChamplainMapSourceDesc *desc = (ChamplainMapSourceDesc *) iter->data; + PyDict_SetItemString(item, "id", PyString_FromString(desc->id)); + PyDict_SetItemString(item, "name", PyString_FromString(desc->name)); + PyDict_SetItemString(item, "license", PyString_FromString(desc->license)); + PyDict_SetItemString(item, "license_uri", PyString_FromString(desc->license_uri)); + PyDict_SetItemString(item, "min_zoom_level", PyInt_FromLong(desc->min_zoom_level)); + PyDict_SetItemString(item, "max_zoom_level", PyInt_FromLong(desc->max_zoom_level)); + PyList_Append(ret, item); + Py_DECREF(item); } - if (!list) { - Py_INCREF (Py_None); - return Py_None; - } - return ret; } %% diff --git a/bindings/python/demos/launcher-gtk.py b/bindings/python/demos/launcher-gtk.py index 8c6d266..6728eed 100755 --- a/bindings/python/demos/launcher-gtk.py +++ b/bindings/python/demos/launcher-gtk.py @@ -43,8 +43,12 @@ class LauncherGTK: combo = gtk.combo_box_new_text() self.map_source_factory = champlain.map_source_factory_get_default() + liststore = gtk.ListStore(str, str) for source in self.map_source_factory.get_list(): - combo.append_text(source) + liststore.append([source["id"], source["name"]]) + combo.append_text(source["name"]) + combo.set_model(liststore) + combo.set_attributes(combo.get_cells()[0], text=1) combo.set_active(0) combo.connect("changed", self.map_source_changed) bbox.add(combo) @@ -86,8 +90,10 @@ class LauncherGTK: self.view.set_property("zoom-level", self.spinbutton.get_value_as_int()) def map_source_changed(self, widget): - selection = widget.get_active_text() - source = self.map_source_factory.create(selection); + model = widget.get_model() + iter = widget.get_active_iter() + id = model.get_value(iter, 0) + source = self.map_source_factory.create(id); self.view.set_property("map-source", source) def map_zoom_changed(self, widget, value): diff --git a/bindings/python/update-binding.sh b/bindings/python/update-binding.sh index fd2d143..0e79f2b 100755 --- a/bindings/python/update-binding.sh +++ b/bindings/python/update-binding.sh @@ -11,6 +11,7 @@ python /usr/share/pygobject/2.0/codegen/h2def.py \ champlain-defines.h \ champlain-layer.h \ champlain-map-source.h \ + champlain-map-source-desc.h \ champlain-map-source-factory.h \ champlain-network-map-source.h \ champlain-marker.h \ -- 2.39.5