]> err.no Git - libchamplain/commitdiff
Update python binding
authorVictor Godoy Poluceno <victorpoluceno@gmail.com>
Fri, 31 Jul 2009 17:46:27 +0000 (14:46 -0300)
committerPierre-Luc Beaudoin <pierre-luc@pierlux.com>
Fri, 31 Jul 2009 21:15:36 +0000 (17:15 -0400)
bindings/python/champlain/pychamplain.defs
bindings/python/champlain/pychamplain.override
bindings/python/demos/animated-marker.py
bindings/python/demos/capitals.py
bindings/python/demos/launcher.py
bindings/python/demos/markers.py [new file with mode: 0644]

index 7a27fab3d817b6b8caaddac3a9eeafc20d7324af..3100082379b9ffdc764e3105cd46d073af36b876 100644 (file)
   (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
   )
 )
 
+(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")
   (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
   (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
   )
 )
 
+(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
 (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
   (c-name "champlain_tile_set_modified_time")
   (return-type "none")
   (parameters
-    '("GTimeVal*" "time")
+    '("const-GTimeVal*" "time")
   )
 )
 
index 2331c06f281c62e0a3c389a35e85d8893d0fefe3..3fea03a1e8234d2b569706eb1c0543c75604d3c6 100644 (file)
@@ -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;
index 18f743a750775fee5d173737bf00c81e4915421c..238592c8ef7f02c8b25db079fe1d1d5cad820881 100755 (executable)
@@ -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
index d2b2193662875362f6f34e1bf804dbb4c5d46144..9147ff7e044c290c7ff98f16b1a87ef9f14680df 100755 (executable)
@@ -1,4 +1,5 @@
 #!/usr/bin/env python
+# -*- coding: utf-8 -*-
 import cluttergtk
 import clutter
 import champlain
index 3fb11f83960a91aec7f409221831430f84ff8eb4..8c82a3a7f8bfdf33318867f424ef153f47dd812d 100644 (file)
@@ -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 (file)
index 0000000..cb5a19e
--- /dev/null
@@ -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\n<span size=\"xx-small\">Québec</span>", "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