Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/TInterpreter.py
blob: aef5706d9b6d49d81abcdaf0d828db7ffa2cdd46 (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
#   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__ = "$20-sep-2012 12:16:32$"

from TInterpreterProject import TInterpreterProject
from util.OpenNewProject import OpenNewProject
from util.ChooseProject import ChooseProject
import pygtk
pygtk.require('2.0')
import gtk
import os
import sys

class TInterpreter:
    PROYECTOS = "proyectos"

    def __init__(self):        
        self.project = TInterpreterProject()

    def load(self, xml):
        self.project.XMLDecode(xml)
        self.project.setCurrentBoard(self.project.getInitialBoard())
        self.project.show_all()


    def getContenedor(self):
        return self.project

    def exit(self, widget, data=None):
        gtk.main_quit()
        sys.exit
        
    def barrido(self, otro=None):
        self.project.barrido()

    def cambiarVelocidad(self, value):
        self.project.cambiarVelocidad(value)



#PARA EL FUNCIONAMIENTO FUERA DE SUGAR
    def mainPropio(self):
        #self.project.XMLDecode("proyectos/Muestra/project.xml")
        #self.project.setCurrentBoard(self.project.getInitialBoard())

        self.win = gtk.Window()
        w = self.win
        w.connect("destroy", self.exit)
        
        self.container = gtk.VBox();
        
        self.toolbar = gtk.Toolbar()
        self.toolbar.append_item("Agregar", "Agregar Proyecto", None, None, self.__agregar) 
        self.toolbar.append_item("Abrir", "Abrir Proyecto", None, None, self.__abrir) 
        self.toolbar.append_item("Barrido", "Barrido Automatico", None, None, self.barrido) 
        self.toolbar.show()      
        self.container.pack_start(self.toolbar)
        
        self.container.pack_start(self.project)   
        
        w.add(self.container)    
        
        w.show_all()


        gtk.main()
        
    def __agregar(self, widget):
        dialog = gtk.FileChooserDialog(title="Abrir", action=gtk.FILE_CHOOSER_ACTION_OPEN, buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK))
        response = dialog.run()
        if response == gtk.RESPONSE_OK:
            try:
                onp = OpenNewProject(dialog.get_filename(), os.path.basename(dialog.get_filename()))
                self.load(os.path.join(self.PROYECTOS, onp.getProjectName(), "project.xml"),)
            except Exception, e:
                print "Exception: ", e
        elif response == gtk.RESPONSE_CANCEL:
            print 'Closed, no files selected'
        
        dialog.destroy()
        
    def __abrir(self, widget):
        abr = ChooseProject(self.PROYECTOS)
        abr.addOnAbrirListener(self.__abierto)
        abr.show()
        
    def __abierto(self, proyName):
        self.load(os.path.join(self.PROYECTOS, proyName, "project.xml"),)

    

if __name__ == "__main__":
    b = TInterpreter()
    b.mainPropio()