Commit c85398de authored by Yves Combe's avatar Yves Combe

rename users.py profiles.py in module_users.py and module_profiles.py.

change administration.py to load automaticly module_*.py
make config_start and config_stop running in python module (test in board.c, to ne removed).
parent 1efb3374
2005-07-04 Yves Combe <yves@ycombe.net>
rename users.py profiles.py in module_users.py and module_profiles.py.
change administration.py to load automaticly module_*.py
make config_start and config_stop running in python module (test in board.c, to ne removed).
* src/boards/python.c: (pythonboard_config_start),
(pythonboard_config_stop):
* src/boards/python/admin/module_profiles.py:
* src/boards/python/admin/module_users.py:
* src/boards/python/admin/profiles.py:
* src/boards/python/admin/users.py:
* src/boards/python/administration.py:
* src/boards/python/tuxpaint.py:
* src/gcompris/board.c: (board_play):
* src/gcompris/gcompris.h:
* src/gcompris/plugin.h:
2005-07-04 Yves Combe <yves@ycombe.net> 2005-07-04 Yves Combe <yves@ycombe.net>
add config_start and config_end entry point to all plugin. add config_start and config_end entry point to all plugin.
......
...@@ -25,10 +25,12 @@ ...@@ -25,10 +25,12 @@
#include "py-mod-gcompris.h" #include "py-mod-gcompris.h"
static GcomprisBoard *gcomprisBoard = NULL; static GcomprisBoard *gcomprisBoard = NULL;
static PyObject* python_gcomprisBoard = NULL; static PyObject* python_gcomprisBoard = NULL;
static PyObject* python_board_module = NULL; static PyObject* python_board_module = NULL;
static PyObject* python_board_instance = NULL; static PyObject* python_board_instance = NULL;
static GcomprisBoard *gcomprisBoard_config = NULL;
static PyObject* python_gcomprisBoard_config = NULL;; static PyObject* python_gcomprisBoard_config = NULL;;
static PyObject* python_board_config_module = NULL; static PyObject* python_board_config_module = NULL;
static PyObject* python_board_config_instance = NULL; static PyObject* python_board_config_instance = NULL;
...@@ -46,7 +48,7 @@ static void pythonboard_set_level (guint level); ...@@ -46,7 +48,7 @@ static void pythonboard_set_level (guint level);
static void pythonboard_config(void); static void pythonboard_config(void);
static void pythonboard_repeat (void); static void pythonboard_repeat (void);
static void pythonboard_config_start (GcomprisBoard *agcomprisBoard, static void pythonboard_config_start (GcomprisBoard *agcomprisBoard,
GnomeCanvas *canvas, GnomeCanvasGroup *canvasgroup,
int x, int x,
int y, int y,
int width, int width,
...@@ -513,7 +515,7 @@ static void pythonboard_repeat (void){ ...@@ -513,7 +515,7 @@ static void pythonboard_repeat (void){
} }
/* /*
* Start the board. * Start the board config_start.
* In this case: * In this case:
* - initialize python interpreter * - initialize python interpreter
* - import gcompris functions/objects * - import gcompris functions/objects
...@@ -521,9 +523,16 @@ static void pythonboard_repeat (void){ ...@@ -521,9 +523,16 @@ static void pythonboard_repeat (void){
* - load the python written board * - load the python written board
* - call the board start function * - call the board start function
*/ */
/*
* Normally python in already runningwhen config_start is called. If not config_stop has to stop it.
*/
static gboolean python_run_by_config = FALSE;
static void static void
pythonboard_config_start (GcomprisBoard *agcomprisBoard, pythonboard_config_start (GcomprisBoard *agcomprisBoard,
GnomeCanvas *canvas, GnomeCanvasGroup *canvasgroup,
int x, int x,
int y, int y,
int width, int width,
...@@ -537,6 +546,59 @@ pythonboard_config_start (GcomprisBoard *agcomprisBoard, ...@@ -537,6 +546,59 @@ pythonboard_config_start (GcomprisBoard *agcomprisBoard,
static char* python_prog_name="gcompris"; static char* python_prog_name="gcompris";
char* boardclass; char* boardclass;
char* board_file_name; char* board_file_name;
PyObject* main_module;
char* boarddir;
gchar *userplugindir;
g_assert (agcomprisBoard != NULL);
if(!Py_IsInitialized()){
/* Initialize the python interpreter */
Py_SetProgramName(python_prog_name);
Py_Initialize();
PySys_SetArgv(1, python_args);
init_pygobject();
main_module = PyImport_AddModule("__main__");
globals = PyModule_GetDict(main_module);
if(globals==NULL){
g_print("Cannot get info from the python interpreter. Seems there is a problem with this one.\n");
return;
} else {
gcomprisBoard_config = agcomprisBoard;
}
/* Add the python plugins dir to the python's search path */
#ifndef DISABLE_USER_PLUGIN_DIR
userplugindir = g_strconcat(g_get_home_dir(), "/.gcompris/Plugins/", NULL);
boarddir = g_strdup_printf("import sys; sys.path.append('%s/python'); sys.path.append('%s'); sys.path.append('%s')",
userplugindir,
PYTHON_PLUGIN_DIR,
gcomprisBoard_config->board_dir);
#else
boarddir = g_strdup_printf("import sys; sys.path.append('%s')",PYTHON_PLUGIN_DIR );
#endif
PyRun_SimpleString(boarddir);
g_free(boarddir);
#ifndef DISABLE_USER_PLUGIN_DIR
g_free(userplugindir);
#endif
/* Load the gcompris modules */
python_gcompris_module_init();
python_run_by_config = TRUE;
}
else {
main_module = PyImport_AddModule("__main__"); /* Borrowed reference */
globals = PyModule_GetDict(main_module); /* Borrowed reference */
}
/* Python is now initialized we create some usefull variables */ /* Python is now initialized we create some usefull variables */
board_file_name = strchr(agcomprisBoard->type, ':')+1; board_file_name = strchr(agcomprisBoard->type, ':')+1;
...@@ -547,30 +609,26 @@ pythonboard_config_start (GcomprisBoard *agcomprisBoard, ...@@ -547,30 +609,26 @@ pythonboard_config_start (GcomprisBoard *agcomprisBoard,
globals, globals,
globals, globals,
NULL); NULL);
if(python_board_config_module!=NULL){ if(python_board_config_module!=NULL){
/* Get the module dictionnary */ /* Get the module dictionnary */
module_dict = PyModule_GetDict(python_board_config_module); module_dict = PyModule_GetDict(python_board_config_module);
/* Get the python board class */ /* Get the python board class */
py_boardclass = PyDict_GetItemString(module_dict, boardclass); py_boardclass = PyDict_GetItemString(module_dict, boardclass);
/* Create a python gcompris board */ /* Create a python gcompris board */
python_gcomprisBoard_config=gcompris_new_pyGcomprisBoardObject(agcomprisBoard); python_gcomprisBoard_config=gcompris_new_pyGcomprisBoardObject(agcomprisBoard);
/* Create an instance of the board class */ /* Create an instance of the board class */
py_boardclass_args = PyTuple_New(1); py_boardclass_args = PyTuple_New(1);
Py_INCREF(python_gcomprisBoard_config); Py_INCREF(python_gcomprisBoard_config);
PyTuple_SetItem(py_boardclass_args, 0, python_gcomprisBoard_config); PyTuple_SetItem(py_boardclass_args, 0, python_gcomprisBoard_config);
PyTuple_SetItem(py_boardclass_args, 1, PyInt_FromLong((long) x));
PyTuple_SetItem(py_boardclass_args, 1, PyInt_FromLong((long) y));
PyTuple_SetItem(py_boardclass_args, 1, PyInt_FromLong((long) width));
PyTuple_SetItem(py_boardclass_args, 1, PyInt_FromLong((long) height));
python_board_config_instance = PyInstance_New(py_boardclass, py_boardclass_args, NULL); python_board_config_instance = PyInstance_New(py_boardclass, py_boardclass_args, NULL);
Py_DECREF(py_boardclass_args); Py_DECREF(py_boardclass_args);
/* Call the function */ py_function_result = PyObject_CallMethod(python_board_config_instance,
py_function_result = PyObject_CallMethod(python_board_config_instance, "config_start", NULL); "config_start", "Oiiii", pygobject_new((GObject*)canvasgroup), x, y, width, height);
if( py_function_result != NULL){ if( py_function_result != NULL){
Py_DECREF(py_function_result); Py_DECREF(py_function_result);
} else { } else {
...@@ -602,6 +660,9 @@ static void pythonboard_config_stop (void){ ...@@ -602,6 +660,9 @@ static void pythonboard_config_stop (void){
Py_XDECREF(python_board_config_module); Py_XDECREF(python_board_config_module);
Py_XDECREF(python_board_config_instance); Py_XDECREF(python_board_config_instance);
Py_XDECREF(python_gcomprisBoard_config); Py_XDECREF(python_gcomprisBoard_config);
Py_Finalize(); if (python_run_by_config){
Py_Finalize();
python_run_by_config = FALSE;
}
} }
} }
...@@ -10,11 +10,29 @@ from gettext import gettext as _ ...@@ -10,11 +10,29 @@ from gettext import gettext as _
# To add a panel, add a python module in the admin subdir # To add a panel, add a python module in the admin subdir
# This module must have a start() and end() function # This module must have a start() and end() function
# Also add it in admin/__init__.py
# Add it in the "from import" bellow # Find the list of modules in admin/
# Last add it in the self.modules variable # that means all files, but __init__.py and module.py
from admin import users list_modules = []
from admin import profiles
import glob
m_list = glob.glob(gcompris.DATA_DIR+'/../python/admin/module_*.py')
for file in m_list:
m_name = file.split('/')[-1].split('.')[0].split('_')[1]
list_modules.append(m_name)
print "Modules List : ", list_modules
# Now import modules,
# and get the list of string 'name.Name' for initialisation below.
modules_init = []
for module in list_modules:
exec('from admin import ' + module)
modules_init.append(module+ '.' + module[0].upper() + module[1:])
del list_modules
class Gcompris_administration: class Gcompris_administration:
"""Administrating GCompris""" """Administrating GCompris"""
...@@ -77,10 +95,11 @@ class Gcompris_administration: ...@@ -77,10 +95,11 @@ class Gcompris_administration:
# Display the menu in the selection area # Display the menu in the selection area
# The list of modules # The list of modules
i = 0 i = 0
users.Users(self.rootitem).init(i, self.select_area, self.select_event) for module in modules_init:
i+=1 print module +'(self.rootitem).init(i, self.select_area, self.select_event)'
profiles.Profiles(self.rootitem).init(i, self.select_area, self.select_event) exec(module +'(self.rootitem).init(i, self.select_area, self.select_event)')
i+=1
print("Gcompris_administration start.") print("Gcompris_administration start.")
......
...@@ -104,7 +104,14 @@ class Gcompris_tuxpaint: ...@@ -104,7 +104,14 @@ class Gcompris_tuxpaint:
def config(self): def config(self):
print "Config" print "Config"
pass pass
def config_start(self, canvasgroup, x, y, w, h):
print "config_start", self, canvasgroup, x, y, w, h
pass
def config_stop(self):
print "config_stop", self
pass
def child_callback(fd, cond, data): def child_callback(fd, cond, data):
global pid global pid
......
...@@ -340,8 +340,23 @@ void board_play(GcomprisBoard *gcomprisBoard) ...@@ -340,8 +340,23 @@ void board_play(GcomprisBoard *gcomprisBoard)
bp = gcomprisBoard->plugin; bp = gcomprisBoard->plugin;
set_current_gcompris_board(gcomprisBoard); set_current_gcompris_board(gcomprisBoard);
if (bp->config_start){
printf("Running confg_start before board\n");
board_config_start(gcomprisBoard, gnome_canvas_root(gcomprisBoard->canvas), 0,10, 20, 30);
board_config_stop();
}
bp->start_board(gcomprisBoard); bp->start_board(gcomprisBoard);
bp_data->playing = TRUE; bp_data->playing = TRUE;
if (bp->config_start){
printf("Running confg_start after board\n");
board_config_start(gcomprisBoard, gnome_canvas_root(gcomprisBoard->canvas), 10,110, 120, 130);
board_config_stop();
}
return; return;
} }
......
/* gcompris - gcompris.h /* gcompris - gcompris.h
* *
* Time-stamp: <2005/06/25 21:17:27 yves> * Time-stamp: <2005/07/04 12:51:36 yves>
* *
* Copyright (C) 2000,2001,2002 Bruno Coudoin * Copyright (C) 2000,2001,2002 Bruno Coudoin
* *
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include "plugin.h" #include "plugin.h"
#include "gcompris-board.h" #include "gcompris-board.h"
#include "board.h" #include "board.h"
#include "board_config.h"
#include "properties.h" #include "properties.h"
#include "gameutil.h" #include "gameutil.h"
#include "bonus.h" #include "bonus.h"
......
/* gcompris - plugin.h /* gcompris - plugin.h
* *
* Time-stamp: <2005/07/02 16:11:40 yves> * Time-stamp: <2005/07/04 09:30:03 yves>
* *
* Copyright (C) 2000 Bruno Coudoin * Copyright (C) 2000 Bruno Coudoin
* *
...@@ -37,7 +37,7 @@ typedef void (*GcomprisSetLevel) (guint level); ...@@ -37,7 +37,7 @@ typedef void (*GcomprisSetLevel) (guint level);
typedef void (*GcomprisConfig) (); typedef void (*GcomprisConfig) ();
typedef void (*GcomprisRepeat) (); typedef void (*GcomprisRepeat) ();
typedef void (*GcomprisConfigStart) (GcomprisBoard *gcomprisBoard, typedef void (*GcomprisConfigStart) (GcomprisBoard *gcomprisBoard,
GnomeCanvas *canvas, GnomeCanvasGroup *canvasgroup,
int x, int x,
int y, int y,
int width, int width,
......
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