From: Victor Godoy Poluceno Date: Fri, 31 Jul 2009 17:46:27 +0000 (-0300) Subject: Update python binding X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=859994f87736361c4c6c6daf6a176a2cf341895d;p=libchamplain Update python binding --- diff --git a/bindings/python/champlain/pychamplain.defs b/bindings/python/champlain/pychamplain.defs index 7a27fab..3100082 100644 --- a/bindings/python/champlain/pychamplain.defs +++ b/bindings/python/champlain/pychamplain.defs @@ -77,6 +77,16 @@ (gtype-id "CHAMPLAIN_TYPE_ZOOM_LEVEL") ) +(define-boxed Point + (in-module "Champlain") + (c-name "ChamplainPoint") + (gtype-id "CHAMPLAIN_TYPE_POINT") + (fields + '("double" "lat") + '("double" "lon") + ) +) + ;; Enumerations and flags ... (define-enum ScrollMode @@ -499,6 +509,15 @@ ) ) +(define-method remove_point + (of-object "ChamplainPolygon") + (c-name "champlain_polygon_remove_point") + (return-type "none") + (parameters + '("ChamplainPoint*" "point") + ) +) + (define-method clear_points (of-object "ChamplainPolygon") (c-name "champlain_polygon_clear_points") @@ -644,6 +663,36 @@ (return-type "ChamplainLayer*") ) +(define-method show + (of-object "ChamplainLayer") + (c-name "champlain_layer_show") + (return-type "none") +) + +(define-method hide + (of-object "ChamplainLayer") + (c-name "champlain_layer_hide") + (return-type "none") +) + +(define-method add_marker + (of-object "ChamplainLayer") + (c-name "champlain_layer_add_marker") + (return-type "none") + (parameters + '("ChamplainBaseMarker*" "marker") + ) +) + +(define-method remove_marker + (of-object "ChamplainLayer") + (c-name "champlain_layer_remove_marker") + (return-type "none") + (parameters + '("ChamplainBaseMarker*" "marker") + ) +) + ;; From champlain-map-source.h @@ -1186,6 +1235,14 @@ (return-type "gboolean") ) +(define-function marker_set_highlight_color + (c-name "champlain_marker_set_highlight_color") + (return-type "none") + (parameters + '("ClutterColor*" "color") + ) +) + ;; From champlain-base-marker.h @@ -1211,6 +1268,21 @@ ) ) +(define-method set_highlighted + (of-object "ChamplainBaseMarker") + (c-name "champlain_base_marker_set_highlighted") + (return-type "none") + (parameters + '("gboolean" "value") + ) +) + +(define-method get_highlighted + (of-object "ChamplainBaseMarker") + (c-name "champlain_base_marker_get_highlighted") + (return-type "gboolean") +) + ;; From champlain-tile.h @@ -1300,13 +1372,13 @@ (define-method get_modified_time_string (of-object "ChamplainTile") (c-name "champlain_tile_get_modified_time_string") - (return-type "char*") + (return-type "gchar*") ) (define-method get_etag (of-object "ChamplainTile") (c-name "champlain_tile_get_etag") - (return-type "const-char*") + (return-type "const-gchar*") ) (define-method set_x @@ -1396,7 +1468,7 @@ (c-name "champlain_tile_set_modified_time") (return-type "none") (parameters - '("GTimeVal*" "time") + '("const-GTimeVal*" "time") ) ) diff --git a/bindings/python/champlain/pychamplain.override b/bindings/python/champlain/pychamplain.override index 2331c06..3fea03a 100644 --- a/bindings/python/champlain/pychamplain.override +++ b/bindings/python/champlain/pychamplain.override @@ -116,60 +116,42 @@ _wrap_champlain_map_source_factory_register(PyGObject *self, PyObject *args, PyO (gpointer)pyuser_data)); } %% -override champlain_polygon_append_point kwargs -static PyObject * -_wrap_champlain_polygon_append_point(PyGObject *self, PyObject *args) -{ - double lat, lon; - - if (!PyArg_ParseTuple(args, "dd:ChamplainPolygon.append_point", &lat, &lon)) - return NULL; - champlain_polygon_append_point(CHAMPLAIN_POLYGON(self->obj), lat, lon); - return Py_BuildValue("(dd)", lat, lon); -} -%% -%% -override champlain_polygon_insert_point kwargs -static PyObject * -_wrap_champlain_polygon_insert_point(PyGObject *self, PyObject *args) -{ - double lat, lon; - int pos; - - if (!PyArg_ParseTuple(args, "ddi:ChamplainPolygon.insert_point", &lat, &lon, &pos)) - return NULL; - champlain_polygon_insert_point(CHAMPLAIN_POLYGON(self->obj), lat, lon, pos); - return Py_BuildValue("(dd)", lat, lon); -} -%% -%% override champlain_polygon_get_points kwargs static PyObject * _wrap_champlain_polygon_get_points(PyGObject *self, PyObject *args) { GList *iter, *list = champlain_polygon_get_points(CHAMPLAIN_POLYGON(self->obj)); PyObject *ret = PyList_New(0); + PyObject *pypoint; for(iter = list; iter != NULL; iter = iter->next) { ChamplainPoint *point = (ChamplainPoint *) iter->data; - PyObject *item = Py_BuildValue("(dd)", point->lat, point->lon); - PyList_Append(ret, item); - Py_DECREF(item); + pypoint = pyg_boxed_new(CHAMPLAIN_TYPE_POINT, point, TRUE, TRUE); + PyList_Append(ret, pypoint); + Py_DECREF(pypoint); } return ret; } %% override champlain_view_get_coords_from_event kwargs static PyObject * -_wrap_champlain_view_get_coords_from_event(PyGObject *self, PyObject *args) +_wrap_champlain_view_get_coords_from_event(PyGObject *self, PyObject *args, PyObject *kargs) { - double lat, lon; + static char *kwlist[] = {"event", NULL}; + gdouble lat, lon; PyObject *pyevent; + ClutterEvent *event; - if (!PyArg_ParseTuple(args, "O:ChamplainView.get_coords_from_event", &pyevent)) + if (!PyArg_ParseTupleAndKeywords(args, kargs, "O:ChamplainView.get_coords_from_event", kwlist, &pyevent)) return NULL; - ClutterEvent *event = pyg_boxed_get (pyevent, ClutterEvent); + if (pyg_boxed_check(pyevent, CLUTTER_TYPE_EVENT)) + event = pyg_boxed_get(pyevent, ClutterEvent); + else { + PyErr_SetString(PyExc_TypeError, "event should be a ClutterEvent"); + return NULL; + } + champlain_view_get_coords_from_event(CHAMPLAIN_VIEW(self->obj), event, &lat, &lon); return Py_BuildValue("(dd)", lat, lon); } @@ -179,7 +161,7 @@ static PyObject * _wrap_champlain_view_get_coords_at(PyGObject *self, PyObject *args) { guint x, y; - double lat, lon; + gdouble lat, lon; if (!PyArg_ParseTuple(args, "ii:ChamplainView.get_coords_at", &x, &y)) return NULL; diff --git a/bindings/python/demos/animated-marker.py b/bindings/python/demos/animated-marker.py index 18f743a..238592c 100755 --- a/bindings/python/demos/animated-marker.py +++ b/bindings/python/demos/animated-marker.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +# -*- coding: utf-8 -*- #This is a demonstration of the libchamplain python binding. #It will display a blue "pulsating" dot on a given position on the map diff --git a/bindings/python/demos/capitals.py b/bindings/python/demos/capitals.py index d2b2193..9147ff7 100755 --- a/bindings/python/demos/capitals.py +++ b/bindings/python/demos/capitals.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +# -*- coding: utf-8 -*- import cluttergtk import clutter import champlain diff --git a/bindings/python/demos/launcher.py b/bindings/python/demos/launcher.py index 3fb11f8..8c82a3a 100644 --- a/bindings/python/demos/launcher.py +++ b/bindings/python/demos/launcher.py @@ -1,7 +1,11 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- import gobject import clutter import champlain +from markers import create_marker_layer + PADDING = 10 def map_view_button_release_cb(actor, event, view): @@ -43,8 +47,8 @@ def main(): actor = champlain.View() actor.set_size(800, 600) actor.set_property('scroll-mode', champlain.SCROLL_MODE_KINETIC) - actor.set_property('zoom-level', 12) actor.center_on(45.466, -73.75) + actor.set_property('zoom-level', 12) # Create the buttons buttons = clutter.Group() @@ -65,6 +69,10 @@ def main(): button.connect('button-release-event', zoom_out, actor) buttons.add(button) + # Create the markers and marker layer + layer = create_marker_layer(actor) + actor.add_layer(layer) + stage = clutter.stage_get_default() stage.set_size(800, 600) stage.add(actor) diff --git a/bindings/python/demos/markers.py b/bindings/python/demos/markers.py new file mode 100644 index 0000000..cb5a19e --- /dev/null +++ b/bindings/python/demos/markers.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +import clutter +import champlain +import pango + +def marker_button_release_cb(actor, event, view): + if event.button != 1 and event.click_count > 1: + return False + + print "Montreal was clicked\n" + return True + + +def create_marker_layer(view): + orange = clutter.Color(0xf3, 0x94, 0x07, 0xbb) + black = clutter.Color(0x00, 0x00, 0x00, 0xff) + layer = champlain.Layer() + + marker = champlain.marker_new_with_text( + "Montréal\nQuébec", "Serif 14", black, + orange) + marker.set_use_markup(True) + marker.set_alignment(pango.ALIGN_RIGHT) + marker.set_color(orange) + + marker.set_position(45.528178, -73.563788) + layer.add_marker(marker) + marker.set_reactive(True) + marker.connect("button-release-event", marker_button_release_cb, view) + + marker = champlain.marker_new_from_file( + "/usr/share/icons/gnome/24x24/emblems/emblem-generic.png") + marker.set_text("New York") + marker.set_position(40.77, -73.98) + layer.add_marker(marker) + + marker = champlain.marker_new_from_file( + "/usr/share/icons/gnome/24x24/emblems/emblem-important.png") + marker.set_position(47.130885, -70.764141) + layer.add_marker(marker) + + marker = champlain.marker_new_from_file( + "/usr/share/icons/gnome/24x24/emblems/emblem-favorite.png") + marker.set_draw_background(False) + marker.set_position(45.41484, -71.918907) + layer.add_marker(marker) + + layer.show() + return layer