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

pass binding of gcomrpis_window like child_spawn.

fix segfault.
fix tuxpaint to work effectively with new configuration funtions
parent 3d364e1b
2005-07-24 Yves Combe <yves@ycombe.net>
pass binding of gcomrpis_window like child_spawn.
fix segfault.
fix tuxpaint to work effectively with new configuration funtions
* src/boards/py-mod-gcompris.c: (pair_in_dict), (hash_to_dict),
(pyGcomprisConfCallback), (py_gcompris_configuration_window):
* src/boards/python/tuxpaint.py:
* src/gcompris/board_config.c: (gcompris_close_board_conf):
2005-07-24 Yves Combe,,, <yves@ycombe.net>
gcompris_configuration_window and gcompris_boolean_box: two usefull functions for boards configuration, with python bindings
......
......@@ -22,15 +22,22 @@ void pair_in_dict(gpointer key,
gpointer dict)
{
PyObject *pyValue;
PyObject *pyKey;
pyKey = PyString_FromString((gchar *)key);
Py_INCREF(pyKey);
/* key cannot be NULL. But value can */
if (value==NULL){
Py_INCREF(Py_None);
pyValue = Py_None;
} else
} else {
pyValue = PyString_FromString((gchar *)value);
Py_INCREF(pyValue);
}
PyDict_SetItem((PyObject *)dict, PyString_FromString((gchar *)key), pyValue);
PyDict_SetItem((PyObject *)dict, pyKey, pyValue);
}
......@@ -44,7 +51,9 @@ PyObject* hash_to_dict(GHashTable *table)
g_hash_table_foreach (table,
pair_in_dict,
(gpointer) pydict);
return pydict;;
Py_INCREF(pydict);
return pydict;
}
......@@ -1029,18 +1038,28 @@ static PyObject* pyGcomprisConfCallbackFunc = NULL;
static GcomprisConfCallback pyGcomprisConfCallback(GHashTable* table){
PyObject* args;
PyObject* result;
PyGILState_STATE gil;
if(pyGcomprisConfCallbackFunc==NULL) return;
/* Build arguments */
args = PyTuple_New(1);
PyTuple_SetItem(args, 0, Py_BuildValue("O", hash_to_dict(table)));
result = PyObject_CallObject(pyGcomprisConfCallbackFunc, args);
gil = pyg_gil_state_ensure();
result = PyObject_CallFunction(pyGcomprisConfCallbackFunc, "O", hash_to_dict(table));
// This callback can be called multiple time
// I must add a second callback to mark the window closed and DECREF this ref.
//Py_DECREF(pyGcomprisConfCallbackFunc);
if(result==NULL){
PyErr_Print();
} else {
Py_DECREF(result);
}
pyg_gil_state_release(gil);
}
......@@ -1060,9 +1079,15 @@ py_gcompris_configuration_window(PyObject* self, PyObject* args){
return NULL;
}
if (pyGcomprisConfCallbackFunc)
Py_DECREF(pyGcomprisConfCallbackFunc);
pyGcomprisConfCallbackFunc = pyCallback;
return (PyObject *)pygobject_new((GObject*) gcompris_configuration_window(pyGcomprisConfCallback));
Py_INCREF(pyGcomprisConfCallbackFunc);
return (PyObject *)pygobject_new((GObject*) gcompris_configuration_window((GcomprisConfCallback )pyGcomprisConfCallback));
}
......
......@@ -154,27 +154,18 @@ class Gcompris_tuxpaint:
pass
def config_start(self, profile):
self.configure_profile = profile
self.config_values = {}
self.main_vbox = gcompris.configuration_window(apply_callback)
self.actual_config = gcompris.get_conf(profile, self.gcomprisBoard)
self.main_vbox = gcompris.configuration_window(self.apply_callback)
gcompris.boolean_box('Disable shape rotation', 'disable_shape_rotation', False)
gcompris.boolean_box('Follow gcompris fullscreen', 'fullscreen', True)
gcompris.boolean_box('Show Uppercase text only', 'uppercase_text', False)
gcompris.boolean_box('Disable stamps', 'disable_stamps', False)
gcompris.boolean_box('Disable stamps control', 'disable_stamps_control', False)
pass
self.config_dict = gcompris.get_conf(profile, self.gcomprisBoard)
def configuration_close(self, button):
self.configure_window.destroy()
def configuration_apply(self, button):
for key,value in self.config_values.iteritems():
gcompris.set_board_conf(self.configure_profile, self.gcomprisBoard, key, value)
pass
gcompris.boolean_box('Disable shape rotation', 'disable_shape_rotation', self.configuration('disable_shape_rotation'))
gcompris.boolean_box('Follow gcompris fullscreen', 'fullscreen', self.configuration('fullscreen'))
gcompris.boolean_box('Show Uppercase text only', 'uppercase_text', self.configuration('uppercase_text'))
gcompris.boolean_box('Disable stamps', 'disable_stamps', self.configuration('disable_stamps'))
gcompris.boolean_box('Disable stamps control', 'disable_stamps_control', self.configuration('disable_stamps_control'))
def boolean_box(self, label, value):
button = gtk.CheckButton(label)
......@@ -188,6 +179,12 @@ class Gcompris_tuxpaint:
def boolean_callback(self, widget, value):
self.config_values[value] = str(widget.get_active())
def apply_callback(self,table):
for key,value in table.iteritems():
gcompris.set_board_conf(self.configure_profile, self.gcomprisBoard, key, value)
def child_callback(fd, cond, data):
#global board
#board.window.set_property("accept-focus", 1)
......@@ -200,7 +197,4 @@ def child_callback(fd, cond, data):
def stop_board():
gcompris.bonus.board_finished(gcompris.bonus.FINISHED_RANDOM)
def apply_callback(table):
print table
/* gcompris - board_config.c
*
* Time-stamp: <2005/07/24 03:11:39 yves>
* Time-stamp: <2005/07/24 09:48:33 yves>
*
* Copyright (C) 2001 Pascal Georges
*
......@@ -71,6 +71,9 @@ void gcompris_close_board_conf (GtkButton *button,
gpointer user_data)
{
gtk_object_destroy ((GtkObject *)conf_window);
g_hash_table_destroy (hash_conf);
hash_conf = NULL;
}
void gcompris_apply_board_conf (GtkButton *button,
......
Supports Markdown
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