Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/Libreta_de_Lectura.py
diff options
context:
space:
mode:
Diffstat (limited to 'Libreta_de_Lectura.py')
-rw-r--r--Libreta_de_Lectura.py178
1 files changed, 178 insertions, 0 deletions
diff --git a/Libreta_de_Lectura.py b/Libreta_de_Lectura.py
new file mode 100644
index 0000000..905a07b
--- /dev/null
+++ b/Libreta_de_Lectura.py
@@ -0,0 +1,178 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# Libreta_de_Lectura.py por:
+# Flavio Danesse <fdanesse@gmail.com>
+# CeibalJAM! - Uruguay
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+import pygame, gc, subprocess
+from pygame.locals import *
+
+gc.enable()
+
+import BiblioJAM
+from BiblioJAM.JAMButton import JAMButton
+import BiblioJAM.JAMGlobals as JAMG
+
+import Globals as VG
+
+class Libreta_de_Lectura(pygame.sprite.OrderedUpdates):
+ def __init__(self, lectura):
+ pygame.sprite.OrderedUpdates.__init__(self)
+ self.sonido_ambiente= None
+ #self.sonido_select= JAMG.get_sound_select()
+ self.motor_de_voz= Motor_de_voz()
+ self.posicion_hoja= None
+ self.hoja= self.get_hoja()
+ self.texto= None
+ self.pagina_actual= ""
+ self.hoja_impresa= pygame.sprite.Sprite()
+
+ self.lectura= lectura
+ self.paginas= []
+ self.indice_pagina_actual= 0
+ self.set_lectura(self.lectura)
+
+ self.frame= self.get_frame()
+ self.boton_anterior, self.boton_leeme, self.boton_siguiente, self.boton_cerrar = self.get_botones_lectura()
+
+ self.add(self.hoja_impresa)
+ self.add(self.frame)
+ self.add(self.boton_anterior)
+ self.add(self.boton_leeme)
+ self.add(self.boton_siguiente)
+ self.add(self.boton_cerrar)
+
+ def next_pagina(self, button= None):
+ if len(self.paginas)-1 > self.indice_pagina_actual:
+ self.indice_pagina_actual += 1
+ else:
+ self.indice_pagina_actual = 0
+ self.hoja_impresa.image = self.paginas[self.indice_pagina_actual]
+ self.hoja_impresa.rect = self.hoja_impresa.image.get_rect()
+ self.set_posicion(punto=self.posicion_hoja)
+
+ def previous_pagina(self, button= None):
+ if self.indice_pagina_actual > 0:
+ self.indice_pagina_actual -= 1
+ else:
+ self.indice_pagina_actual = len(self.paginas)-1
+ self.hoja_impresa.image = self.paginas[self.indice_pagina_actual]
+ self.hoja_impresa.rect = self.hoja_impresa.image.get_rect()
+ self.set_posicion(punto=self.posicion_hoja)
+
+ def audio_stop(self):
+ self.sonido_ambiente.stop()
+
+ def play(self, sonido_ambiente, valor):
+ self.sonido_ambiente= pygame.mixer.Sound(sonido_ambiente)
+ self.sonido_ambiente.play(valor)
+
+ def set_posicion(self, punto= (0,0)):
+ # posicion de la hoja impresa
+ x, y= punto
+ self.hoja_impresa.rect.x, self.hoja_impresa.rect.y = x, y
+ self.frame.rect.x, self.frame.rect.y= (x, y)
+ self.posicion_hoja = punto
+
+ # Posicion de los botones
+ y= self.hoja_impresa.rect.h + y - self.boton_anterior.get_tamanio()[1] - 20
+ x= self.hoja_impresa.rect.centerx + 20
+ x-= self.boton_leeme.get_tamanio()[0]/2
+ self.boton_leeme.set_posicion(punto= (x, y))
+ a= x - 20 - self.boton_anterior.get_tamanio()[0]
+ self.boton_anterior.set_posicion(punto= (a, y))
+ b= x + 20 + self.boton_siguiente.get_tamanio()[0]
+ self.boton_siguiente.set_posicion(punto= (b, y))
+
+ x= self.hoja_impresa.rect.x + self.hoja_impresa.rect.w - 10 - self.boton_cerrar.get_tamanio()[0]
+ y= self.hoja_impresa.rect.y + 10
+ self.boton_cerrar.set_posicion(punto= (x, y))
+
+ def set_lectura(self, lectura):
+ # pasas un texto y lo imprime en la hoja
+ self.indice_pagina_actual = 0
+ self.lectura= lectura
+ self.paginas= []
+ for pagina in self.lectura:
+ hoja_impresa= self.get_hoja_impresa(pagina, self.hoja.copy())
+ self.paginas.append(hoja_impresa)
+
+ self.hoja_impresa.image= self.paginas[self.indice_pagina_actual]
+ self.hoja_impresa.rect= self.hoja_impresa.image.get_rect()
+
+ def get_hoja(self):
+ # superficie de hoja vacĂ­a
+ fondo= pygame.image.load(VG.FONDO_LIBRO)
+ superficie= JAMG.get_Rectangulo_Transparente( (500,648) )
+ y = 0
+ for x in range(1,19):
+ superficie.blit(fondo, (0,y))
+ y+= 36
+ return superficie
+
+ def get_hoja_impresa(self,texto, superficie):
+ y = 20
+ for linea in texto:
+ fuente= pygame.font.Font(pygame.font.match_font(pygame.font.get_default_font(), False, False), 26)
+ string_to_render= unicode( str(linea).decode("utf-8") )
+ imagen_fuente= fuente.render(string_to_render, 1, (0,0,0,1))
+ rectangulo_fuente= imagen_fuente.get_rect()
+ superficie.blit(imagen_fuente, (80,y))
+ y += rectangulo_fuente.h
+ return superficie
+
+ def get_frame(self):
+ frame= pygame.sprite.Sprite()
+ frame.image= JAMG.get_Rectangulo_Transparente( (self.hoja_impresa.rect.w, self.hoja_impresa.rect.h) )
+ frame.rect= frame.image.get_rect()
+ return frame
+
+ def get_botones_lectura(self):
+ x, y = 0,0
+ boton1= JAMButton("", JAMG.get_icon_back())
+ boton1.set_imagen(origen= JAMG.get_icon_back())
+ boton1.connect(callback= self.previous_pagina, sonido_select= None)
+ boton1.set_posicion(punto= (x,y))
+
+ x+= 25 + boton1.get_tamanio()[0]
+ boton2= JAMButton("", JAMG.get_icon_play())
+ boton2.set_imagen(origen= JAMG.get_icon_play())
+ boton2.set_posicion(punto=(x,y))
+
+ x+= 25 + boton2.get_tamanio()[0]
+ boton3= JAMButton("", JAMG.get_icon_next())
+ boton3.set_imagen(origen= JAMG.get_icon_next())
+ boton3.connect(callback= self.next_pagina, sonido_select= None)
+ boton3.set_posicion(punto= (x,y))
+
+ x+= 25 + boton2.get_tamanio()[0]
+ boton4= JAMButton("", JAMG.get_icon_exit())
+ boton4.set_imagen(origen= JAMG.get_icon_exit())
+ x= self.hoja_impresa.rect.x + self.hoja_impresa.rect.w - 10 - boton4.get_tamanio()[0]
+ y= self.hoja_impresa.rect.y + 10
+ boton4.set_posicion(punto= (x,y))
+
+ return boton1, boton2, boton3, boton4
+
+class Motor_de_voz():
+ def __init__(self):
+ pass
+ def lee(self, textbuffer):
+ pass
+ #subprocess.call(['espeak', "-ves", "-a 200", "-g 5", "-p 10", "--punct=<>", textbuffer])
+