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

Connect treeview signal to allow usage of pref button

Add pref icon in treeview if board is configurable
gcompris_load_menus_* skip boards listed in profile unactivated activities. (Works !)
parent b656de92
2005-07-22 Yves Combe <yves@ycombe.net>
Connect treeview signal to allow usage of pref button
Add pref icon in treeview if board is configurable
gcompris_load_menus_* skip boards listed in profile unactivated activities. (Works !)
* src/boards/python/admin/board_list.py:
* src/boards/python/tuxpaint.py:
* src/gcompris/gameutil.c: (compare_id), (gcompris_load_menus_dir),
(gcompris_load_menus):
2005-07-21 Bruno coudoin <bruno.coudoin@free.fr>
Added 3 new background musics (classical music).
......
......@@ -125,10 +125,11 @@ class Board_list:
# Add buttons
button_configure = gtk.Button(stock=gtk.STOCK_PROPERTIES)
# button_add.connect("clicked", self.on_add_item_clicked, model)
button_configure.show()
box3.pack_start(button_configure, True, False, 0)
self.button_configure = gtk.Button(stock=gtk.STOCK_PREFERENCES)
self.button_configure.connect("clicked", self.configure_board)
self.button_configure.show()
box3.pack_start(self.button_configure, True, False, 0)
self.button_configure.set_sensitive(False)
# -------------------
......@@ -174,21 +175,27 @@ class Board_list:
row_dict = {}
self.board_dict = {}
height = 24
for board_cell in menu_list:
self.board_dict['%s/%s' % (board_cell[1].section,board_cell[1].name)] = board_cell[1]
if board_cell[0] == None:
row_dict[''] = \
row_dict[''] = \
model.append(None,
[self.pixbuf_at_height('gcompris/misc/tuxplane.png', height),
_('Main menu') + '\n' + _('/'),
not board_cell[1].board_id in self.out_dict[self.active_profile.profile_id],
'%s/%s' % (board_cell[1].section,board_cell[1].name)])
'%s/%s' % (board_cell[1].section,board_cell[1].name), self.pixbuf_configurable(board_cell[1])])
else:
row_dict['%s/%s' % (board_cell[1].section,board_cell[1].name)] = \
model.append(row_dict[board_cell[1].section],
[self.pixbuf_at_height(board_cell[1].icon_name, height),
_(board_cell[1].title) + '\n' + '%s/%s' % (board_cell[1].section,board_cell[1].name),
not board_cell[1].board_id in self.out_dict[self.active_profile.profile_id], '%s/%s' % (board_cell[1].section,board_cell[1].name)])
not board_cell[1].board_id in self.out_dict[self.active_profile.profile_id],
'%s/%s' % (board_cell[1].section,board_cell[1].name), self.pixbuf_configurable(board_cell[1])])
def pixbuf_at_height(self,file, height):
pixbuf = gcompris.utils.load_pixmap(file)
......@@ -203,6 +210,7 @@ class Board_list:
gobject.TYPE_STRING,
gobject.TYPE_BOOLEAN,
gobject.TYPE_STRING,
gobject.TYPE_STRING,
)
boards_list = gcompris.admin.get_boards_list()
......@@ -218,38 +226,51 @@ class Board_list:
# Render for Board name with icon.
cell_board_icon = gtk.CellRendererPixbuf()
# cell_board_name = gtk.CellRendererText()
cell_board_title = gtk.CellRendererText()
cell_active_board = gtk.CellRendererToggle()
cell_active_board.set_property('activatable', True)
cell_active_board.connect( 'toggled', self.board_acive_cb, model )
cell_board_configure = gtk.CellRendererPixbuf()
# columns for Board name
column0 = gtk.TreeViewColumn(_('active'))
column1 = gtk.TreeViewColumn(_('Board title'))
column1.pack_start(cell_board_icon, False)
column1.pack_start(cell_board_title, True)
# column2 = gtk.TreeViewColumn(_('Name'))
column0.pack_start(cell_active_board, False)
treeview.append_column(column0)
treeview.append_column(column1)
# treeview.append_column(column2)
# column2.pack_start(cell_board_name, True)
column1.add_attribute(cell_board_icon, 'pixbuf', 0)
column1.add_attribute(cell_board_title, 'text', 1)
column0.add_attribute(cell_active_board, 'active', 2)
# columns for Board name
# column_pref = gtk.TreeViewColumn(_('Conf'))
# image = gtk.image_new_from_stock(gtk.STOCK_PREFERENCES, gtk.ICON_SIZE_MENU)
# image.show()
# column_pref.set_widget(image)
column_active = gtk.TreeViewColumn(_('Active'))
column_title = gtk.TreeViewColumn(_('Board title'))
column_title.pack_start(cell_board_icon, False)
column_active.pack_start(cell_board_configure, False)
column_title.pack_start(cell_board_title, True)
column_active.pack_start(cell_active_board, False)
treeview.append_column(column_active)
treeview.append_column(column_title)
column_title.add_attribute(cell_board_icon, 'pixbuf', 0)
column_title.add_attribute(cell_board_title, 'text', 1)
column_active.add_attribute(cell_active_board, 'active', 2)
column_active.set_attributes(cell_board_configure, stock_id=4)
treeview.connect("cursor-changed", self.row_selected, model)
def board_acive_cb(self, cell, path, model):
model[path][2] = not model[path][2]
print "Toggle '%s' %d to: %s" % (self.board_dict[model[path][3]].title, self.board_dict[model[path][3]].board_id , model[path][2],)
if model[path][2]:
print 'DELETE FROM activities_out WHERE board_id=%d AND out_id=%d' % (self.board_dict[model[path][3]].board_id, self.active_profile.profile_id)
self.cur.execute('DELETE FROM activities_out WHERE board_id=%d AND out_id=%d' % (self.board_dict[model[path][3]].board_id, self.active_profile.profile_id))
self.cur.execute('DELETE FROM activities_out WHERE board_id=%d AND out_id=%d' % (
self.board_dict[model[path][3]].board_id,
self.active_profile.profile_id
))
else:
print 'INSERT INTO activities_out (board_id, out_id) VALUES (%d, %d)' % (self.board_dict[model[path][3]].board_id, self.active_profile.profile_id)
self.cur.execute('INSERT INTO activities_out (board_id, out_id) VALUES (%d, %d)' % (self.board_dict[model[path][3]].board_id, self.active_profile.profile_id))
self.cur.execute('INSERT INTO activities_out (board_id, out_id) VALUES (%d, %d)' % (
self.board_dict[model[path][3]].board_id,
self.active_profile.profile_id
))
self.con.commit()
......@@ -285,3 +306,27 @@ class Board_list:
self.cur.execute('select board_id, out_id from activities_out')
return self.dict_from_list(self.cur.fetchall())
def pixbuf_configurable(self, board):
if board.is_configurable:
return gtk.STOCK_PREFERENCES
else:
return None
def preference_clicked(self, widget, event, board):
print 'preference', board.title
def row_selected(self, treeview, model):
path = model.get_path(treeview.get_selection().get_selected()[1])
print "Row selected:", model[path][3]
self.selected_board = self.board_dict[model[path][3]]
if self.selected_board.is_configurable:
self.button_configure.set_sensitive(True)
else:
self.button_configure.set_sensitive(False)
def configure_board(self, button):
print 'Oui, Oui un de ces jours a va lancer la conf de ', self.selected_board.title
# gcompris.admin.board_config_start(self.selected_board)
# gcompris.admin.board_config_stop(self.selected_board)
......@@ -31,6 +31,7 @@ import os
from gettext import gettext as _
pid = None
#board = None
class Gcompris_tuxpaint:
"""TuxPaint Launcher"""
......@@ -39,13 +40,18 @@ class Gcompris_tuxpaint:
def __init__(self, gcomprisBoard):
self.gcomprisBoard = gcomprisBoard
pass
def start(self):
# line = os.sys.stdin.readline()
# while (len(line) >1):
# exec(line)
# line = os.sys.stdin.readline()
self.window = self.gcomprisBoard.canvas.get_toplevel()
#global board
#board = self
Prop = gcompris.get_properties()
self.rootitem = self.gcomprisBoard.canvas.root().add(
......@@ -60,6 +66,10 @@ class Gcompris_tuxpaint:
gcompris.sound.close()
#self.window.set_property("accept-focus", 0)
#self.window.set_keep_below(False)
try:
# gobject.SPAWN_DO_NOT_REAP_CHILD|gobject.SPAWN_SEARCH_PATH = 2 | 4
pid,stdin, stdout, stderr = gcompris.spawn_async(
......@@ -84,7 +94,7 @@ class Gcompris_tuxpaint:
fill_color_rgba = 0x000000ffL,
font = gcompris.skin.get_font("gcompris/board/huge bold"),
)
def end(self):
gcompris.sound.reopen()
global pid
......@@ -130,6 +140,9 @@ class Gcompris_tuxpaint:
pass
def child_callback(fd, cond, data):
#global board
#board.window.set_property("accept-focus", 1)
#board.window.set_keep_above(False)
gcompris.sound.reopen()
global pid
pid = None
......
/* gcompris - gameutil.c
*
* Time-stamp: <2005/07/03 23:01:47 yves>
* Time-stamp: <2005/07/22 01:21:03 yves>
*
* Copyright (C) 2000 Bruno Coudoin
*
......@@ -716,6 +716,17 @@ GList *suppress_int_from_list(GList *list, int value)
return list;
}
gboolean compare_id(gconstpointer data1, gconstpointer data2)
{
int *i = (int *) data1;
int *j = (int *) data2;
if (*i == *j)
return 0;
else
return -1;
}
/*
* gcompris_load_menus
*
......@@ -739,10 +750,8 @@ void gcompris_load_menus_dir(char *dirname, gboolean db){
g_warning("gcompris_load_menus : no menu found in %s", dirname);
return;
} else {
if (db){
if (db)
list_old_boards_id = gcompris_db_get_board_id(list_old_boards_id);
printf("length list_old_boards_id %d\n", g_list_length(list_old_boards_id));
}
while((one_dirent = g_dir_read_name(dir)) != NULL) {
/* add the board to the list */
......@@ -770,13 +779,14 @@ void gcompris_load_menus_dir(char *dirname, gboolean db){
GcomprisBoard *board_read = gcompris_read_xml_file(gcomprisBoard, filename, db);
if (board_read){
list_old_boards_id = suppress_int_from_list(list_old_boards_id, board_read->board_id);
if ((properties->administration) ||
(strncmp(board_read->section,
"/administration",
strlen("/administration"))!=0))
if (properties->administration)
boards_list = g_list_append(boards_list, board_read);
//else
//gcompris_free_board(board_read);
else
if ((strncmp(board_read->section,
"/administration",
strlen("/administration"))!=0) &&
(!(g_list_find_custom(gcompris_get_current_profile()->activities, &(board_read->board_id), compare_id))))
boards_list = g_list_append(boards_list, board_read);
}
}
g_free(filename);
......@@ -785,7 +795,6 @@ void gcompris_load_menus_dir(char *dirname, gboolean db){
if (db){
/* remove suppressed boards from db */
printf("length list_old_boards_id to suppress %d\n", g_list_length(list_old_boards_id));
while (list_old_boards_id != NULL){
int *data=list_old_boards_id->data;
gcompris_db_remove_board(*data);
......@@ -813,6 +822,21 @@ void gcompris_load_menus()
if ((!properties->reread_xml) && gcompris_db_check_boards()){
boards_list = gcompris_load_menus_db(boards_list);
if (!properties->administration){
GList *out_boards = NULL;
GList *list = NULL;
GcomprisBoard *board;
for (list = boards_list; list != NULL; list = list->next){
board = (GcomprisBoard *)list->data;
if (g_list_find_custom(gcompris_get_current_profile()->activities,
&(board->board_id), compare_id))
out_boards = g_list_append(out_boards, board);
}
for (list = out_boards; list != NULL; list = list->next)
boards_list = g_list_remove(boards_list, list->data);
}
}
else {
properties->reread_xml = TRUE;
......
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