Commit d57bea10 authored by Yves Combe's avatar Yves Combe
Browse files

Uses GtkIMContext to handle correctly input in all languages. All boards using...

Uses GtkIMContext to handle correctly input in all languages. All boards using key_press are now broken.
anim.py and gnumch.py are fixed.
parent 0e4e93e6
2005-09-19 Yves Combe <yves@ycombe.net>
Uses GtkIMContext to handle correctly input in all languages. All boards using key_press are now broken.
anim.py and gnumch.py are fixed.
* src/boards/algebra.c: (key_press):
* src/boards/draw.c: (key_press):
* src/boards/enumerate.c: (key_press):
* src/boards/gletters.c: (key_press):
* src/boards/maze.c: (key_press), (key_press_2D_relative),
(key_press_3D):
* src/boards/memory.c: (start_board):
* src/boards/paratrooper.c: (key_press):
* src/boards/planegame.c: (key_press):
* src/boards/py-gcompris-properties.c:
(pyGcomprisPropertiesType_getattr):
* src/boards/py-mod-gcompris.c: (py_gcompris_im_reset):
* src/boards/python.c: (pythonboard_key_press):
* src/boards/python/administration.py:
* src/boards/python/algorithm.py:
* src/boards/python/anim.py:
* src/boards/python/ballcatch.py:
* src/boards/python/bargame.py:
* src/boards/python/connect4.py:
* src/boards/python/followline.py:
* src/boards/python/gnumch.py:
* src/boards/python/hexagon.py:
* src/boards/python/login.py:
* src/boards/python/melody.py:
* src/boards/python/pythontest.py:
* src/boards/python/redraw.py:
* src/boards/python/searace.py:
* src/boards/python/sudoku.py:
* src/boards/python/tuxpaint.py:
* src/boards/python/watercycle.py:
* src/boards/reversecount.c: (key_press):
* src/boards/shapegame.c: (key_press):
* src/boards/smallnumbers.c: (key_press):
* src/boards/target.c: (key_press):
* src/boards/wordsgame.c: (key_press):
* src/gcompris/Makefile.am:
* src/gcompris/gcompris.c: (board_widget_key_press_callback),
(popup_menu_detach), (setup_window), (gcompris_init):
* src/gcompris/gcompris.h:
* src/gcompris/gcompris_db.h:
* src/gcompris/plugin.h:
* src/gcompris/properties.h:
2005-09-18 Bruno coudoin <bruno.coudoin@free.fr>
Fixed gcompris2spip to work with spip 1.8.2
......
/* gcompris - algebra.c
*
* Time-stamp: <2005/07/01 23:09:38 yves>
* Time-stamp: <2005/09/18 20:31:25 yves>
*
* Copyright (C) 2000 Bruno Coudoin
*
......@@ -72,7 +72,7 @@ static void pause_board (gboolean pause);
static void end_board (void);
static gboolean is_our_board (GcomprisBoard *gcomprisBoard);
static void set_level (guint level);
static gint key_press(guint keyval);
static gint key_press(guint keyval, gchar *commit_str, gchar *preedit_str);
static void process_ok(void);
static GnomeCanvasItem *algebra_create_item(GnomeCanvasGroup *parent);
......@@ -215,8 +215,15 @@ set_level (guint level)
}
}
static gint key_press(guint keyval)
static gint key_press(guint keyval, gchar *commit_str, gchar *preedit_str)
{
if (preedit_str)
return;
g_warning("key_press: %d %s %s %s", keyval, gdk_keyval_name (keyval), commit_str, preedit_str);
guint c;
gboolean stop = FALSE;
......
......@@ -177,7 +177,7 @@ static guint ext_colorlist [] =
static void start_board (GcomprisBoard *agcomprisBoard);
static void pause_board (gboolean pause);
static void end_board (void);
static gint key_press(guint keyval);
static gint key_press(guint keyval, gchar *commit_str, gchar *preedit_str);
static gboolean is_our_board (GcomprisBoard *gcomprisBoard);
static void config(void);
......@@ -307,7 +307,7 @@ end_board ()
}
/* Get the user keys to use with the text tool */
static gint key_press(guint keyval)
static gint key_press(guint keyval, gchar *commit_str, gchar *preedit_str)
{
char str[2];
char utf8char[6];
......
......@@ -29,7 +29,7 @@ static GcomprisBoard *gcomprisBoard = NULL;
static gboolean board_paused = TRUE;
static void start_board (GcomprisBoard *agcomprisBoard);
static gint key_press(guint keyval);
static gint key_press(guint keyval, gchar *commit_str, gchar *preedit_str);
static void pause_board (gboolean pause);
static void end_board (void);
static void process_ok(void);
......@@ -168,7 +168,7 @@ static void end_board ()
}
/* Get the user keys to use to get the answer */
static gint key_press(guint keyval)
static gint key_press(guint keyval, gchar *commit_str, gchar *preedit_str)
{
char str[2];
GnomeCanvasItem *item = NULL;
......
/* gcompris - gletters.c
*
* Time-stamp: <2005/08/28 12:16:42 yves>
* Time-stamp: <2005/09/15 00:21:33 yves>
*
* Copyright (C) 2000 Bruno Coudoin
*
......@@ -101,7 +101,7 @@ static void pause_board (gboolean pause);
static void end_board (void);
static gboolean is_our_board (GcomprisBoard *gcomprisBoard);
static void set_level (guint level);
static gint key_press(guint keyval);
static gint key_press(guint keyval, gchar *commit_str, gchar *preedit_str);
static void gletter_config_start(GcomprisBoard *agcomprisBoard,
GcomprisProfile *aProfile);
static void gletter_config_stop(void);
......@@ -427,7 +427,7 @@ gint is_falling_letter(char *utfchar) {
return FALSE;
}
static gint key_press(guint keyval) {
static gint key_press(guint keyval, gchar *commit_str, gchar *preedit_str) {
char lcStr[6], ucStr[6];
char utf8char[6], keyChar[6], mapChar[6];
gchar list_of_letters[255];
......
......@@ -87,7 +87,7 @@ static GnomeCanvasItem *maze_create_item(GnomeCanvasGroup *parent);
static void maze_destroy_all_items(void);
static void maze_next_level(void);
static void set_level (guint level);
static gint key_press(guint keyval);
static gint key_press(guint keyval, gchar *commit_str, gchar *preedit_str);
/*--------------------*/
static void draw_a_rect(GnomeCanvasGroup *group, int x1, int y1, int x2, int y2, char *color);
static void draw_a_line(GnomeCanvasGroup *group, int x1, int y1, int x2, int y2, guint32 color);
......@@ -120,8 +120,8 @@ static eyepos_t eye_pos_x=0, eye_pos_y=0, eye_pos_z=0;
static void threeDdisplay();
static void twoDdisplay();
static void draw3D();
static gint key_press_3D(guint keyval);
static gint key_press_2D_relative(guint keyval);
static gint key_press_3D(guint keyval, gchar *commit_str, gchar *preedit_str);
static gint key_press_2D_relative(guint keyval, gchar *commit_str, gchar *preedit_str);
/*----------------------*/
/* Description of this plugin */
......@@ -876,16 +876,16 @@ static void one_step(guint richting)
}
}
static gint key_press(guint keyval)
static gint key_press(guint keyval, gchar *commit_str, gchar *preedit_str)
{
guint richting=0,level=gcomprisBoard->level;
if(board_paused)
return FALSE;
if (threeDactive) return key_press_3D(keyval);
if (threeDactive) return key_press_3D(keyval, commit_str, preedit_str);
if (modeRelative) return key_press_2D_relative(keyval);
if (modeRelative) return key_press_2D_relative(keyval, commit_str, preedit_str);
switch (keyval)
{
......@@ -972,7 +972,7 @@ static gint target_event(GnomeCanvasItem *item, GdkEvent *event, gpointer data)
return FALSE;
}
static gint key_press_2D_relative(guint keyval)
static gint key_press_2D_relative(guint keyval, gchar *commit_str, gchar *preedit_str)
{
guint richting=0,level=gcomprisBoard->level;
......@@ -1009,7 +1009,7 @@ static gint key_press_2D_relative(guint keyval)
return TRUE;
}
static gint key_press_3D(guint keyval)
static gint key_press_3D(guint keyval, gchar *commit_str, gchar *preedit_str)
{
switch (keyval)
{
......
/* gcompris - memory.c
*
* Time-stamp: <2005/09/01 15:33:53 yves>
* Time-stamp: <2005/09/16 14:01:03 yves>
*
* Copyright (C) 2000 Bruno Coudoin
*
......@@ -442,9 +442,12 @@ static void start_board (GcomprisBoard *agcomprisBoard)
alphabet_lowercase=_("abcdefghijklmnopqrstuvwxyz");
assert(g_utf8_validate(alphabet_lowercase,-1,NULL)); // require by all utf8-functions
g_warning("Using lowercase %s", alphabet_lowercase);
/* TRANSLATORS: Put here the alphabet uppercase in your language */
alphabet_uppercase=_("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
assert(g_utf8_validate(alphabet_uppercase,-1,NULL)); // require by all utf8-functions
g_warning("Using uppercase %s", alphabet_uppercase);
if (currentMode == MODE_TUX){
tux_memory_size = tux_memory_sizes[gcomprisBoard->level];
......
/* gcompris - paratrooper.c
*
* Time-stamp: <2005/07/01 23:46:38 yves>
* Time-stamp: <2005/09/15 00:19:23 yves>
*
* Copyright (C) 2000 Bruno Coudoin
*
......@@ -77,7 +77,7 @@ static void pause_board (gboolean pause);
static void end_board (void);
static gboolean is_our_board (GcomprisBoard *gcomprisBoard);
static void set_level (guint level);
static gint key_press(guint keyval);
static gint key_press(guint keyval, gchar *commit_str, gchar *preedit_str);
static GnomeCanvasItem *paratrooper_create_cloud(GnomeCanvasGroup *parent);
static gint paratrooper_drop_clouds (GtkWidget *widget, gpointer data);
......@@ -224,7 +224,7 @@ set_level (guint level)
}
}
static gint key_press(guint keyval)
static gint key_press(guint keyval, gchar *commit_str, gchar *preedit_str)
{
if(!gcomprisBoard)
......
/* gcompris - planegame.c
*
* Time-stamp: <2005/07/01 23:48:30 yves>
* Time-stamp: <2005/09/15 00:18:56 yves>
*
* Copyright (C) 2000 Bruno Coudoin
*
......@@ -54,7 +54,7 @@ static void pause_board (gboolean pause);
static void end_board (void);
static gboolean is_our_board (GcomprisBoard *gcomprisBoard);
static void set_level (guint level);
static gint key_press(guint keyval);
static gint key_press(guint keyval, gchar *commit_str, gchar *preedit_str);
static GnomeCanvasItem *planegame_create_item(GnomeCanvasGroup *parent);
static gint planegame_drop_items (GtkWidget *widget, gpointer data);
......@@ -184,7 +184,7 @@ set_level (guint level)
}
}
static gint key_press(guint keyval)
static gint key_press(guint keyval, gchar *commit_str, gchar *preedit_str)
{
if(!gcomprisBoard)
......
......@@ -158,6 +158,17 @@ pyGcomprisPropertiesType_getattr(pyGcomprisPropertiesObject *self, char *name)
}
}
if(strcmp(name,"context")==0){
if (self->cdata->context)
return (PyObject*) pygobject_new((GObject*)self->cdata->context);
else {
Py_INCREF(Py_None);
return Py_None;
}
}
if(strcmp(name,"default_context")==0) return Py_BuildValue("s", self->cdata->default_context);
}
return Py_FindMethod(pyGcomprisPropertiesType_methods, (PyObject *)self, name);
}
......
......@@ -1608,6 +1608,21 @@ py_gcompris_get_wordlist_from_file (PyObject* self, PyObject* args)
}
}
static PyObject*
py_gcompris_im_reset (PyObject* self, PyObject* args)
{
/* Parse arguments */
if(!PyArg_ParseTuple(args, ":gcompris.im_reset"))
return NULL;
/* Call the corresponding C function */
gcompris_im_reset ();
Py_INCREF(Py_None);
return Py_None;
}
/****************************************************/
......@@ -1671,6 +1686,7 @@ static PyMethodDef PythonGcomprisModule[] = {
{ "get_board_dirname", py_gcompris_get_board_dirname, METH_VARARGS, "gcompris_get_board_dirname" },
{ "get_current_board_dirname", py_gcompris_get_current_board_dirname, METH_VARARGS, "gcompris_get_current_board_dirname" },
{ "get_wordlist", py_gcompris_get_wordlist_from_file, METH_VARARGS, "gcompris_get_wordlist_from_file" },
{ "im_reset", py_gcompris_im_reset, METH_VARARGS, "gcompris_im_reset" },
{ NULL, NULL, 0, NULL}
};
......
......@@ -42,7 +42,7 @@ static void pythonboard_end (void);
static gboolean pythonboard_is_our_board (GcomprisBoard *agcomprisBoard);
static gint pythonboard_key_press (guint keyval);
static gint pythonboard_key_press (guint keyval, gchar *commit_str, gchar *preedit_str);
static void pythonboard_ok (void);
static void pythonboard_set_level (guint level);
static void pythonboard_config(void);
......@@ -442,10 +442,10 @@ static gboolean pythonboard_is_our_board (GcomprisBoard *agcomprisBoard){
/*
* Key press
*/
static gint pythonboard_key_press (guint keyval){
static gint pythonboard_key_press (guint keyval, gchar *commit_str, gchar *preedit_str){
PyObject* result = NULL;
result = PyObject_CallMethod(python_board_instance, "key_press", "i", keyval);
result = PyObject_CallMethod(python_board_instance, "key_press", "iss", keyval, commit_str, preedit_str);
if (result==NULL) return FALSE;
......
......@@ -144,7 +144,7 @@ class Gcompris_administration:
pass
def key_press(self, keyval):
def key_press(self, keyval, commit_str, preedit_str):
#print("Gcompris_administration key press. %i" % keyval)
return False
......
......@@ -172,7 +172,7 @@ class Gcompris_algorithm:
y = 185, fill_color_rgba = 0x000000ffL,
font = gcompris.skin.get_font("gcompris/board/huge bold"))
def key_press(self, keyval):
def key_press(self, keyval, commit_str, preedit_str):
print("got key %i" % keyval)
return False
......
......@@ -383,6 +383,8 @@ class Gcompris_anim:
def start(self):
self.last_commit = None
# GCompris initialisation
self.gcomprisBoard.level=1
self.gcomprisBoard.maxlevel=1
......@@ -434,7 +436,8 @@ class Gcompris_anim:
def config(self):
print("Gcompris_anim config.")
def key_press(self, keyval):
def key_press(self, keyval, commit_str, preedit_str):
print keyval, commit_str, preedit_str
#
# I suppose codec is the stdin one.
#
......@@ -508,7 +511,10 @@ class Gcompris_anim:
return True
textItem = self.selected.item_list[0]
oldtext = textItem.get_property('text').decode('UTF-8')
if (self.last_commit == None):
oldtext = textItem.get_property('text').decode('UTF-8')
else:
oldtext = self.last_commit
if ((keyval == gtk.keysyms.BackSpace) or
(keyval == gtk.keysyms.Delete)):
......@@ -519,19 +525,26 @@ class Gcompris_anim:
newtext = u'?'
else:
utf8char=gtk.gdk.keyval_to_unicode(keyval)
str = u'%c' % utf8char
if ((oldtext[:1] == u'?') and (len(oldtext)==1)):
oldtext = u' '
oldtext = oldtext.strip()
if (commit_str != None):
str = commit_str
self.last_commit = oldtext + str
if (preedit_str != None):
str = '<span foreground="red">'+ preedit_str +'</span>'
self.last_commit = oldtext
if (len(oldtext) < self.MAX_TEXT_CHAR):
newtext = oldtext + str
else:
newtext = oldtext
textItem.set(text=newtext.encode('UTF-8'))
textItem.set(markup=newtext.encode('UTF-8'))
self.updated_text(textItem)
return True
......@@ -630,16 +643,13 @@ class Gcompris_anim:
if not self.running:
# unselect object if necessary
if (self.selected != None):
self.selected.item_list[1].hide()
self.selected = None
self.unselect()
self.playing_start()
return True
elif (self.tools[tool][0] != "SELECT") and (self.selected != None):
self.selected.item_list[1].hide()
self.selected = None
self.unselect()
#
# Normal case, tool button switch
......@@ -964,10 +974,7 @@ class Gcompris_anim:
if event.type == gtk.gdk.BUTTON_PRESS and event.button == 1:
if event.button == 1:
# deactivate the anchors
if self.selected != None:
self.selected.item_list[1].hide()
self.selected=None
self.unselect()
#
# MOUSE DRAG STOP
......@@ -1861,8 +1868,7 @@ class Gcompris_anim:
def select_item(self, group):
if (self.selected != None):
self.selected.item_list[1].hide()
self.selected = None
self.unselect()
# Deactivate old button
self.old_tool_item.set(pixbuf = gcompris.utils.load_pixmap(self.tools[self.current_tool][1]))
......@@ -2160,6 +2166,20 @@ class Gcompris_anim:
self.timeout=gobject.timeout_add(1000/self.anim_speed, self.run_anim2)
def unselect(self):
if ((gobject.type_name(self.selected.item_list[0])=="GnomeCanvasText")
and
(self.last_commit != None)):
#suppress preedit
self.selected.item_list[0].set(markup=self.last_commit)
self.last_commit = None
gcompris.im_reset()
self.selected.item_list[1].hide()
self.selected = None
###############################################
#
......
......@@ -139,7 +139,7 @@ class Gcompris_ballcatch:
print("Gcompris_ballcatch config.")
def key_press(self, keyval):
def key_press(self, keyval, commit_str, preedit_str):
print("Gcompris_ballcatch key press. %i" % keyval)
if (keyval == gtk.keysyms.Shift_L):
......
......@@ -105,7 +105,7 @@ class Gcompris_bargame:
self.play(self.answer.value,True)
pass
def key_press(self, keyval):
def key_press(self, keyval, commit_str, preedit_str):
#print("got key %i" % keyval)
return False
......
......@@ -150,7 +150,7 @@ class Gcompris_connect4:
print("Gcompris_connect4 config.")
def key_press(self, keyval):
def key_press(self, keyval, commit_str, preedit_str):
print("Gcompris_connect4 key press. %i" % keyval)
self.timericon.hide()
return False
......
......@@ -74,7 +74,7 @@ class Gcompris_followline:
print("Gcompris_followline config.")
def key_press(self, keyval):
def key_press(self, keyval, commit_str, preedit_str):
return False
......
......@@ -838,8 +838,15 @@ class Gcompris_gnumch:
self.winGame()
self.squares[x][y].setNum(new)
def key_press(self, keyval):
self.muncher.push_key(keyval)
def key_press(self, keyval, commit_str, preedit_str):
if ((commit_str != None) or (preedit_str != None)):
if ((' ' in commit_str) or (' ' in preedit_str)):
key = gtk.keysyms.space
else:
key = 0
else:
key = keyval
self.muncher.push_key(key)
return False
def stopGame(self):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment