Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/activity.py
blob: c8d05dad31c3cd9b21f24efb97c249db92dce092 (plain)
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
# Copyright 2013 Paolo Monsalvo
#
# 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 gtk
import logging
import gobject
import random
from ConfigParser import SafeConfigParser
from subprocess import Popen


from gettext import gettext as _

from sugar.activity import activity
from sugar.graphics.toolbarbox import ToolbarBox
from sugar.activity.widgets import ActivityButton
from sugar.activity.widgets import ActivityToolbox
from sugar.activity.widgets import TitleEntry
from sugar.activity.widgets import StopButton
from sugar.activity.widgets import ShareButton

class JugandoAprendesActivity(activity.Activity):
    """HelloWorldActivity class as specified in activity.info"""

    def __init__(self, handle):
        """Set up the HelloWorld activity."""
        activity.Activity.__init__(self, handle)

        # toolbar with the new toolbar redesign
        toolbar_box = ToolbarBox()

        activity_button = ActivityButton(self)
        toolbar_box.toolbar.insert(activity_button, 0)
        activity_button.show()

        title_entry = TitleEntry(self)
        toolbar_box.toolbar.insert(title_entry, -1)
        title_entry.show()

        separator = gtk.SeparatorToolItem()
        separator.props.draw = False
        separator.set_expand(True)
        toolbar_box.toolbar.insert(separator, -1)
        separator.show()

        stop_button = StopButton(self)
        toolbar_box.toolbar.insert(stop_button, -1)
        stop_button.show()

        self.set_toolbar_box(toolbar_box)
        toolbar_box.show()
        
        self.load_data()
        self.cargar_ui()

        # label with the text, make the string translatable
    def cargar_ui(self):
        vbox = gtk.VBox()
        self.set_canvas(vbox)
        self.hbox = gtk.HBox()
        label = gtk.Label()
        self.connect('key-press-event', self.__key_press_cb)
        
        
        vbox.add(self.hbox)
            
        self.image1=gtk.Image()
        self.image1.set_from_file('imagenes/derecha.png')
        self.image1.show()
        self.hbox.pack_start(self.image1)
        
        self.image2=gtk.Image()
        self.image2.set_from_file('imagenes/izquierda.png')
        self.image2.show()
        self.hbox.pack_start(self.image2)
        
        self.image3=gtk.Image()
        self.image3.set_from_file('imagenes/arriba.png')
        self.image3.show()
        self.hbox.pack_start(self.image3)
        
        self.image4=gtk.Image()
        self.image4.set_from_file('imagenes/abajo.png')
        self.image4.show()
        self.hbox.pack_start(self.image4)
            
        vbox.show_all()
            
    def load_data(self):
        parser=SafeConfigParser()
        parser.read('config.ini')
        words= parser.get('inicio','patron')
        self.say (words)    
        
    def leer_patrones(self):
        def leer_patrones(self):
        self.say(self.p)
        #self.controlar_patrones()  
        
    def generar_patrones(self):
        self.patron=['arriba','abajo','izquierda', 'derecha']
        random.shuffle(self.patron)
        self.p="    ".join(self.patron)
        self.hbox.remove(self.image1)
        self.hbox.remove(self.image2)
        self.hbox.remove(self.image3)
        self.hbox.remove(self.image4)
        
        self.image1=gtk.Image()
        self.image1.set_from_file('imagenes/'+self.patron[0]+'.png')
        self.image1.show()
        self.hbox.pack_start(self.image1)
        
                  
        self.image2=gtk.Image()
        self.image2.set_from_file('imagenes/'+self.patron[1]+'.png')
        self.image2.show()
        self.hbox.pack_start(self.image2)
        
                   
        self.image3=gtk.Image()
        self.image3.set_from_file('imagenes/'+self.patron[2]+'.png')
        self.image3.show()
        self.hbox.pack_start(self.image3)
        
                   
        self.image4=gtk.Image()
        self.image4.set_from_file('imagenes/'+self.patron[3]+'.png')
        self.image4.show()
        self.hbox.pack_start(self.image4)
        self.leer_patrones()    
          
            
    def __key_press_cb(self, window, event, label):
        key_name = gtk.gdk.keyval_name(event.keyval)
        if (self.key_name=='Up'):
            self.say ('Arriba')
            self.key_name='arriba'
        elif (self.key_name=='Down'):
            self.say ('Abajo')
            self.key_name='abajo'
        elif (self.key_name=='Left'):
            self.say ('Izquierda')
            self.key_name='izquierda'
        elif (self.key_name=='Right'):
            self.say ('Derecha')
            self.key_name='derecha'
        elif (self.key_name=='space'):
            self.generar_patrones()
        else:
            self.say('Tecla incorrecta')
                       
    def say(self, text):
        Popen(['espeak', '-v', 'es', text])
        
           
if __name__ == "__main__":
    my_app = MyApp()
    gtk.main()