[gcompris/gcomprixogoo] Added support for user_data in image selector api.



commit 560b6233377cc6e59812d284a61474fb1d7ba1b1
Author: Bruno Coudoin <bruno coudoin free fr>
Date:   Sun Oct 25 19:18:01 2009 +0100

    Added support for user_data in image selector api.

 src/anim-activity/anim.py      |    6 +++---
 src/boards/py-mod-gcompris.c   |   14 +++++++++-----
 src/gcompris/gcompris.h        |    8 +++++---
 src/gcompris/images_selector.c |    7 +++++--
 4 files changed, 22 insertions(+), 13 deletions(-)
---
diff --git a/src/anim-activity/anim.py b/src/anim-activity/anim.py
index c1229c8..3174997 100644
--- a/src/anim-activity/anim.py
+++ b/src/anim-activity/anim.py
@@ -393,7 +393,8 @@ class Gcompris_anim:
 
           gcompris.images_selector_start(self.gcomprisBoard,
                                          "dataset",
-                                         image_selected);
+                                         image_selected,
+                                         self);
           return False
 
         elif (self.tools[tool][0] == "MOVIE"):
@@ -750,9 +751,8 @@ def general_restore(filename, filetype, fles):
   print "general_restore : ", filename, " type ",filetype
 
 
-def image_selected(image):
+def image_selected(image, fles):
   #fles is used because self is not passed through callback
-  global fles
   print "image selected %s" %(image,)
   pixmap = gcompris.utils.load_pixmap(image)
 
diff --git a/src/boards/py-mod-gcompris.c b/src/boards/py-mod-gcompris.c
index cfa4044..159b580 100644
--- a/src/boards/py-mod-gcompris.c
+++ b/src/boards/py-mod-gcompris.c
@@ -404,14 +404,15 @@ py_gc_cursor_set(PyObject* self, PyObject* args)
 /* Some functions and variables needed to get the image selector working */
 static PyObject* pyImageSelectorCallBackFunc = NULL;
 
-void pyImageSelectorCallBack(gchar* image){
+void pyImageSelectorCallBack(gchar* image, void *user_data){
   PyObject* args;
   PyObject* result;
   if(pyImageSelectorCallBackFunc==NULL) return;
 
   /* Build arguments */
-  args = PyTuple_New(1);
+  args = PyTuple_New(2);
   PyTuple_SetItem(args, 0, Py_BuildValue("s", image));
+  PyTuple_SetItem(args, 1, Py_BuildValue("O", user_data));
   result = PyObject_CallObject(pyImageSelectorCallBackFunc, args);
   if(result==NULL){
     PyErr_Print();
@@ -431,13 +432,15 @@ py_gc_selector_images_start(PyObject* self, PyObject* args)
   GcomprisBoard* cGcomprisBoard;
   PyObject* pyCallback;
   gchar* dataset;
+  void *user_data;
 
   /* Parse arguments */
   if(!PyArg_ParseTuple(args,
-		       "OsO:gc_selector_images_start",
+		       "OsOO:gc_selector_images_start",
 		       &pyGcomprisBoard,
 		       &dataset,
-		       &pyCallback))
+		       &pyCallback,
+		       &user_data))
     return NULL;
   if(!PyCallable_Check(pyCallback)) return NULL;
   cGcomprisBoard = ((pyGcomprisBoardObject*) pyGcomprisBoard)->cdata;
@@ -446,7 +449,8 @@ py_gc_selector_images_start(PyObject* self, PyObject* args)
   pyImageSelectorCallBackFunc = pyCallback;
   gc_selector_images_start(cGcomprisBoard,
 			   dataset,
-			   pyImageSelectorCallBack);
+			   pyImageSelectorCallBack,
+			   user_data);
 
   /* Create and return the result */
   Py_INCREF(Py_None);
diff --git a/src/gcompris/gcompris.h b/src/gcompris/gcompris.h
index 61819f7..bf8731e 100644
--- a/src/gcompris/gcompris.h
+++ b/src/gcompris/gcompris.h
@@ -168,10 +168,12 @@ gchar		*gc_locale_get_name(gchar *locale);
 
 void		 gc_cursor_set(guint gdk_cursor_type);
 
-typedef void     (*ImageSelectorCallBack)     (gchar* image);
+typedef void     (*ImageSelectorCallBack)     (gchar* image,
+					       void *user_context);
 void		 gc_selector_images_start (GcomprisBoard *gcomprisBoard,
-						 gchar *dataset,
-						 ImageSelectorCallBack imscb);
+					   gchar *dataset,
+					   ImageSelectorCallBack imscb,
+					   void *user_context);
 void		 gc_selector_images_stop (void);
 
 typedef void     (*FileSelectorCallBack)     (gchar *file, gchar *file_type,
diff --git a/src/gcompris/images_selector.c b/src/gcompris/images_selector.c
index 7516b53..870ba39 100644
--- a/src/gcompris/images_selector.c
+++ b/src/gcompris/images_selector.c
@@ -58,6 +58,7 @@ static GtkWidget	*canvas_image_selector; /* The scrolled right part */
 static GooCanvasItem    *image_bg_item;
 
 static ImageSelectorCallBack imageSelectorCallBack = NULL;
+static void *current_user_context = NULL;
 
 static gboolean		 display_in_progress;
 
@@ -103,7 +104,8 @@ static GtkAdjustment    *image_adj;
 
 void
 gc_selector_images_start (GcomprisBoard *gcomprisBoard, gchar *dataset,
-			  ImageSelectorCallBack iscb)
+			  ImageSelectorCallBack iscb,
+			  void *user_context)
 {
 
   GooCanvasItem *item;
@@ -120,6 +122,7 @@ gc_selector_images_start (GcomprisBoard *gcomprisBoard, gchar *dataset,
   gc_board_pause(TRUE);
 
   imageSelectorCallBack = iscb;
+  current_user_context = user_context;
 
   rootitem = goo_canvas_group_new (goo_canvas_get_root_item(gc_get_canvas()),
 				   NULL);
@@ -568,7 +571,7 @@ item_event_images_selector(GooCanvasItem *item,
   else
     {
       if(imageSelectorCallBack!=NULL)
-	imageSelectorCallBack(data);
+	imageSelectorCallBack(data, current_user_context);
 
       gc_selector_images_stop();
     }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]