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
|
# 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 10:15:25$"
from threading import Thread
import gobject
gobject.threads_init()
import time
import pygtk
pygtk.require('2.0')
import gtk
class TInterpreterBoard(gtk.EventBox):
def __init__(self):
self.cellList = {}
super(TInterpreterBoard, self).__init__()
self.f = gtk.Fixed()
self.add(self.f)
self.cellResaltada = None
self._backgroundColor = None
self.barriendo = False
self.velocidadBarrido = 2.0
#========SETUP FUNCTIONS========================================================
def setNombre(self, value):
self._nombre = value
def setOrderedCellList(self, list):
self._orderedCellList = list
def setOriginalSize(self, value):
self._originalSize = value
def addCell(self, cell):
self.cellList[cell.getId()] = cell
def setBackgroundColor(self, color):
self._backgroundColor = color
#======GET FUNCTIONS============================================================
def getNombre(self):
return self._nombre
#======INITIALIZATION
def initialize(self):
if self._backgroundColor:
color = self.get_colormap().alloc_color("#" + self._backgroundColor.upper()[2:])
self.modify_bg(gtk.STATE_NORMAL, color)
self.modify_bg(gtk.STATE_PRELIGHT, color)
for cell in self.cellList.itervalues():
cell.initialize()
cell.set_size_request(cell.getWidth(), cell.getHeight())
self.f.put(cell, cell.getX(), cell.getY())
self.show_all()
#======BARRIDO AUTOMATICO=======================================================
def barrer(self):
while self.barriendo:
if self.cellResaltada != None:
gobject.idle_add(self.cellList[self.cellResaltada].desResaltar)
self.cellResaltada = self._orderedCellList[self.barridoActual]
gobject.idle_add(self.cellList[self.cellResaltada].resaltar)
if self.barridoActual < len(self._orderedCellList) - 1:
self.barridoActual += 1
else:
self.barridoActual = 0
time.sleep(self.velocidadBarrido)
def accionarSeleccionado(self, widget, data):
self.cellList[self.cellResaltada].onClick(None)
def iniciarBarrido(self):
self.barriendo = True
# And bind an action to it
#self.set_events(gtk.gdk.BUTTON_PRESS_MASK)
self._handl_id = self.connect("button_press_event", self.accionarSeleccionado)
self.barridoActual = 0
#self.t = Timer(2.0, self.barrerSiguiente)
self.t = Thread(target= self.barrer)
self.t.start()
def detenerBarrido(self):
self.barriendo = False
self.disconnect(self._handl_id)
def setVelocidadBarrido(self, value):
self.velocidadBarrido = value
def getVelocidadBarrido():
return self.velocidadBarrido
if __name__ == "__main__":
print "Hello World"
|