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

gcompris_radio_buttons python binded. Test sample is in tuxpaint.py (colors.c for C sample).

parent adb4cada
2005-08-14 Yves Combe <yves@ycombe.net>
gcompris_radio_buttons configuration utility function for boards. Get a GHashTable with (key, label) pair, return the key pf the value selected.
gcompris_radio_buttons python binded. Test sample is in tuxpaint.py (colors.c for C sample).
* src/boards/colors.c: (colors_config_start):
* src/boards/py-mod-gcompris.c: (pair_object_in_dict),
(hash_object_to_dict), (py_gcompris_radio_buttons):
* src/boards/python/tuxpaint.py:
* src/gcompris/board_config.c: (gcompris_combo_box_changed),
(create_radio_buttons), (gcompris_radio_buttons):
2005-08-14 Yves Combe <yves@ycombe.net>
gcompris_radio_buttons configuration utility function for boards. Get a GHashTable with (key, label) pair, return the key of the value selected.
python binding is missing.
* src/boards/colors.c: (colors_config_start):
......
......@@ -150,10 +150,12 @@ colors_config_start(GcomprisBoard *agcomprisBoard,
g_strdup_printf("Radio Button %d", i)
);
gcompris_radio_buttons( " Radio Buttons Sample ",
gcompris_radio_buttons( " <b><i>Radio</i> Buttons</b> Sample ",
"color_radio",
table,
"key_7");
g_hash_table_destroy( table);
}
/* ======================= */
......
......@@ -1172,8 +1172,94 @@ py_gcompris_combo_box(PyObject* self, PyObject* args)
}
/* Params: */
/* - Label */
/* - key (for hashtable return) */
/* - g_hash_table (gchar *values, gchar *label) */
/* Returns */
/* - g_hash_table (gchar *values, GtkWidget *pointer) */
/* GHashTable *gcompris_radio_buttons(const gchar *label, */
/* gchar *key, */
/* GHashTable *buttons_label, */
/* gchar *init); */
void pair_object_in_dict(gpointer key,
gpointer value,
gpointer dict)
{
PyObject *pyValue;
PyObject *pyKey;
pyKey = PyString_FromString((gchar *)key);
Py_INCREF(pyKey);
pyValue = pygobject_new((GObject*) value);
Py_INCREF(pyValue);
PyDict_SetItem((PyObject *)dict, pyKey, pyValue);
}
/* Utility */
PyObject* hash_object_to_dict(GHashTable *table)
{
PyObject *pydict;
pydict = PyDict_New();
g_hash_table_foreach (table,
pair_object_in_dict,
(gpointer) pydict);
Py_INCREF(pydict);
return pydict;
}
static PyObject*
py_gcompris_radio_buttons(PyObject* self, PyObject* args)
{
PyObject *py_dict;
GHashTable *buttons_label, *result;
gchar *label;
gchar *key;
gchar *init;
/* Parse arguments */
if(!PyArg_ParseTuple(args, "ssOs:gcompris_radio_buttons", &label, &key, &py_dict, &init))
return NULL;
if (!PyDict_Check(py_dict)){
PyErr_SetString(PyExc_TypeError,
"gcompris_radio_buttons second argument must be a dict");
return NULL;
}
PyObject *pykey, *pyvalue;
int pos = 0;
buttons_label = g_hash_table_new_full (g_str_hash,
g_str_equal,
g_free,
g_free);
while (PyDict_Next(py_dict, &pos, &pykey, &pyvalue)) {
g_hash_table_replace (buttons_label,
g_strdup(PyString_AsString(pykey)),
g_strdup(PyString_AsString(pyvalue)));
}
result = gcompris_radio_buttons(label,
key,
buttons_label,
init);
g_hash_table_destroy(buttons_label);
return hash_object_to_dict(result);
}
/****************************************************/
......@@ -1222,6 +1308,7 @@ static PyMethodDef PythonGcomprisModule[] = {
{ "configuration_window", py_gcompris_configuration_window, METH_VARARGS, "gcompris_configuration_window" },
{ "boolean_box", py_gcompris_boolean_box, METH_VARARGS, "gcompris_boolean_box" },
{ "combo_box", py_gcompris_combo_box, METH_VARARGS, "gcompris_combo_box" },
{ "radio_buttons", py_gcompris_radio_buttons, METH_VARARGS, "gcompris_radio_buttons" },
{ NULL, NULL, 0, NULL}
};
......
......@@ -167,11 +167,28 @@ class Gcompris_tuxpaint:
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'))
stamps = gcompris.boolean_box('Disable stamps', 'disable_stamps', self.configuration('disable_stamps'))
self.stamps_control = gcompris.boolean_box('Disable stamps control', 'disable_stamps_control', self.configuration('disable_stamps_control'))
self.stamps_control.set_sensitive(self.configuration('disable_stamps'))
gcompris.combo_box('ComboBox Test ', ['red', 'blue', 'green'], 'combo_test', 1)
gcompris.radio_buttons('<b>Radio Buttons</b> Test',
'radio_test',
{ 'red': 'Red Carpet',
'blue': 'Blue Hotel',
'green': 'Yellow Submarine'
},
'green'
)
stamps.connect("toggled", self.stamps_changed)
def stamps_changed(self, button):
self.stamps_control.set_sensitive(button.get_active())
def apply_callback(self,table):
print table
for key,value in table.iteritems():
......
/* gcompris - board_config.c
*
* Time-stamp: <2005/08/14 02:38:38 yves>
* Time-stamp: <2005/08/14 14:29:23 yves>
*
* Copyright (C) 2001 Pascal Georges
*
......@@ -205,7 +205,7 @@ void gcompris_combo_box_changed(GtkComboBox *combobox,
{
gchar *the_key = g_strdup((gchar *)key);
gchar *value = gtk_combo_box_get_active_text (combobox);
gchar *value = g_strdup_printf("%d", gtk_combo_box_get_active (combobox));
g_hash_table_replace(hash_conf, (gpointer) the_key, (gpointer) value);
}
......@@ -289,9 +289,9 @@ void radio_changed(GtkToggleButton *togglebutton,
}
}
gboolean create_radio_buttons(gpointer key,
gpointer value,
gpointer hash_radio)
void create_radio_buttons(gpointer key,
gpointer value,
gpointer hash_radio)
{
GtkWidget *radio_button;
gchar *key_copy;
......@@ -316,8 +316,6 @@ gboolean create_radio_buttons(gpointer key,
(gpointer) key_copy);
g_hash_table_replace ( hash_radio, (gpointer) key_copy, (gpointer) radio_button);
return TRUE;
}
void destroy_hash (GtkObject *object,
......@@ -370,12 +368,10 @@ GHashTable *gcompris_radio_buttons(const gchar *label,
radio_key = g_strdup(key);
radio_init = g_strdup(init);
g_hash_table_foreach_remove( buttons_label,
(GHRFunc) create_radio_buttons,
g_hash_table_foreach( buttons_label,
(GHFunc) create_radio_buttons,
(gpointer) buttons);
g_hash_table_destroy (buttons_label);
g_signal_connect (G_OBJECT(radio_box), "destroy", G_CALLBACK(destroy_hash), (gpointer) buttons);
return buttons;
......
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