Back to index

gcompris  8.2.2
administration.py
Go to the documentation of this file.
00001 #  gcompris - administration.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 # Administration Board module
00020 import gnomecanvas
00021 import gcompris
00022 import gcompris.utils
00023 import gcompris.skin
00024 import gtk
00025 import gtk.gdk
00026 from gettext import gettext as _
00027 
00028 # To add a panel, add a python module in the admin subdir
00029 # This module must have a start() and end() function
00030 class Gcompris_administration:
00031   """Administering GCompris"""
00032 
00033 
00034   def __init__(self, gcomprisBoard):
00035     self.gcomprisBoard = gcomprisBoard
00036 
00037     # The panel being displayed
00038     self.current_panel = None
00039     self.current_panel_stopped = False
00040 
00041     # Create our rootitem. We put each canvas item in it so at the end we
00042     # only have to kill it. The canvas deletes all the items it contains automaticaly.
00043     self.rootitem = self.gcomprisBoard.canvas.root().add(
00044       gnomecanvas.CanvasGroup,
00045       x=0.0,
00046       y=0.0
00047       )
00048 
00049     gap = 10
00050     panel_x = 120
00051     self.select_area = (gap , gap, panel_x + gap , gcompris.BOARD_HEIGHT-gap)
00052     self.panel_area  = (panel_x + 2*gap ,
00053                         gap,
00054                         gcompris.BOARD_WIDTH-gap,
00055                         gcompris.BOARD_HEIGHT-gap)
00056 
00057 
00058 
00059   def pause(self, pause):
00060     if(self.current_panel != None):
00061       if pause:
00062         # Stop current panel
00063         self.current_panel.stop()
00064         self.current_panel_stopped = True
00065       else:
00066         # Restart the current panel
00067         self.current_panel.start(self.panel_area)
00068         self.current_panel_stopped = False
00069 
00070 
00071   def start(self):
00072 
00073     # Find the list of modules in admin/
00074     # that means all files, but __init__.py and module.py
00075     list_modules = []
00076 
00077     import glob
00078     m_list = glob.glob('admin/module_*.py')
00079     if m_list == []:
00080       m_list = glob.glob(gcompris.PYTHON_PLUGIN_DIR+'/admin/module_*.py')
00081     for file in m_list:
00082       m_name = file.split('/')[-1].split('.')[0].split('_')[1]
00083       list_modules.append(m_name)
00084 
00085     # Now import modules,
00086     # and get the list of string 'name.Name' for initialisation below.
00087     modules_init = []
00088 
00089     for module in list_modules:
00090       exec('from admin import module_' + module + ' as ' + module)
00091       modules_init.append(module+ '.' + module[0].upper() + module[1:])
00092 
00093     del list_modules
00094 
00095     self.gcomprisBoard.level=1
00096     self.gcomprisBoard.maxlevel=1
00097     self.gcomprisBoard.sublevel=1
00098     self.gcomprisBoard.number_of_sublevel=1
00099     gcompris.bar_set(0)
00100     gcompris.set_background(self.gcomprisBoard.canvas.root(),
00101                             gcompris.skin.image_to_skin("gcompris-bg.jpg"))
00102     gcompris.bar_set_level(self.gcomprisBoard)
00103 
00104     self.rootitem.add(
00105       gnomecanvas.CanvasRect,
00106       x1=self.select_area[0],
00107       y1=self.select_area[1],
00108       x2=self.select_area[2],
00109       y2=self.select_area[3],
00110       fill_color="white",
00111       outline_color_rgba=0x111199FFL,
00112       width_units=1.0
00113       )
00114 
00115     # A White background in the panel area
00116     self.rootitem.add(
00117       gnomecanvas.CanvasRect,
00118       x1=self.panel_area[0],
00119       y1=self.panel_area[1],
00120       x2=self.panel_area[2],
00121       y2=self.panel_area[3],
00122       fill_color="white",
00123       outline_color_rgba=0x111199FFL,
00124       width_units=1.0
00125       )
00126 
00127     # Get the menu position for each module
00128     # The list of modules
00129     modules_ordered = []
00130     for module in modules_init:
00131       p = eval(module +'(self.rootitem).position()')
00132       modules_ordered.append((p, module))
00133 
00134     # Display the menu in the selection area
00135     # The list of modules
00136     i = 0
00137     modules_ordered.sort()
00138     for tmodule in modules_ordered:
00139       module = tmodule[1]
00140       eval(module +'(self.rootitem).init(i, self.select_area, self.select_event)')
00141       i+=1
00142 
00143 
00144   def end(self):
00145     # Stop current panel
00146     if(self.current_panel != None and not self.current_panel_stopped):
00147       self.current_panel.stop()
00148       self.current_panel_stopped = False
00149 
00150   def ok(self):
00151     pass
00152 
00153 
00154   def repeat(self):
00155     pass
00156 
00157 
00158   def config(self):
00159     pass
00160 
00161 
00162   def key_press(self, keyval, commit_str, preedit_str):
00163     #print("Gcompris_administration key press. %i" % keyval)
00164     return False
00165 
00166   # ---- End of Initialisation
00167 
00168   # Event when a tool is selected
00169   def select_event(self, item, event, module):
00170     if event.type == gtk.gdk.BUTTON_PRESS:
00171       if event.button == 1:
00172 
00173         # Do not reload it
00174         if(self.current_panel ==  module):
00175           return
00176 
00177         # Stop previous panel if any
00178         if(self.current_panel != None):
00179           self.current_panel.stop()
00180           self.current_panel_stopped = False
00181 
00182         self.current_panel = module
00183 
00184         # Start the new panel
00185         module.start(self.panel_area)
00186