Ir
Olivier
Samyn
osamyn@ulb.ac.be
February 2003
0.1
February 2003
0.2
April 2003
0.3
January 2004
0.4
January 2005
0.5
December 2006
0.6
July 2007
Python wrapper for Gcompris
Notes about this wrapper
Generaly speaking, all C gc_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 member
Type
Readable
Writable
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 function
C equivalent
Notes
gcompris.end_board()
void gc_board_end(void)
gcompris.bar_start(gnomeCanvas)
void gc_bar_start(GnomeCanvas *theCanvas)
gcompris.set_background(gnomeCanvasGroup, file)
GnomeCanvasItem *gc_set_background(GnomeCanvasGroup *parent, gchar *file)
return a gnome.canvas.CanvasItem object
gcompris.bar_set_level(gcomprisBoard)
void gc_bar_set_level(GcomprisBoard *gcomprisBoard)
gcompris.bar_set_repeat_icon(pixmap)
void gc_bar_set_repeat_icon(GdkPixbuf *pixmap)
gcompris.bar_set(flags)
void gc_bar_set(const GComprisBarFlags flags)
gcompris.bar_hide(hide)
void gc_bar_hide(gboolean hide)
gcompris.get_canvas()
GnomeCanvas* gc_get_canvas()
return a gnome.canvas.Canvas
gcompris.get_window()
GtkWidget* gc_get_window(void)
return a gtk.Widget
gcompris.get_locale()
gchar* gc_locale_get(void)
return a string
gcompris.set_locale(locale)
void gc_locale_set(gchar *locale)
gcompris.set_cursor(cursor_type)
void gc_cursor_set(guint gdk_cursor_type)
gcompris.images_selector_start(gcomprisBoard, dataset, callback)
void gc_selector_images_start (GcomprisBoard *gcomprisBoard, gchar *dataset, ImageSelectorCallBack imscb)
The callback must be a callable object
gcompris.images_selector_stop()
void gc_selector_images_stop(void)
gcompris.exit()
void gc_exit(void)
gcompris.log_set_reason (gcomprisBoard, expected, got)
gc_log_set_reason (GcomprisBoard *gcomprisBoard, gchar *expected, gchar *got)
gcompris.log_end (gcomprisBoard, status)
gc_log_end (GcomprisBoard *gcomprisBoard, gchar *status)
gcompris.file_selector_load(gcomprisBoard, rootdir, file_types, callback)
void gc_selector_file_load (GcomprisBoard *gcomprisBoard, gchar *rootdir, gchar *file_types, FileSelectorCallBack fscb)
The callback must be a callable object
gcompris.file_selector_save(gcomprisBoard, rootdir, file_types, callback)
void gc_selector_file_save(GcomprisBoard *gcomprisBoard, gchar *rootdir,gchar *file_types, FileSelectorCallBack fscb)
The callback must be a callable object
gcompris.file_selector_stop()
void gc_selector_file_stop(void)
gcompris.get_database()
gchar* gc_db_get_filename(void)
return the filename (string) of the database (fullpath)
GComprisBarFlags enum mapping
Python constant
C equivalent
gcompris.BAR_LEVEL
GCOMPRIS_BAR_LEVEL
gcompris.BAR_OK
GCOMPRIS_BAR_OK
gcompris.BAR_REPEAT
GCOMPRIS_BAR_REPEAT
gcompris.BAR_REPEAT_ICON
GCOMPRIS_BAR_REPEAT_ICON
gcompris.BAR_CONFIG
GCOMPRIS_BAR_CONFIG
gcompris.BAR_ABOUT
GCOMPRIS_BAR_ABOUT
Misc constants mapping
Python constant
C equivalent
gcompris.BOARD_HEIGHT
BOARDHEIGHT
gcompris.BOARD_WIDTH
BOARDWIDTH
gcompris.BAR_HEIGHT
BAR_HEIGHT
gcompris.DEFAULT_SKIN
DEFAULT_SKIN
Colors constants mapping
Python constant
C equivalent
gcompris.COLOR_TITLECOLOR_TITLE
gcompris.COLOR_TEXT_BUTTONCOLOR_TEXT_BUTTON
gcompris.COLOR_CONTENTCOLOR_CONTENT
gcompris.COLOR_SUBTITLECOLOR_SUBTITLE
Fonts constants mapping
Python constant
C 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 constant
C 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 constant
C equivalent
gcompris.CURSOR_FIRST_CUSTOM
GCOMPRIS_FIRST_CUSTOM_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 function
C equivalent
Notes
gcompris.utils.image_to_skin(imagename)
gchar *gc_skin_image_get(gchar *imagename)
return a string
gcompris.skin.load_pixmap(pixmapfile)
GdkPixbuf *gc_skin_pixmap_load(char *pixmapfile)
return a gtk.gdk.Pixbuf
gcompris.utils.load_pixmap(pixmapfile)
GdkPixbuf *gc_pixmap_load(char *pixmapfile)
return a gtk.gdk.Pixbuf
gcompris.utils.find_file_absolute(file)
char *gc_file_find_absolute(char *file)
return a string
gcompris.utils.set_image_focus(item, focus)
void gc_item_focus_set(GnomeCanvasItem *item, gboolean focus)
gcompris.utils.item_event_focus(item, event, dest_item)
gint gc_item_focus_event(GnomeCanvasItem *item, GdkEvent *event, GnomeCanvasItem *dest_item)
return an integer
gcompris.utils.item_absolute_move(item, x, y)
void gc_item_absolute_move(GnomeCanvasItem *item, int x, int y)
gcompris.utils.item_rotate(item, angle)
void gc_item_rotate(GnomeCanvasItem *item, double angle)
gcompris.utils.item_rotate_relative(item, angle)
void gc_item_rotate_relative(GnomeCanvasItem *item, double angle)
gcompris.utils.item_rotate_with_center(item, angle, x, y)
void gc_item_rotate_with_center(GnomeCanvasItem *item, double angle, int x, int y)
gcompris.utils.item_rotate_relative_with_center(item, angle, x, y)
void gc_item_rotate_relative_with_center(GnomeCanvasItem *item, double angle, int x, int y)
gcompris.utils.dialog(str, callback)
void gc_dialog(gchar *str, DialogBoxCallBack callback)
The callback must be a callable object
gcompris.utils.dialog_close()
void gc_dialog_close()
Constants mapping
There is no constants in this package.
bonus.h functions and constants Mapping
Functions mapping
Python function
C equivalent
Notes
gcompris.bonus.display(BonusStatusList, BonusList)
void gc_bonus_display(BonusStatusList, BonusList)
gcompris.bonus.board_finished(BoardFinishedList)
void gc_bonus_end_display(BoardFinishedList)
Constants mapping (BonusStatusList)
Python constant
C equivalent
gcompris.bonus.LOOSE
BOARD_LOOSE
gcompris.bonus.WIN
BOARD_WIN
gcompris.bonus.DRAW
BOARD_DRAW
Constants mapping (BonusList)
Python constant
C equivalent
gcompris.bonus.TIME_CLICK_TO
TIME_CLICK_TO_BONUS
gcompris.bonus.RANDOM
BONUS_RANDOM
gcompris.bonus.SMILEY
BONUS_SMILEY
gcompris.bonus.FLOWER
BONUS_FLOWER
gcompris.bonus.TUX
BONUS_TUX
gcompris.bonus.GNU
BONUS_TUX
gcompris.bonus.LION
BONUS_LION
Constants mapping (BoardFinishedList)
Python constant
C equivalent
gcompris.bonus.FINISHED_RANDOM
BOARD_FINISHED_RANDOM
gcompris.bonus.FINISHED_TUXPLANE
BOARD_FINISHED_TUXPLANE
gcompris.bonus.FINISHED_TUXLOCO
BOARD_FINISHED_TUXLOCO
gcompris.bonus.FINISHED_TOOMANYERRORS
BOARD_FINISHED_TOOMANYERRORS
score.h functions and constants Mapping
Functions mapping
Python function
C equivalent
Notes
gcompris.score.start(style, x, y, max)
void gc_score_start(ScoreStyleList style, guint x, guint y, guint max)
gcompris.score.end()
void gc_score_end()
gcompris.score.set(value)
void gc_score_set(guint value)
Constants mapping
Python constant
C equivalent
gcompris.score.STYLE_NOTE
SCORESTYLE_NOTE
gcompris.score.STYLE_LIFE
SCORESTYLE_LIFE
sound.h functions and constants Mapping
Functions mapping
Python function
C equivalent
Notes
gcompris.sound.play_ogg_list(list)
void gc_sound_play_ogg_list( GList* files )
The list argument is a GList
gcompris.sound.play_ogg(list)
void gc_sound_play_ogg(char *, ...)
The list argument is a python list containing strings
gcompris.sound.play_ogg_cb(list)
void gc_sound_play_ogg_cb((const gchar *file, GcomprisSoundCallback cb)
The list argument is a python string and a function callback. It will be called once the sound has been played.
Constants mapping
There is no constants in this package.
timer.h functions and constants Mapping
Functions mapping
Python function
C equivalent
Notes
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 gc_timer_add(int second)
gcompris.timer.end()
void gc_timer_end(void)
gcompris.timer.get_remaining()
guint gc_timer_get_remaining()
Return an integer
gcompris.timer.pause(pause)
void gc_timer_pause(gboolean pause)
Constants mapping
Python constant
C equivalent
gcompris.timer.TEXT
GCOMPRIS_TIMER_TEXT
gcompris.timer.SAND
GCOMPRIS_TIMER_SAND
gcompris.timer.BALLOON
GCOMPRIS_TIMER_BALLOON
gcompris.timer.CLOCK
GCOMPRIS_TIMER_CLOCK
anim.h structures Mapping
The gcompris.anim module supplies two objects, Animation and CanvasItems, corresponding to GcomprisAnimation and GcomprisAnimCanvasItem respectively.
Animation
The Animation object represents a set of animation files loaded into memory; it has no methods or members, only a constructor and a destructor. The constructor takes a single argument, the name of a text file containing a space-separated list of animation files. Each animation file in the text file corresponds to an animation state; the animations states are numbered from 0 to n-1.
CanvasItem
The CanvasItem object is a bit more interesting than the Animation object. It represents an active instance of an animation file. Its constructor takes two arguments, an Animation and a GnomeCanvasGroup (the parent of the desired active animation).
Members
Structure member
Type
Readable
Writable
gnome_canvas
gnome.canvas.CanvasPixbuf
Y
N
num_states
int
Y
N
Functions
Python function
C equivalent
Notes
gcompris.anim.CanvasItem.setState(int)
gc_anim_set_state(GcomprisAnimCanvasItem*, int)