1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
#!/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
import gc
import 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])
|