Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/TInterpreterProject.py
blob: 29755041f2c5f9343007b1480f2ff8129ae9450e (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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
# -*- coding: utf-8 -*-
#   Tixo - A Sugar interpreter for TICO projects
#   Copyright (C) 2012  Rodrigo Perez Fulloni
#   Fundacion Teleton Uruguay - Departamento de Ingenieria
#
#   Based on TICO Project: http://www.proyectotico.com/
#
#
#    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 3 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, see <http://www.gnu.org/licenses/>.

__author__ = "Rodrigo"
__date__ = "$18-sep-2012 12:35:06$"

from components.TInterpreterTextArea import TInterpreterTextArea
from components.TInterpreterControlCell import TInterpreterControlCell
from components.TInterpreterAcumulatedCell import TInterpreterAcumulatedCell
from TInterpreterBoard import TInterpreterBoard
from components.TInterpreterCell import TInterpreterCell
import xml.etree.ElementTree as ET

import pygtk
pygtk.require('2.0')
import gtk
import os

import string

class TInterpreterProject(gtk.VBox):
    PROYECTOS = "proyectos"
    

    def __init__(self):
        super(TInterpreterProject, self).__init__()
        self.currentBoard = None
        self.boardList = {}
        self.acumuladas = []
        self.acumuladasContainer = gtk.HBox(False, 0)
        self.pack_end(self.acumuladasContainer)
        self.show_all()

        self.barriendo = False
        self.velActual = 2.0

    def __getRealPath(self, path):
        path = string.replace(path, "\\", os.sep)
        path = string.replace(path, "/", os.sep)
        

        salida = os.path.join(self.PROYECTOS, self.projectName, path)
        return salida

        



    def XMLDecode(self, file):
        tree = ET.parse(file)
        root = tree.getroot()

        self.projectName = root.attrib["name"]
        TInterpreterCell.projectName = self.projectName
        self.initialBoard = root.find("initial_board").text

        for boardXML in root.findall("board"):
            board = TInterpreterBoard()
            board.setNombre(boardXML.attrib["name"])

            model = boardXML.find("model")

            for attrXML in model.find("attributes").findall("attribute"):
                key = attrXML.get("key")

                if key == "imageResizeStyle":
                    pass
                elif key == "orderedCellList":
                    orderedCellList = []
                    for cell in attrXML.findall("element"):
                        orderedCellList.append(cell.text)
                    board.setOrderedCellList(orderedCellList)
                elif key == "size":
                    width = int(float(attrXML.find("width").text))
                    height = int(float(attrXML.find("height").text))
                    board.setOriginalSize((width, height))
                elif key == "soundFile":
                    pass
                elif key == "icon":
                    pass
                elif key == "backgroundColor":
                    board.setBackgroundColor(attrXML.text)
                elif key == "gradientColor":
                    pass

            for compXML in model.findall("component"):
                type = compXML.get("type")

                if type == "cell":
                    cell = TInterpreterCell()

                    for attrXML in compXML.find("attributes").findall("attribute"):
                        key = attrXML.get("key")

                        if key == "followingBoard":
                            cell.setFollowingBoard(attrXML.text, self.setCurrentBoard)                        

                        elif key == "backgroundColor":
                            cell.setBackgroundColor(attrXML.text)

                        elif key == "gradientColor":
                            pass

                        elif key == "bordercolor":
                            cell.setBorderColor(attrXML.text)

                        elif key == "linewidth":
                            cell.setBorderWidth(int(float(attrXML.text)))                        

                        elif key=="environmentAction":
                            pass                        

                        elif key=="alternativeBorderColor":
                            cell.setAlternativeBorderColor(attrXML.text)

                        elif key=="alternativeLinewidth":
                            cell.setAlternativeBorderWidth(attrXML.text)

                        elif key=="accumulated":
                            acumulable = True if attrXML.text == "true" else False
                            cell.setAcumulable(acumulable, self.acumular)

                        elif key=="sendTextTimer":
                            pass

                        elif key=="sendTextTarget":
                            cell.setSendTextTarget(attrXML.text)

                        elif key=="sendText":
                            cell.setSendText(attrXML.text)

                        elif key=="alternativeIcon":
                            cell.setAlternativeIcon(self.__getRealPath(attrXML.text))
                        elif key=="verticalTextPosition":
                            cell.setVerticalTextPosition(attrXML.text)

                        elif key=="soundFile":
                            cell.setSoundFile(self.__getRealPath(attrXML.text))
                            
                        elif key=="alternativeSoundFile":
                            cell.setAlternativeSoundFile(self.__getRealPath(attrXML.text))

                        elif key=="voiceName":
                            pass
                        elif key=="voiceText":
                            cell.setVoiceText(attrXML.text)
                        elif key=="videoFile":
                            pass
                        elif key=="videoURL":
                            pass                    

                elif type == "controllerCell":
                    cell = TInterpreterControlCell()

                    for attrXML in compXML.find("attributes").findall("attribute"):
                        key = attrXML.get("key")
                        
                        if key=="actionCode":
                            code = int(attrXML.text)

                            if code == TInterpreterControlCell.EXIT_ACTION_CODE:
                                cell.setActionCode(code)
                            elif code == TInterpreterControlCell.UNDO_ACTION_CODE:
                                cell.setActionCode(code, self.desAcumular)
                            elif code == TInterpreterControlCell.UNDO_ALL_ACTION_CODE:
                                cell.setActionCode(code, self.desAcumularTodas)
                            elif code == TInterpreterControlCell.HOME_ACTION_CODE:                                
                                cell.setActionCode(code, self.irAInicial)
                            elif code==TInterpreterControlCell.READ_ACTION_CODE:
                                cell.setActionCode(code, self.readAcumuladas)


                elif type == "line":
                    pass

                elif type == "oval":
                    pass

                elif type == "rectangle":
                    pass

                elif type == "textArea":
                    cell = TInterpreterTextArea()

                    for attrXML in compXML.find("attributes").findall("attribute"):

                        if key=="horizontalAlignment":
                            pass
                        elif key == "verticalAlignment":
                            pass
                elif type == "roundRect":
                    pass
                elif type=="label":
                    pass


                #common attributes
                if type == "cell" or type == "controllerCell":
                    for attrXML in compXML.find("attributes").findall("attribute"):
                        key = attrXML.get("key")

                        if key == "font":
                            cell.setFontFamily(attrXML.find("family").text)
                            cell.setFontSize(int(attrXML.find("size").text))

                            bold = False if attrXML.find("bold") == None else True
                            cell.setFontBold(bold)

                            italic = False if attrXML.find("italic") == None else True
                            cell.setFontBold(italic)

                        elif key == "id":
                            cell.setId(attrXML.text)

                        elif key=="foregroundColor":
                            cell.setForegroundColor(attrXML.text)

                        elif key == "bounds":
                            x = int(float(attrXML.find("x").text))
                            y = int(float(attrXML.find("y").text))
                            width = int(float(attrXML.find("width").text))
                            height = int(float(attrXML.find("height").text))

                            cell.setOriginalRect((x, y, width, height))

                        elif key == "text":
                            cell.setText(attrXML.text)

                        elif key=="icon":
                            cell.setIcon(self.__getRealPath(attrXML.text))




                #agregar al tablero
                if type == "cell" or type == "controllerCell":
                    board.addCell(cell)
                                            


            self.boardList[board.getNombre()] = board
            


#========PROJECT ACTIONS========================================================
        
    def setCurrentBoard(self, nombre):
        if self.currentBoard != None:
            if self.barriendo:
                self.currentBoard.detenerBarrido()
            self.remove(self.currentBoard)

        board = self.boardList[nombre]
        board.initialize()
        self.pack_start(board)
        self.currentBoard = board

        if self.barriendo:
            self.currentBoard.iniciarBarrido()
        

    def acumular(self, cell):
        acu = TInterpreterAcumulatedCell(cell)
        self.acumuladasContainer.pack_start(acu, False, False, 0)
        acu.set_size_request(acu.getWidth(), acu.getHeight())
        acu.show_all()
        self.acumuladas.append(acu)

    def desAcumular(self):
        if len(self.acumuladas) > 0:
            self.acumuladasContainer.remove(self.acumuladas.pop())

    def desAcumularTodas(self):
        for acu in self.acumuladas:
            self.acumuladasContainer.remove(acu)
        self.acumuladas = []

    def irAInicial(self):
        self.setCurrentBoard(self.getInitialBoard())
        
    def readAcumuladas(self):
        for acu in self.acumuladas:
            acu.leer()

    def barrido(self):
        if not self.barriendo:
            self.cambiarVelocidad(self.velActual)
            self.currentBoard.iniciarBarrido()
            self.barriendo = True
        else:
            self.currentBoard.detenerBarrido()
            self.barriendo = False

    def cambiarVelocidad(self, value):
        self.velActual = value
        self.currentBoard.setVelocidadBarrido(value)



#=========GET===================================================================

    def getInitialBoard(self):
        return self.initialBoard

    def getProjectName(self):
        return self.projectName


if __name__ == "__main__":
    x = TInterpreterProject()
    x.XMLDecode("proyectos/Muestra/project.xml")