Python wrapper for Gcompris

Ir. Olivier Samyn

Revision History
Revision 0.1February 2003
Revision 0.2April 2003
Revision 0.3January 2004

Table of Contents

Notes about this wrapper
Python board structure
GcomprisBoard structure mapping
gcompris.h functions and constants Mapping
Functions mapping
GComprisBarFlags enum mapping
Misc constants mapping
Colors constants mapping
Fonts constants mapping
Board font constants mapping
Cursor constants mapping
gameutil.h functions and constants Mapping
Functions mapping
Constants mapping
bonus.h functions and constants Mapping
Functions mapping
Constants mapping
score.h functions and constants Mapping
Functions mapping
Constants mapping
sound.h functions and constants Mapping
Functions mapping
Constants mapping
timer.h functions and constants Mapping
Functions mapping
Constants mapping

Notes about this wrapper

Generaly speaking, all C gcompris_xxx functions are wrapped to a corresponding gcompris.xxx function; parameters and return types remains the same. Some structures have also been wrapped. See below particular notes about this.

The wrapped functions are divided into packages. Every package correponds to a gcompris header file (gameutil.h, score.h, ...)

For each package/header not all functions have been wrapped. Only functions that are used/usefull for plugins are wrapped.

Notice also that not all functions have been tested (with time and new python plugins implemented they will be, but...). The wrappers have been written, they compiles, but there is no warranty on their behaviour... I you find a bug report it!

Python board structure

Each board written in python must contains a class which name is "Gcompris_xxx" where xxx is the name of the board. Let's take an example: I made a gcompris board written in python and called "pythontest".

For this board there is a gcompris pythontest.xml file containing "pythontest" for the board name and "pythonboard" for the board type. There's also a pythontest.py file containing the board code. And to finish, this file contains a "Gcompris_pythontest" class definition which in turns contains the needed gcompris board functions.

The class defined in the python board must contains the following methods:

  • __init__(self, gcomprisBoard)
  • start(self)
  • end(self)
  • ok(self)
  • repeat(self)
  • config(self)
  • key_press(self, keyval)
  • pause(self, pause)
  • set_level(self, level)

For the method role and use, please consult the sample pythontest.py board and other C boards.

GcomprisBoard structure mapping

An instance of this structure in Python will act like an instance of the C one. Here a some Python call samples:

...
  gcomprisBoard.level = 1
  gcomprisBoard.maxlevel = 1
...
  gcompris.bar_start(gcomprisBoard.canvas)
...

Here are the Python structure member name and type, and a note indicating if the attribute is readeable and/or writable.

Structure memberTypeReadableWritable
typestringYN
board_readybooleanYN
modestringYN
namestringYN
titlestringYN
descriptionstringYN
icon_namestringYN
authorstringYN
boarddirstringYN
filenamestringYN
difficultystringYN
mandatory_sound_filestringYN
sectionstringYN
menuposotionstringYN
prerequisitestringYN
goalstringYN
manualstringYN
creditstringYN
widthintYN
heightintYN
canvasgnome.canvas.CanvasYN
previous_boardGcomprisBoardYN
levelintYY
maxlevelintYY
sublevelintYY
number_of_sublevelintYY

gcompris.h functions and constants Mapping

Functions mapping

Python functionC equivalentNotes
gcompris.end_board()void gcompris_end_board(void) 
gcompris.bar_start(gnomeCanvas)void gcompris_bar_start(GnomeCanvas *theCanvas) 
gcompris.set_background(gnomeCanvasGroup, file)GnomeCanvasItem *gcompris_set_background(GnomeCanvasGroup *parent, gchar *file)return a gnome.canvas.CanvasItem object
gcompris.bar_set_level(gcomprisBoard)void gcompris_bar_set_level(GcomprisBoard *gcomprisBoard) 
gcompris.bar_set_repeat_icon(pixmap)void gcompris_bar_set_repeat_icon(GdkPixbuf *pixmap) 
gcompris.bar_set(flags)void gcompris_bar_set(const GComprisBarFlags flags) 
gcompris.bar_hide(hide)void gcompris_bar_hide(gboolean hide) 
gcompris.board_has_help(gcomprisBoard)gboolean gcompris_board_has_help(GcomprisBoard *gcomprisBoard)return a boolean
gcompris.help_start(gcomprisBoard)void gcompris_help_start(GcomprisBoard *gcomprisBoard) 
gcompris.help_stop()void gcompris_help_stop(void) 
gcompris.get_canvas()GnomeCanvas* gcompris_get_canvas()return a gnome.canvas.Canvas
gcompris.get_window()GtkWidget* gcompris_get_window(void)return a gtk.Widget
gcompris.get_locale()gchar* gcompris_get_locale(void)return a string
gcompris.set_locale(locale)void gcompris_set_locale(gchar *locale) 
gcompris.set_cursor(cursor_type)void gcompris_set_cursor(guint gdk_cursor_type) 
gcompris.images_selector_start(gcomprisBoard, dataset, callback)void gcompris_images_selector_start (GcomprisBoard *gcomprisBoard, gchar *dataset, ImageSelectorCallBack imscb)The callback must be a callable object
gcompris.images_selector_stop()void gcompris_images_selector_stop(void) 
gcompris.exit()void gcompris_exit(void) 
gcompris.log_set_reason (gcomprisBoard, comment)gcompris_log_set_reason (GcomprisBoard *gcomprisBoard, gchar *comment) 
gcompris.log_end (gcomprisBoard, status)gcompris_log_end (GcomprisBoard *gcomprisBoard, gchar *status) 

GComprisBarFlags enum mapping

Python constantC equivalent
gcompris.BAR_LEVELGCOMPRIS_BAR_LEVEL
gcompris.BAR_OKGCOMPRIS_BAR_OK
gcompris.BAR_REPEATGCOMPRIS_BAR_REPEAT
gcompris.BAR_CONFIGGCOMPRIS_BAR_CONFIG
gcompris.BAR_ABOUTGCOMPRIS_BAR_ABOUT

Misc constants mapping

Python constantC equivalent
gcompris.BOARD_HEIGHTBOARDHEIGHT
gcompris.BOARD_WIDTHBOARDWIDTH
gcompris.BAR_HEIGHTBAR_HEIGHT
gcompris.DEFAULT_SKINDEFAULT_SKIN

Colors constants mapping

Python constantC equivalent
gcompris.COLOR_TITLECOLOR_TITLE
gcompris.COLOR_TEXT_BUTTONCOLOR_TEXT_BUTTON
gcompris.COLOR_CONTENTCOLOR_CONTENT
gcompris.COLOR_SUBTITLECOLOR_SUBTITLE

Fonts constants mapping

Python constantC equivalent
gcompris.FONT_TITLEFONT_TITLE
gcompris.FONT_TITLE_FALLBACKFONT_TITLE_FALLBACK
gcompris.FONT_SUBTITLEFONT_SUBTITLE
gcompris.FONT_SUBTITLE_FALLBACKFONT_SUBTITLE_FALLBACK
gcompris.FONT_CONTENTFONT_CONTENT
gcompris.FONT_CONTENT_FALLBACKFONT_CONTENT_FALLBACK

Board font constants mapping

Python constantC equivalent
gcompris.FONT_BOARD_TINYFONT_BOARD_TINY
gcompris.FONT_BOARD_SMALLFONT_BOARD_SMALL
gcompris.FONT_BOARD_MEDIUMFONT_BOARD_MEDIUM
gcompris.FONT_BOARD_BIGFONT_BOARD_BIG
gcompris.FONT_BOARD_BIG_BOLDFONT_BOARD_BIG_BOLD
gcompris.FONT_BOARD_FIXEDFONT_BOARD_FIXED
gcompris.FONT_BOARD_TITLEFONT_BOARD_TITLE
gcompris.FONT_BOARD_TITLE_BOLDFONT_BOARD_TITLE_BOLD
gcompris.FONT_BOARD_HUGEFONT_BOARD_HUGE
gcompris.FONT_BOARD_HUGE_BOLDFONT_BOARD_HUGE_BOLD

Cursor constants mapping

Python constantC equivalent
gcompris.CURSOR_FIRST_CUSTOMGCOMPRIS_FIRST_CUSTOM_CURSOR
gcompris.CURSOR_BIG_RED_ARROWGCOMPRIS_BIG_RED_ARROW_CURSOR
gcompris.CURSOR_BIRDGCOMPRIS_BIRD_CURSOR
gcompris.CURSOR_LINEGCOMPRIS_LINE_CURSOR
gcompris.CURSOR_FILLRECTGCOMPRIS_FILLRECT_CURSOR
gcompris.CURSOR_RECTGCOMPRIS_RECT_CURSOR
gcompris.CURSOR_FILLCIRCLEGCOMPRIS_FILLCIRCLE_CURSOR
gcompris.CURSOR_CIRCLEGCOMPRIS_CIRCLE_CURSOR
gcompris.CURSOR_DELGCOMPRIS_DEL_CURSOR
gcompris.CURSOR_FILLGCOMPRIS_FILL_CURSOR
gcompris.CURSOR_SELECTGCOMPRIS_SELECT_CURSOR
gcompris.CURSOR_DEFAULTGCOMPRIS_DEFAULT_CURSOR

gameutil.h functions and constants Mapping

Functions mapping

Python functionC equivalentNotes
gcompris.utils.load_number_pixmap(number)GdkPixbuf *gcompris_load_number_pixmap(char number)return a gtk.gdk.Pixbuf
gcompris.utils.image_to_skin(imagename)gchar *gcompris_image_to_skin(gchar *imagename)return a string
gcompris.utils.load_skin_pixmap(pixmapfile)GdkPixbuf *gcompris_load_skin_pixmap(char *pixmapfile)return a gtk.gdk.Pixbuf
gcompris.utils.load_pixmap(pixmapfile)GdkPixbuf *gcompris_load_pixmap(char *pixmapfile)return a gtk.gdk.Pixbuf
gcompris.utils.set_image_focus(item, focus)void gcompris_set_image_focus(GnomeCanvasItem *item, gboolean focus) 
gcompris.utils.item_event_focus(item, event, dest_item)gint gcompris_item_event_focus(GnomeCanvasItem *item, GdkEvent *event, GnomeCanvasItem *dest_item)return an integer
gcompris.utils.item_absolute_move(item, x, y)void item_absolute_move(GnomeCanvasItem *item, int x, int y) 
gcompris.utils.item_rotate(item, angle)void item_rotate(GnomeCanvasItem *item, double angle) 
gcompris.utils.item_rotate_relative(item, angle)void item_rotate_relative(GnomeCanvasItem *item, double angle) 
gcompris.utils.item_rotate_with_center(item, angle, x, y)void item_rotate_with_center(GnomeCanvasItem *item, double angle, int x, int y) 
gcompris.utils.item_rotate_relative_with_center(item, angle, x, y)void item_rotate_relative_with_center(GnomeCanvasItem *item, double angle, int x, int y) 
gcompris.utils.dialog(str, callback)void gcompris_dialog(gchar *str, DialogBoxCallBack callback)The callback must be a callable object
gcompris.utils.load_pixmap_asset(dataset, categories, mimetype, name)GdkPixbuf *gcompris_load_pixmap_asset(gchar *dataset, gchar* categories, gchar* mimetype, gchar* name)return a gtk.gdk.Pixbuf
gcompris.utils.get_asset_file(dataset, categories, mimetype, name)gchar *gcompris_get_asset_file(gchar *dataset, gchar* categories, gchar* mimetype, gchar* name)return a string

Constants mapping

There is no constants in this package.

bonus.h functions and constants Mapping

Functions mapping

Python functionC equivalentNotes
gcompris.bonus.display(gamewon, bonus_id)void gcompris_display_bonus(int gamewon, int bonus_id) 
gcompris.bonus.board_finished(type)void board_finished(int type) 

Constants mapping

Python constantC equivalent
gcompris.bonus.TIME_CLICK_TOTIME_CLICK_TO_BONUS
gcompris.bonus.RANDOMBONUS_RANDOM
gcompris.bonus.SMILEYBONUS_SMILEY
gcompris.bonus.FLOWERBONUS_FLOWER
gcompris.bonus.LASTBONUS_LAST
gcompris.bonus.FINISHED_RANDOMBOARD_FINISHED_RANDOM
gcompris.bonus.FINISHED_TUXPLANEBOARD_FINISHED_TUXPLANE
gcompris.bonus.FINISHED_TUXLOCOBOARD_FINISHED_TUXLOCO
gcompris.bonus.FINISHED_TOOMANYERRORSBOARD_FINISHED_TOOMANYERRORS
gcompris.bonus.FINISHED_LASTBOARD_FINISHED_LAST

score.h functions and constants Mapping

Functions mapping

Python functionC equivalentNotes
gcompris.score.start(style, x, y, max)void gcompris_score_start(ScoreStyleList style, guint x, guint y, guint max) 
gcompris.score.end()void gcompris_score_end() 
gcompris.score.set(value)void gcompris_score_set(guint value) 

Constants mapping

Python constantC equivalent
gcompris.score.STYLE_NOTESCORESTYLE_NOTE
gcompris.score.STYLE_LIFESCORESTYLE_LIFE
gcompris.score.LASTSCORE_LAST

sound.h functions and constants Mapping

Functions mapping

Python functionC equivalentNotes
gcompris.sound.play_ogg_list(list)void gcompris_play_ogg_list( GList* files )The list argument is a GList
gcompris.sound.play_ogg(list)void gcompris_play_ogg(char *, ...)The list argument is a python list containing strings

Constants mapping

There is no constants in this package.

timer.h functions and constants Mapping

Functions mapping

Python functionC equivalentNotes
gcompris.timer.display(x, y, type, second, callback)void gcompris_timer_display (int x, int y, TimerList type, int second, GcomprisTimerEnd gcomprisTimerEnd);The callback must be a callable object
gcompris.timer.add(second)void gcompris_timer_add(int second) 
gcompris.timer.end()void gcompris_timer_end(void) 
gcompris.timer.get_remaining()guint gcompris_timer_get_remaining()Return an integer
gcompris.timer.pause(pause)void gcompris_timer_pause(gboolean pause) 

Constants mapping

Python constantC equivalent
gcompris.timer.TEXTGCOMPRIS_TIMER_TEXT
gcompris.timer.SANDGCOMPRIS_TIMER_SAND
gcompris.timer.BALLOONGCOMPRIS_TIMER_BALLOON
gcompris.timer.CLOCKGCOMPRIS_TIMER_CLOCK