Back to index

gcompris  8.2.2
module.py
Go to the documentation of this file.
00001 #  gcompris - module.py
00002 #
00003 # Copyright (C) 2005 Bruno Coudoin and Yves Combe
00004 #
00005 #   This program is free software; you can redistribute it and/or modify
00006 #   it under the terms of the GNU General Public License as published by
00007 #   the Free Software Foundation; either version 2 of the License, or
00008 #   (at your option) any later version.
00009 #
00010 #   This program is distributed in the hope that it will be useful,
00011 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 #   GNU General Public License for more details.
00014 #
00015 #   You should have received a copy of the GNU General Public License
00016 #   along with this program; if not, write to the Free Software
00017 #   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 #
00019 
00020 # This is the base Class for all Administration modules.
00021 
00022 import gnomecanvas
00023 import gcompris
00024 import gcompris.utils
00025 import gcompris.skin
00026 import gtk
00027 import gtk.gdk
00028 from gettext import gettext as _
00029 
00030 class Module:
00031     """GCompris Administrative Module"""
00032 
00033     def __init__(self, canvas, module_name, module_label):
00034         self.module_name = module_name
00035         self.module_label = module_label
00036         self.canvas = canvas
00037 
00038         self.selector_color = 0xC5D2DDFFL
00039         self.outline_color  = 0XD8B09AFFL
00040         self.module_panel_ofset = 3
00041 
00042     # Return the position it must have in the administration menu
00043     # The smaller number is the highest.
00044     # By default, return 999 to let the module be low
00045     def position(self):
00046         return 999
00047 
00048     def init(self, index, select_area, callback):
00049         print("Gcompris_administration init panel.")
00050 
00051         height = 80
00052         gap = 35
00053         x   = select_area[0] + (select_area[2] - select_area[0]) / 2
00054         y1  = select_area[1] + height * index + 2
00055         y2  = select_area[1] + height * (index + 1) + 1
00056 
00057         # Create our rootitem. We put each canvas item in it so at the end we
00058         # only have to kill it. The canvas deletes all the items it contains automaticaly.
00059 
00060         self.root_select_item = self.canvas.add(
00061             gnomecanvas.CanvasGroup,
00062             x=0.0,
00063             y=0.0
00064             )
00065 
00066         self.select_item = self.root_select_item.add(
00067             gnomecanvas.CanvasRect,
00068             x1=select_area[0]+2,
00069             y1=y1,
00070             x2=select_area[2]-2,
00071             y2=y2,
00072             fill_color="white",
00073             outline_color="white",
00074             width_units=1.0
00075             )
00076         self.select_item.connect("event", callback, self)
00077 
00078         y1 += 30
00079         print "config_" + self.module_name + ".png"
00080         print gcompris.skin.image_to_skin("config_" +
00081                                           self.module_name +
00082                                           ".png")
00083         item = self.root_select_item.add(
00084             gnomecanvas.CanvasPixbuf,
00085             pixbuf = gcompris.utils.load_pixmap(gcompris.skin.image_to_skin("config_" +
00086                                                                             self.module_name +
00087                                                                             ".png")),
00088             x = x,
00089             y = y1,
00090             anchor=gtk.ANCHOR_CENTER,
00091             )
00092         item.connect("event", callback, self)
00093 
00094         y1 += gap
00095 
00096         item = self.root_select_item.add (
00097             gnomecanvas.CanvasText,
00098             text=_(self.module_label),
00099             font=gcompris.skin.get_font("gcompris/tiny"),
00100             x = x,
00101             y = y1,
00102             fill_color="black"
00103             )
00104         item.connect("event", callback, self)
00105 
00106 
00107     def get_module_name(self):
00108         return self.module_name
00109 
00110     def start(self):
00111         self.select_item.set(
00112             fill_color_rgba=self.selector_color,
00113             outline_color_rgba=self.outline_color
00114             )
00115 
00116     def stop(self):
00117         self.select_item.set(
00118             fill_color="white",
00119             outline_color="white"
00120             )
00121