Back to index

gcompris  8.2.2
tuxpaint.py
Go to the documentation of this file.
00001 #  gcompris - Tuxpaint Launcher
00002 #
00003 #  Copyright (C) 2004  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 import gnomecanvas
00020 import gcompris
00021 import gcompris.utils
00022 import gcompris.bonus
00023 import gcompris.skin
00024 import gcompris.sound
00025 import gcompris.admin
00026 import gtk
00027 import os
00028 
00029 import pango
00030 
00031 #import gobject
00032 from gettext import gettext as _
00033 
00034 pid = None
00035 #board = None
00036 
00037 class Gcompris_tuxpaint:
00038   """TuxPaint Launcher"""
00039   global pid
00040 
00041   def __init__(self, gcomprisBoard):
00042     self.gcomprisBoard = gcomprisBoard
00043     pass
00044 
00045   def configuration(self, value, init):
00046     if self.config_dict.has_key(value):
00047       return eval(self.config_dict[value])
00048     else:
00049       return init
00050 
00051   def start(self):
00052 #    line = os.sys.stdin.readline()
00053 #    while (len(line) >1):
00054 #      exec(line)
00055 #      line = os.sys.stdin.readline()
00056 
00057     self.window = self.gcomprisBoard.canvas.get_toplevel()
00058 
00059     #global board
00060     #board = self
00061 
00062     Prop = gcompris.get_properties()
00063 
00064     #get default values
00065     self.config_dict = self.init_config()
00066 
00067     #replace configured values
00068     self.config_dict.update(gcompris.get_board_conf())
00069 
00070     self.rootitem = self.gcomprisBoard.canvas.root().add(
00071       gnomecanvas.CanvasGroup,
00072       x=0.0,
00073       y=0.0
00074       )
00075 
00076     options = ['tuxpaint']
00077 
00078     if (Prop.fullscreen and eval(self.config_dict['fullscreen'])):
00079       options.append('--fullscreen')
00080 
00081     # tuxpaint size are 800x600 and 640x480 in 9.14
00082     # in cvs (future 9.15) it will be
00083     # [--640x480   | --800x600   | --1024x768 |
00084     #  --1280x1024 | --1400x1050 | --1600x1200]
00085     if (Prop.screensize and eval(self.config_dict['size'])):
00086       if (Prop.screensize >=1):
00087         print 'Prop.screensize', Prop.screensize
00088         options.append('--800x600')
00089       else:
00090         options.append('--640x480')
00091 
00092     if eval(self.config_dict['disable_shape_rotation']):
00093       options.append('--simpleshapes')
00094 
00095     if eval(self.config_dict['uppercase_text']):
00096       options.append('--uppercase')
00097 
00098     if eval(self.config_dict['disable_stamps']):
00099       options.append('--nostamps')
00100 
00101     if eval(self.config_dict['disable_stamps_control']):
00102       options.append('--nostampcontrols')
00103 
00104     gcompris.sound.close()
00105 
00106     # release pointergrab if running fullscreen, tuxpaint wants to grab the
00107     # pointer itself
00108     if (Prop.fullscreen and not Prop.noxf86vm):
00109       gtk.gdk.pointer_ungrab()
00110 
00111     #self.window.set_property("accept-focus", 0)
00112     #self.window.set_keep_below(False)
00113 
00114     try:
00115       # gobject.SPAWN_DO_NOT_REAP_CHILD|gobject.SPAWN_SEARCH_PATH = 2 | 4
00116       pid,stdin, stdout, stderr = gcompris.spawn_async(
00117         options, flags=2|4)
00118     except:
00119       gcompris.utils.dialog(_("Cannot find Tuxpaint.\nInstall it to use this activity !"),stop_board)
00120       return
00121 
00122     gcompris.child_watch_add(pid, child_callback, self)
00123 
00124     gcompris.bar_set(0)
00125     gcompris.bar_hide(1)
00126 
00127     gcompris.set_background(self.rootitem,
00128                             gcompris.skin.image_to_skin("gcompris-bg.jpg"))
00129 
00130     textItem = self.rootitem.add(
00131       gnomecanvas.CanvasText,
00132       text = _("Waiting for Tuxpaint to finish"),
00133       x = gcompris.BOARD_WIDTH/2,
00134       y = 185,
00135       fill_color_rgba = 0x000000ffL,
00136       font = gcompris.skin.get_font("gcompris/board/title bold"),
00137       )
00138 
00139   def end(self):
00140     gcompris.sound.reopen()
00141     global pid
00142     # force kill - data loss
00143     if pid != None:
00144       print "Tuxpaint not killed", self.pid
00145     #import os
00146     #os.kill(self.pid, signal.SIGKILL)
00147     if self.rootitem != None:
00148       self.rootitem.destroy()
00149       self.rootitem = None
00150 
00151   def set_level(self,level):
00152     pass
00153 
00154   def ok(self):
00155     pass
00156 
00157   def key_press(self, keyval, commit_str, preedit_str):
00158     return False
00159 
00160   def repeat(self):
00161     pass
00162 
00163   def pause(self, pause):
00164     pass
00165 
00166   def config(self):
00167     print "Config"
00168     pass
00169 
00170   def config_stop(self):
00171     print "config_stop", self
00172     pass
00173 
00174   def config_start(self, profile):
00175     self.configure_profile = profile
00176 
00177     #get default values
00178     self.config_dict = self.init_config()
00179 
00180     #set already configured values
00181     self.config_dict.update(gcompris.get_conf(profile, self.gcomprisBoard))
00182 
00183     self.main_vbox = gcompris.configuration_window(_('<b>%s</b> configuration\n for profile <b>%s</b>') % ('Tuxpaint', profile.name ),
00184                                                    self.apply_callback)
00185 
00186 
00187     gcompris.boolean_box(_('Inherit fullscreen setting from GCompris'), 'fullscreen', eval(self.config_dict['fullscreen']))
00188 
00189     gcompris.separator()
00190 
00191     gcompris.boolean_box(_('Inherit size setting from GCompris (800x600, 640x480)'), 'size', eval(self.config_dict['size']))
00192 
00193     gcompris.separator()
00194 
00195     gcompris.boolean_box(_('Disable shape rotation'), 'disable_shape_rotation', eval(self.config_dict['disable_shape_rotation']))
00196 
00197     gcompris.separator()
00198 
00199     gcompris.boolean_box(_('Show Uppercase text only'), 'uppercase_text', eval(self.config_dict['uppercase_text']))
00200 
00201     gcompris.separator()
00202 
00203     stamps = gcompris.boolean_box(_('Disable stamps'), 'disable_stamps', eval(self.config_dict['disable_stamps']))
00204     stamps.connect("toggled", self.stamps_changed)
00205 
00206     self.stamps_control = gcompris.boolean_box('Disable stamps control', 'disable_stamps_control', eval(self.config_dict['disable_stamps_control']))
00207     self.stamps_control.set_sensitive(not eval(self.config_dict['disable_stamps']))
00208 
00209   def stamps_changed(self, button):
00210     self.stamps_control.set_sensitive(not button.get_active())
00211 
00212   def apply_callback(self,table):
00213     print table
00214     for key,value in table.iteritems():
00215       gcompris.set_board_conf(self.configure_profile, self.gcomprisBoard, key, value)
00216 
00217   def init_config(self):
00218     default_config_dict = { 'fullscreen'             : 'True',
00219                             'disable_shape_rotation' : 'False',
00220                             'uppercase_text'         : 'False',
00221                             'disable_stamps'         : 'False',
00222                             'disable_stamps_control' : 'False',
00223                             'size'                   : 'True'
00224       }
00225     return default_config_dict
00226 
00227 def child_callback(fd,  cond, data):
00228   # restore pointergrab if running fullscreen
00229   if (gcompris.get_properties().fullscreen and
00230       not gcompris.get_properties().noxf86vm):
00231     gtk.gdk.pointer_grab(data.window.window, True, 0, data.window.window)
00232   #global board
00233   #board.window.set_property("accept-focus", 1)
00234   #board.window.set_keep_above(False)
00235   gcompris.sound.reopen()
00236 
00237   #a bug in tuxpaint 9.14: it does not suppress it lockfile
00238   lockfile = os.getenv('HOME') + '/.tuxpaint/lockfile.dat'
00239 
00240   try:
00241     os.remove(lockfile)
00242   except:
00243     print lockfile, 'not removed.'
00244 
00245   global pid
00246   pid = None
00247   gcompris.bar_hide(0)
00248   gcompris.bonus.board_finished(gcompris.bonus.FINISHED_RANDOM)
00249 
00250 def stop_board():
00251   gcompris.bonus.board_finished(gcompris.bonus.FINISHED_RANDOM)
00252