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

gcompris_change_locale and gcompris_reset_locale are usefull fonction to...

gcompris_change_locale and gcompris_reset_locale are usefull fonction to change locale easily in boards. colors uses it, and pythontest.
Fix configuration window behaviour: now the window closes when "Apply" button is clicked.
add a asset_get based gcompris_get_locales_asset_list: really to long, needs to be rewritten. unusable.
parent f5c77fb6
2005-08-18 Yves Combe <yves@ycombe.net>
gcompris_change_locale and gcompris_reset_locale are usefull fonction to change locale easily in boards. colors uses it, and pythontest.
Fix configuration window behaviour: now the window closes when "Apply" button is clicked.
add a asset_get based gcompris_get_locales_asset_list: really to long, needs to be rewritten. unusable.
* src/boards/colors.c: (save_table), (conf_apply),
(colors_config_start), (start_board), (end_board):
* src/boards/py-mod-gcompris.c: (pyGcomprisConfCallback),
(py_gcompris_configuration_window), (py_gcompris_combo_locales),
(py_gcompris_change_locale), (py_gcompris_reset_locale):
* src/boards/python/pythontest.py:
* src/gcompris/board_config.c: (gcompris_apply_board_conf),
(gcompris_combo_locales_changed), (gcompris_combo_locales),
(gcompris_change_locale), (gcompris_reset_locale),
(gcompris_get_locales_asset_list):
* src/gcompris/board_config.h:
2005-08-17 Yves Combe <yves@ycombe.net>
fix stupid bug
......
......@@ -98,33 +98,40 @@ static BoardPlugin menu_bp =
*
* =====================================================================*/
GET_BPLUGIN_INFO(colors)
/* ======================= */
/* = config_start = */
/* ======================= */
static GtkVBox *config_vbox = NULL;
static GcomprisProfile *profile_conf;
static GcomprisBoard *board_conf;
GHFunc print_table (gpointer key,
GHFunc save_table (gpointer key,
gpointer value,
gpointer user_data)
{
printf (" Hash key %s as value %s \n", (gchar *) key, (gchar *) value);
gcompris_set_board_conf ( profile_conf,
board_conf,
(gchar *) key,
(gchar *) value);
}
static GcomprisConfCallback conf_apply(GHashTable *table)
{
printf ("Config Hashtable size %d\n", g_hash_table_size(table));
g_hash_table_foreach(table, (GHFunc) print_table, NULL);
g_hash_table_foreach(table, (GHFunc) save_table, NULL);
board_conf = NULL;
profile_conf = NULL;
}
static void
static void
colors_config_start(GcomprisBoard *agcomprisBoard,
GcomprisProfile *aProfile)
{
board_conf = agcomprisBoard;
profile_conf = aProfile;
gchar *label;
label = g_strdup_printf("<b>%s</b> configuration\n for profile <b>%s</b>",
......@@ -134,65 +141,25 @@ colors_config_start(GcomprisBoard *agcomprisBoard,
g_free(label);
gcompris_separator();
gcompris_boolean_box("Test Check Box", "key1", TRUE);
gcompris_separator();
GList *list = NULL;
int i;
for (i =0; i< 10; i++)
list = g_list_append( list, g_strdup_printf("value_%d", i));
gcompris_combo_box( "Gcompris ComboBox", list, "combo_key", NULL);
gcompris_separator();
GHashTable *table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
for (i =0; i< 5; i++)
g_hash_table_insert ( table,
g_strdup_printf("key_%d", i),
g_strdup_printf("Radio Button %d", i)
);
gcompris_radio_buttons( " <b><i>Radio</i> Buttons</b> Sample ",
"color_radio",
table,
"key_7");
gcompris_separator();
gcompris_spin_int(" <b><i>Spin</i> Button</b> Sample ",
"color_spin",
2,
52,
5,
12);
/* init the combo to previously saved value */
GHashTable *config = gcompris_get_board_conf();
gchar *locale = g_hash_table_lookup( config, "locale");
if (!locale)
locale = "NULL";
g_hash_table_destroy( table);
/* Choose new value */
gcompris_combo_locales("locale", locale);
GList *locales = gcompris_get_locales_list();
GList *locale = locales;
gchar *actual_lang = g_strdup(gcompris_get_locale());
g_warning("locale was set to %s", actual_lang);
while (locale){
gcompris_set_locale(locale->data);
g_warning("Brain in %s : %s",locale->data, _("Brain"));
locale = locale->next;
}
gcompris_set_locale(actual_lang);
g_free(actual_lang);
//segfault (list too long ? )
gcompris_combo_box( "Gcompris locales", locales, "locale", "fr");
/**************************/
/* unusable: too long */
/* GList *locales_asset = gcompris_get_locales_asset_list("gcompris colors", NULL, "audio/x-ogg", "purple.ogg" ); */
/* gchar *locale_asset = g_hash_table_lookup( config, "locale_asset"); */
/* gcompris_combo_box( "Select sound locale", locales_asset, "locale_asset", locale_asset); */
}
/* ======================= */
/* = config_stop = */
......@@ -227,6 +194,13 @@ static void start_board (GcomprisBoard *agcomprisBoard) {
int * item;
int i;
GHashTable *config = gcompris_get_board_conf();
gchar *locale = g_hash_table_lookup( config, "locale");
if (locale)
gcompris_change_locale(locale);
if(agcomprisBoard!=NULL) {
gcomprisBoard=agcomprisBoard;
gcompris_set_background(gnome_canvas_root(gcomprisBoard->canvas), "colors/colors_bg.jpg");
......@@ -275,6 +249,7 @@ static void end_board () {
listColors=NULL;
}
gcomprisBoard = NULL;
gcompris_reset_locale();
}
/* =====================================================================
......
......@@ -1066,9 +1066,9 @@ static GcomprisConfCallback pyGcomprisConfCallback(GHashTable* table){
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);
// This callback can be called multiple time ? not now
Py_DECREF(pyGcomprisConfCallbackFunc);
if(result==NULL){
PyErr_Print();
......@@ -1099,8 +1099,8 @@ py_gcompris_configuration_window(PyObject* self, PyObject* args){
return NULL;
}
if (pyGcomprisConfCallbackFunc)
Py_DECREF(pyGcomprisConfCallbackFunc);
//if (pyGcomprisConfCallbackFunc)
// Py_DECREF(pyGcomprisConfCallbackFunc);
pyGcomprisConfCallbackFunc = pyCallback;
......@@ -1303,7 +1303,7 @@ py_gcompris_combo_locales(PyObject* self, PyObject* args)
gchar *init;
/* Parse arguments */
if(!PyArg_ParseTuple(args, "ss:gcompris_radio_buttons", &key, &init))
if(!PyArg_ParseTuple(args, "ss:gcompris_combo_locales", &key, &init))
return NULL;
return (PyObject *)pygobject_new((GObject*) \
......@@ -1350,10 +1350,43 @@ py_gcompris_gettext(PyObject* self, PyObject* args)
/****************************************************/
/* void gcompris_change_locale(gchar *locale); */
static PyObject*
py_gcompris_change_locale(PyObject* self, PyObject* args)
{
gchar *locale;
/* Parse arguments */
if(!PyArg_ParseTuple(args, "s:gcompris_change_locale", &locale))
return NULL;
/* Call the corresponding C function */
gcompris_change_locale(locale);
/* Create and return the result */
Py_INCREF(Py_None);
return Py_None;
}
/* void gcompris_reset_locale(gchar *locale); */
static PyObject*
py_gcompris_reset_locale(PyObject* self, PyObject* args)
{
/* Parse arguments */
if(!PyArg_ParseTuple(args, ":gcompris_reset_locale"))
return NULL;
/* Call the corresponding C function */
gcompris_reset_locale();
/* Create and return the result */
Py_INCREF(Py_None);
return Py_None;
}
/****************************************************/
static PyMethodDef PythonGcomprisModule[] = {
{ "end_board", py_gcompris_end_board, METH_VARARGS, "gcompris_end_board" },
......@@ -1404,6 +1437,8 @@ static PyMethodDef PythonGcomprisModule[] = {
{ "combo_locales", py_gcompris_combo_locales, METH_VARARGS, "gcompris_combo_locales" },
{ "get_locales_list", py_gcompris_get_locales_list, METH_VARARGS, "gcompris_get_locales_list" },
{ "gcompris_gettext", py_gcompris_gettext, METH_VARARGS, "gcompris_gettext" },
{ "change_locale", py_gcompris_change_locale, METH_VARARGS, "gcompris_change_locale" },
{ "reset_locale", py_gcompris_reset_locale, METH_VARARGS, "gcompris_reset_locale" },
{ NULL, NULL, 0, NULL}
};
......
......@@ -45,7 +45,7 @@ class Gcompris_pythontest:
self.previous_locale = gcompris.get_locale()
if self.config_dict.has_key('locale'):
gcompris.set_locale(self.config_dict['locale'])
gcompris.change_locale(self.config_dict['locale'])
# self.colors['line'] s set in init.
# I put here the configuration use
......@@ -205,7 +205,7 @@ class Gcompris_pythontest:
def end(self):
gcompris.set_locale(self.previous_locale)
gcompris.reset_locale()
# Remove the root item removes all the others inside it
self.rootitem.destroy()
......@@ -404,7 +404,7 @@ class Gcompris_pythontest:
print gcompris.get_locales_list()
gcompris.combo_locales('locale', self.init_conf_str('locale', 'fr'))
gcompris.combo_locales('locale', self.init_conf_str('locale', 'NULL'))
# Get value from config_dict or value passed
def init_conf(self, key, value):
......
/* gcompris - board_config.c
*
* Time-stamp: <2005/08/17 01:29:47 yves>
* Time-stamp: <2005/08/18 00:53:22 yves>
*
* Copyright (C) 2001 Pascal Georges
*
......@@ -20,6 +20,7 @@
*/
#include "gcompris.h"
#include "assetml.h"
#define COMBOBOX_COL_MAX 15
......@@ -83,6 +84,9 @@ void gcompris_apply_board_conf (GtkButton *button,
{
if (Confcallback != NULL)
Confcallback(hash_conf);
gcompris_close_board_conf (button,
user_data);
}
GtkVBox *gcompris_configuration_window(gchar *label, GcomprisConfCallback callback)
......@@ -523,12 +527,154 @@ GList *gcompris_get_locales_list(){
return locales;
}
void gcompris_combo_locales_changed(GtkComboBox *combobox,
gpointer key)
{
gchar *the_key = g_strdup((gchar *)key);
gchar *value;
gint index = gtk_combo_box_get_active (combobox);
if (index == 0)
/* Default value of gcompris selected */
value = g_strdup ("NULL");
else
value = gtk_combo_box_get_active_text (combobox);
g_hash_table_replace(hash_conf, (gpointer) the_key, (gpointer) value);
}
GtkComboBox *gcompris_combo_locales(gchar *key, gchar *init)
{
return gcompris_combo_box(_("Select the language to use in the board"),
gcompris_get_locales_list(),
key,
init);
GtkWidget *combobox;
GtkWidget *hbox = gtk_hbox_new (FALSE, 8);
GList *list, *strings;
GtkWidget *label_combo;
gint init_index = 0;
strings = gcompris_get_locales_list();
strings = g_list_prepend( strings, _("Default"));
if (init){
if (strcmp(init, "NULL")!=0)
init_index = g_list_position ( strings, g_list_find_custom ( strings,(gconstpointer) init, (GCompareFunc) my_strcmp));
}
if (init_index < 0)
init_index=0;
gtk_widget_show(hbox);
gtk_box_pack_start (GTK_BOX(main_conf_box),
hbox,
FALSE,
FALSE,
0);
/* Label */
label_combo = gtk_label_new ((gchar *)NULL);
gtk_widget_show(label_combo);
gtk_box_pack_start (GTK_BOX(hbox),
label_combo,
FALSE,
FALSE,
0);
gtk_label_set_justify (GTK_LABEL(label_combo),
GTK_JUSTIFY_RIGHT);
gtk_label_set_markup (GTK_LABEL(label_combo),
_("Select the language\n to use in the board"));
combobox = gtk_combo_box_new_text();
gtk_widget_show(combobox);
gtk_box_pack_start (GTK_BOX(hbox),
combobox,
FALSE,
FALSE,
0);
for (list = strings; list != NULL; list = list->next)
gtk_combo_box_append_text (GTK_COMBO_BOX(combobox),
list->data);
if (g_list_length(strings) > COMBOBOX_COL_MAX)
gtk_combo_box_set_wrap_width (GTK_COMBO_BOX(combobox),
g_list_length(strings) / COMBOBOX_COL_MAX +1 );
gtk_combo_box_set_active (GTK_COMBO_BOX(combobox),
init_index);
g_signal_connect(G_OBJECT(combobox),
"changed",
G_CALLBACK(gcompris_combo_locales_changed),
key);
return GTK_COMBO_BOX(combobox);
}
static gchar *current_locale = NULL;
void gcompris_change_locale(gchar *locale)
{
if (strcmp(locale, "NULL") == 0)
return;
current_locale = g_strdup(gcompris_get_locale());
gcompris_set_locale(locale);
}
void gcompris_reset_locale(){
if (current_locale == NULL)
return;
gcompris_set_locale(current_locale);
g_free(current_locale);
current_locale = NULL;
}
GList *gcompris_get_locales_asset_list(gchar *dataset, gchar* categories,
gchar* mimetype, gchar* file){
GList *locales, *list, *locales_asset = NULL;
GList *gl_result;
AssetML *assetml;
gchar* resultfile = NULL;
locales = gcompris_get_locales_list();
for (list = locales; list != NULL; list = list->next){
printf ("Looking for %s sound file...", list->data);
gl_result = assetml_get_asset(dataset, categories, mimetype, list->data, file);
if(gl_result && g_list_length(gl_result)>0)
{
/* Always get the first item */
assetml = (AssetML *)g_list_nth_data(gl_result, 0);
if(assetml->file)
{
locales_asset = g_list_append ( locales_asset, list->data);
printf("ok.\n");
}
else
printf("no.\n");
assetml_free_assetlist(gl_result);
}
else
printf("no.\n");
}
return locales_asset;
}
/* Local Variables: */
......
/* gcompris - board_config.h
*
* Time-stamp: <2005/08/17 01:06:21 yves>
* Time-stamp: <2005/08/18 00:38:49 yves>
*
* Copyright (C) 2001 Pascal Georges
*
......@@ -68,6 +68,13 @@ GList *gcompris_get_locales_list();
GtkComboBox *gcompris_combo_locales(gchar *key, gchar *init);
void gcompris_change_locale(gchar *locale);
void gcompris_reset_locale();
GList *gcompris_get_locales_asset_list(gchar *dataset, gchar* categories,
gchar* mimetype, gchar* file);
#endif
/* Local Variables: */
......
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