Author: bcoudoin Date: Sat Feb 16 15:23:45 2008 New Revision: 3255 URL: http://svn.gnome.org/viewvc/gcompris?rev=3255&view=rev
Log: implemented the new focus system in python and ported the activities Modified: branches/gcomprixogoo/src/bargame-activity/bargame.py branches/gcomprixogoo/src/boards/py-mod-utils.c branches/gcomprixogoo/src/connect4-activity/connect4.py branches/gcomprixogoo/src/gcompris/gameutil.c branches/gcomprixogoo/src/gcompris/gameutil.h branches/gcomprixogoo/src/login-activity/login.py branches/gcomprixogoo/src/melody-activity/melody.py branches/gcomprixogoo/src/mosaic-activity/mosaic.py branches/gcomprixogoo/src/sudoku-activity/sudoku.py branches/gcomprixogoo/src/watercycle-activity/watercycle.py Modified: branches/gcomprixogoo/src/bargame-activity/bargame.py ============================================================================== --- branches/gcomprixogoo/src/bargame-activity/bargame.py (original) +++ branches/gcomprixogoo/src/bargame-activity/bargame.py Sat Feb 16 15:23:45 2008 @@ -471,20 +471,20 @@ def __init__(self, board, root, prof_image): self.board = board - self.prof_item =goocanvas.Image( + self.prof_item = goocanvas.Image( parent = root, y = 230 ) + + + def set_prof(self, prof_image): + self.prof_item.props.pixbuf = gcompris.utils.load_pixmap(prof_image) bounds = self.prof_item.get_bounds() self.prof_item.props.x = \ (gcompris.BOARD_WIDTH - bounds.x2-bounds.x1)/2 - 90 - self.prof_item.connect("button_press_event",self.event_play) # This item is clickeable and it must be seen - self.prof_item.connect("button_press_event", gcompris.utils.item_event_focus) - - def set_prof(self, prof_image): - self.prof_item.props.pixbuf = gcompris.utils.load_pixmap(prof_image) + gcompris.utils.item_focus_init(self.prof_item, None) def event_play(self, item, target, event): if ((event.type != gtk.gdk.BUTTON_PRESS) or Modified: branches/gcomprixogoo/src/boards/py-mod-utils.c ============================================================================== --- branches/gcomprixogoo/src/boards/py-mod-utils.c (original) +++ branches/gcomprixogoo/src/boards/py-mod-utils.c Sat Feb 16 15:23:45 2008 @@ -72,26 +72,28 @@ } - -/* void gc_item_focus_set(GooCanvasItem *item, gboolean focus); */ +/* gint gc_item_focus_init(GooCanvasItem *source_item, + GooCanvasItem *target_item); +*/ static PyObject* -py_gc_item_focus_set(PyObject* self, PyObject* args) +py_gc_item_focus_init(PyObject* self, PyObject* args) { PyObject* pyitem; + PyObject* pytarget; GooCanvasItem* item; - gint pyfocus; - gboolean focus; + GooCanvasItem* target = NULL; /* Parse arguments */ - if(!PyArg_ParseTuple(args, "Oi:gc_item_focus_set", &pyitem, &pyfocus)) + if(!PyArg_ParseTuple(args, "OO:gc_item_focus_init", + &pyitem, &pytarget)) return NULL; item = (GooCanvasItem*) pygobject_get(pyitem); - if(pyfocus>0) focus = TRUE; - else focus = FALSE; + if(pytarget != Py_None) + target = (GooCanvasItem*) pygobject_get(pytarget); /* Call the corresponding C function */ - gc_item_focus_set(item, focus); + gc_item_focus_init(item, target); /* Create and return the result */ Py_INCREF(Py_None); @@ -99,37 +101,6 @@ } -/* gint gc_item_focus_event(GooCanvasItem *item, - GdkEvent *event, - GooCanvasItem *dest_item); -*/ -static PyObject* -py_gc_item_focus_event(PyObject* self, PyObject* args) -{ - PyObject* pyitem; - PyObject* pytarget; - GooCanvasItem* item; - GooCanvasItem* target; - PyObject* pyevent; - GdkEvent* event; - gint result; - - /* Parse arguments */ - if(!PyArg_ParseTuple(args, "OOO:gc_item_focus_event", - &pyitem, &pytarget, &pyevent)) - return NULL; - item = (GooCanvasItem*) pygobject_get(pyitem); - target = (GooCanvasItem*) pygobject_get(pytarget); - event = (GdkEvent*) pygobject_get(pyevent); - - /* Call the corresponding C function */ - result = gc_item_focus_event(item, target, event, NULL); - - /* Create and return the result */ - return Py_BuildValue("i", result); -} - - /* void gc_item_absolute_move(GooCanvasItem *item, int x, int y); */ static PyObject* py_gc_item_absolute_move(PyObject* self, PyObject* args) @@ -341,7 +312,8 @@ /* Parse arguments */ - if(!PyArg_ParseTuple(args, "Oss:gcompris_canvas_set_property", &pyitem, &property, &value)) + if(!PyArg_ParseTuple(args, "Oss:gcompris_canvas_set_property", + &pyitem, &property, &value)) return NULL; /* pass parameter from python */ @@ -393,8 +365,7 @@ static PyMethodDef PythonGcomprisUtilsModule[] = { { "load_pixmap", py_gc_pixmap_load, METH_VARARGS, "gc_pixmap_load" }, { "find_file_absolute", py_gc_file_find_absolute, METH_VARARGS, "gc_file_find_absolute" }, - { "set_image_focus", py_gc_item_focus_set, METH_VARARGS, "gc_item_focus_set" }, - { "item_event_focus", py_gc_item_focus_event, METH_VARARGS, "gc_item_focus_event" }, + { "item_focus_init", py_gc_item_focus_init, METH_VARARGS, "gc_item_focus_init" }, { "item_absolute_move", py_gc_item_absolute_move, METH_VARARGS, "gc_item_absolute_move" }, { "item_rotate", py_gc_item_rotate, METH_VARARGS, "gc_item_rotate" }, { "item_rotate_relative", py_gc_item_rotate_relative, METH_VARARGS, "gc_item_rotate_relative" }, Modified: branches/gcomprixogoo/src/connect4-activity/connect4.py ============================================================================== --- branches/gcomprixogoo/src/connect4-activity/connect4.py (original) +++ branches/gcomprixogoo/src/connect4-activity/connect4.py Sat Feb 16 15:23:45 2008 @@ -98,7 +98,7 @@ y=350.0 ) self.prof.connect("button_press_event", self.profItemEvent, 0) - self.prof.connect("enter_notify_event", gcompris.utils.item_event_focus) + gcompris.utils.item_focus_init(self.prof, None) self.timericon = gcompris.anim.CanvasItem( gcompris.anim.Animation("connect4/sablier.txt"), self.rootitem ) Modified: branches/gcomprixogoo/src/gcompris/gameutil.c ============================================================================== --- branches/gcomprixogoo/src/gcompris/gameutil.c (original) +++ branches/gcomprixogoo/src/gcompris/gameutil.c Sat Feb 16 15:23:45 2008 @@ -175,66 +175,16 @@ } /** - * Init an item so that it has a focus - * Optionnaly, provide a target_item that will be focused - * by events on source_item. - * - */ -#define GAP 4 -void gc_item_focus_init(GooCanvasItem *source_item, - GooCanvasItem *target_item) -{ - GooCanvasItem *highlight_item; - GooCanvasBounds bounds; - - if(!target_item) - target_item = source_item; - - goo_canvas_item_get_bounds(target_item, &bounds); - - highlight_item = g_object_get_data (G_OBJECT(target_item), - "highlight_item"); - - /* Create the highlight_item */ - if(!highlight_item) - highlight_item = - goo_canvas_rect_new (goo_canvas_item_get_parent(target_item), - bounds.x1 - GAP, - bounds.y1 - GAP, - bounds.x2 - bounds.x1 + GAP*2, - bounds.y2 - bounds.y1 + GAP*2, - "stroke_color_rgba", 0xFFFFFFFFL, - "fill_color_rgba", 0xFF000090L, - "line-width", (double) 2, - "radius-x", (double) 10, - "radius-y", (double) 10, - NULL); - - g_object_set_data (G_OBJECT(target_item), "highlight_item", - highlight_item); - goo_canvas_item_lower(highlight_item, target_item); - g_object_set (highlight_item, - "visibility", GOO_CANVAS_ITEM_INVISIBLE, - NULL); - - g_signal_connect(source_item, "enter_notify_event", - (GtkSignalFunc) gc_item_focus_event, - target_item); - g_signal_connect(source_item, "leave_notify_event", - (GtkSignalFunc) gc_item_focus_event, - target_item); -} - -/** * Set the focus of the given image (highlight or not) * */ -void gc_item_focus_set(GooCanvasItem *item, gboolean focus) +static void +gc_item_focus_set(GooCanvasItem *item, gboolean focus) { GooCanvasItem *highlight_item; highlight_item = g_object_get_data (G_OBJECT(item), - "highlight_item"); + "highlight_item"); g_assert(highlight_item); switch (focus) @@ -260,7 +210,7 @@ * or the given one * */ -gint +static gint gc_item_focus_event(GooCanvasItem *item, GooCanvasItem *target, GdkEvent *event, GooCanvasItem *target_item) @@ -283,6 +233,57 @@ return FALSE; } +/** + * Init an item so that it has a focus + * Optionnaly, provide a target_item that will be focused + * by events on source_item. + * + */ +#define GAP 4 +void gc_item_focus_init(GooCanvasItem *source_item, + GooCanvasItem *target_item) +{ + GooCanvasItem *highlight_item; + GooCanvasBounds bounds; + + if(!target_item) + target_item = source_item; + + goo_canvas_item_get_bounds(target_item, &bounds); + + highlight_item = g_object_get_data (G_OBJECT(target_item), + "highlight_item"); + + /* Create the highlight_item */ + if(!highlight_item) + highlight_item = + goo_canvas_rect_new (goo_canvas_item_get_parent(target_item), + bounds.x1 - GAP, + bounds.y1 - GAP, + bounds.x2 - bounds.x1 + GAP*2, + bounds.y2 - bounds.y1 + GAP*2, + "stroke_color_rgba", 0xFFFFFFFFL, + "fill_color_rgba", 0xFF000090L, + "line-width", (double) 2, + "radius-x", (double) 10, + "radius-y", (double) 10, + NULL); + + g_object_set_data (G_OBJECT(target_item), "highlight_item", + highlight_item); + goo_canvas_item_lower(highlight_item, target_item); + g_object_set (highlight_item, + "visibility", GOO_CANVAS_ITEM_INVISIBLE, + NULL); + + g_signal_connect(source_item, "enter_notify_event", + (GtkSignalFunc) gc_item_focus_event, + target_item); + g_signal_connect(source_item, "leave_notify_event", + (GtkSignalFunc) gc_item_focus_event, + target_item); +} + /* * Return a new copy of the given string in which it has * changes '\''n' to '\n'. Modified: branches/gcomprixogoo/src/gcompris/gameutil.h ============================================================================== --- branches/gcomprixogoo/src/gcompris/gameutil.h (original) +++ branches/gcomprixogoo/src/gcompris/gameutil.h Sat Feb 16 15:23:45 2008 @@ -46,10 +46,6 @@ RsvgHandle *gc_rsvg_load(const gchar *format, ...); void gc_item_focus_init(GooCanvasItem *source_item, GooCanvasItem *target_item); -void gc_item_focus_set(GooCanvasItem *item, gboolean focus); -gint gc_item_focus_event(GooCanvasItem *item, GooCanvasItem *target, - GdkEvent *event, - GooCanvasItem *dest_item); gchar *convertUTF8Toisolat1(gchar * text); void gc_item_absolute_move(GooCanvasItem *item, int x, int y); Modified: branches/gcomprixogoo/src/login-activity/login.py ============================================================================== --- branches/gcomprixogoo/src/login-activity/login.py (original) +++ branches/gcomprixogoo/src/login-activity/login.py Sat Feb 16 15:23:45 2008 @@ -277,7 +277,7 @@ y = y - button_pixbuf.get_height()/2, ) # This item is clickeable and it must be seen - item.connect("button_press_event", gcompris.utils.item_event_focus) + gcompris.utils.item_focus_init(item, None) item.connect("button_press_event", self.letter_click_event, (users, start_filter + letter)) @@ -339,7 +339,7 @@ y = y - button_pixbuf.get_height()/2, ) # This item is clickeable and it must be seen - item.connect("button_press_event", gcompris.utils.item_event_focus) + gcompris.utils.item_focus_init(item, None) item.connect("button_press_event", self.name_click_event, user) Modified: branches/gcomprixogoo/src/melody-activity/melody.py ============================================================================== --- branches/gcomprixogoo/src/melody-activity/melody.py (original) +++ branches/gcomprixogoo/src/melody-activity/melody.py Sat Feb 16 15:23:45 2008 @@ -163,7 +163,7 @@ ) self.switch_item.connect("button_press_event", self.switch_item_event) # This item is clickeable and it must be seen - self.switch_item.connect("button_press_event", gcompris.utils.item_event_focus) + gcompris.utils.item_focus_init(self.switch_item, None) # Put the sound buttons @@ -178,8 +178,7 @@ ) self.sound_item.connect("button_press_event", self.sound_item_event, i) # This item is clickeable and it must be seen - self.sound_item.connect("button_press_event", - gcompris.utils.item_event_focus) + gcompris.utils.item_focus_init(self.sound_item, None) self.bang_item = goocanvas.Image( Modified: branches/gcomprixogoo/src/mosaic-activity/mosaic.py ============================================================================== --- branches/gcomprixogoo/src/mosaic-activity/mosaic.py (original) +++ branches/gcomprixogoo/src/mosaic-activity/mosaic.py Sat Feb 16 15:23:45 2008 @@ -274,7 +274,8 @@ y = orig_y + y * (self.palette_item_height + gap_y)) if not colored: - item.connect("button_press_event", self.set_focus_item_event, (i, palette)) + item.connect("button_press_event", + self.set_focus_item_event, (i, palette)) self.user_list.append((-1, -1)) else: self.target_list.append((color_index_x, color_index_y)) @@ -314,7 +315,7 @@ x = coord_x, y = coord_y) - item.connect("button_press_event", gcompris.utils.item_event_focus) + gcompris.utils.item_focus_init(item, None) item.connect("button_press_event", self.set_color_item_event, (palette_x, palette_y, coord_x, coord_y)) Modified: branches/gcomprixogoo/src/sudoku-activity/sudoku.py ============================================================================== --- branches/gcomprixogoo/src/sudoku-activity/sudoku.py (original) +++ branches/gcomprixogoo/src/sudoku-activity/sudoku.py Sat Feb 16 15:23:45 2008 @@ -454,7 +454,7 @@ item.connect("button_press_event", self.symbol_item_event, valid_chars[y]) # This item is clickeable and it must be seen - item.connect("button_press_event", gcompris.utils.item_event_focus) + gcompris.utils.item_focus_init(item, None) # Select the first item if y == 0: @@ -582,7 +582,7 @@ if(not text): item.props.visibility = goocanvas.ITEM_INVISIBLE # This item is clickeable and it must be seen - item.connect("enter_notify_event", gcompris.utils.item_event_focus) + gcompris.utils.item_focus_init(item, None) item.connect("button_press_event", self.hide_symbol_event, (x, y)) # Modified: branches/gcomprixogoo/src/watercycle-activity/watercycle.py ============================================================================== --- branches/gcomprixogoo/src/watercycle-activity/watercycle.py (original) +++ branches/gcomprixogoo/src/watercycle-activity/watercycle.py Sat Feb 16 15:23:45 2008 @@ -107,7 +107,7 @@ ) self.sunitem.connect("button_press_event", self.sun_item_event) # This item is clickeable and it must be seen - self.sunitem.connect("button_press_event", gcompris.utils.item_event_focus) + gcompris.utils.item_focus_init(self.sunitem, None) self.sun_direction = -1 self.sun_on = 0 @@ -155,7 +155,7 @@ self.clouditem.props.visibility = goocanvas.ITEM_INVISIBLE self.clouditem.connect("button_press_event", self.cloud_item_event) # This item is clickeable and it must be seen - self.clouditem.connect("button_press_event", gcompris.utils.item_event_focus) + gcompris.utils.item_focus_init(self.clouditem, None) self.cloud_on = 0 # The vapor _______________________________________________ SVN-commits-list mailing list (read only) http://mail.gnome.org/mailman/listinfo/svn-commits-list Want to limit the commits to a few modules? Go to above URL, log in to edit your options and select the modules ('topics') you want. Module maintainer? It is possible to set the reply-to to your development mailing list. Email [EMAIL PROTECTED] if interested.