Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/hMouse.py
blob: 983cc7663751fa7bebcbf017e8af9376d525b4ac (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
from gettext import gettext as _

import sys
sys.path.insert(0, "lib")

import gtk

from sugar.graphics.toolbutton import ToolButton
from sugar.activity import activity
import sugargame.canvas

import logging
import time
import Procesador

class hMouse(activity.Activity):
	def __init__(self, handle):
		activity.Activity.__init__(self, handle)

		self.mCamara = False #si se esta mostrando la camara
		self.pAyuda = 1 #paso de la ayuda

		self._logger = logging.getLogger('hMouse-activity')

		toolbox = activity.ActivityToolbox(self)

		#activity toolbar
		self.activity_tb = toolbox.get_activity_toolbar()
		self.activity_tb.keep.props.visible = False
		self.activity_tb.share.props.visible = False

		#########toolbar hMouse############
		self.hMouseTB = gtk.Toolbar()

		TI = gtk.ToolItem()
		#etiqueta estado
		self.estado = gtk.Label(_("Push Start!"))
		self.estado.set_width_chars(40)
		
		TI.add(self.estado)
		self.estado.show()

		self.hMouseTB.insert(TI, -1)
		TI.show()
		

		#boton calibrar ArrIzq-AbjDer
		self.calibrar0_bt = ToolButton('calibrar0')
		self.calibrar0_bt.set_tooltip(_('Calibrate UpLeft-DownRight'))
		self.hMouseTB.insert(self.calibrar0_bt, -1)
		self.calibrar0_bt.connect('clicked', self.calibrar0)
		self.calibrar0_bt.show()


		#boton calibrar Izq-Der-Arr-Abj
		self.calibrar1_bt = ToolButton('calibrar1')
		self.calibrar1_bt.set_tooltip(_('Calibrate Left-Right-Up-Down'))
		self.hMouseTB.insert(self.calibrar1_bt, -1)
		self.calibrar1_bt.connect('clicked', self.calibrar1)
		self.calibrar1_bt.show()


		#boton calibrar Centro
		self.calibrar2_bt = ToolButton('calibrar2')
		self.calibrar2_bt.set_tooltip(_('Calibrate Center'))
		self.hMouseTB.insert(self.calibrar2_bt, -1)
		self.calibrar2_bt.connect('clicked', self.calibrar2)
		self.calibrar2_bt.show()

		#boton iniciar
		self.iniciar_bt = ToolButton('iniciar')
		self.iniciar_bt.set_tooltip(_('Start'))
		self.hMouseTB.insert(self.iniciar_bt, -1)
		self.iniciar_bt.connect('clicked', self.start)
		self.iniciar_bt.show()

		#boton camara
		self.camara_bt = ToolButton('camara')
		self.camara_bt.set_tooltip(_('Watch camera'))
		self.hMouseTB.insert(self.camara_bt, -1)
		self.camara_bt.connect('clicked', self.camara)
		self.camara_bt.show()

		#boton ayuda
		self.ayuda_bt = ToolButton('ayuda')
		self.ayuda_bt.set_tooltip(_('Help'))
		self.hMouseTB.insert(self.ayuda_bt, -1)
		self.ayuda_bt.connect('clicked', self.ayuda)
		self.ayuda_bt.show()

		#boton acerca
		self.acerca_bt = ToolButton('acerca')
		self.acerca_bt.set_tooltip(_('About...'))
		self.hMouseTB.insert(self.acerca_bt, -1)
		self.acerca_bt.connect('clicked', self.acerca)
		self.acerca_bt.show()

		##############toolbar velocidad################
		self.velTB = gtk.Toolbar()
		
		#boton 1hz
		self.uno_bt = ToolButton('1hz')
		self.uno_bt.set_tooltip(_('Speed 1'))
		self.velTB.insert(self.uno_bt, -1)
		self.uno_bt.connect('clicked', self.uno)
		self.uno_bt.show()
		
		#boton 2hz
		self.dos_bt = ToolButton('2hz')
		self.dos_bt.set_tooltip(_('Speed 2'))
		self.velTB.insert(self.dos_bt, -1)
		self.dos_bt.connect('clicked', self.dos)
		self.dos_bt.show()
		
		#boton 3hz
		self.tres_bt = ToolButton('3hz')
		self.tres_bt.set_tooltip(_('Speed 3'))
		self.velTB.insert(self.tres_bt, -1)
		self.tres_bt.connect('clicked', self.tres)
		self.tres_bt.show()
		
		#boton 4hz
		self.cuatro_bt = ToolButton('4hz')
		self.cuatro_bt.set_tooltip(_('Speed 4'))
		self.velTB.insert(self.cuatro_bt, -1)
		self.cuatro_bt.connect('clicked', self.cuatro)
		self.cuatro_bt.show()


		#toolbox
		toolbox.add_toolbar(_("hMouse"), self.hMouseTB)
		toolbox.show_all()

		#toolbox
		toolbox.add_toolbar(_("Speed"), self.velTB)
		toolbox.show_all()
		
		toolbox.set_current_toolbar(1)
		self.set_toolbox(toolbox)
		toolbox.show()

		#canvas
		self.canv = sugargame.canvas.PygameCanvas(self)
		self.set_canvas(self.canv)

		self.proc = Procesador.Procesador(self.estado)
		time.sleep(2)
		self.canv.run_pygame(self.proc.iniciar)	


	def start(self, boton):
		self.proc.cont = not self.proc.cont
		if self.proc.cont:
			#self.iniciar_bt.set_icon("detener")
			self.iniciar_bt.set_tooltip(_('Stop'))
			self.proc.funcionando()
		else:
			self.iniciar_bt.set_icon("iniciar")
			self.iniciar_bt.set_tooltip(_('Start'))


	def sensibilidad(self, boton, dx, dy):
		self.proc.calibrar2SetSensib(dx, dy)

	def calibrar0(self, boton):
		self.proc.iniciarCalibrado(0)

	def calibrar1(self, boton):
		self.proc.iniciarCalibrado(1)

	def calibrar2(self, boton):
		self.proc.iniciarCalibrado(2)

	def camara(self, boton):
		self.mCamara = not self.mCamara
		if self.mCamara:
			self.proc.mostrarVideo((0,0))
			i=0
			while self.mCamara:
				i+=1
				if i > 60:
					self.proc.updGTK()
					i=0
		else:
			self.proc.dejarDeMostrar()

	def ayuda(self, boton):
		self.ayuda_bt.set_tooltip(_('Next'))
		self.ayuda_bt.set_icon('siguiente')

		self.proc.updFondo()
		self.proc.tutorial(3, self.pAyuda)
		self.pAyuda +=1
		if self.pAyuda >4:
			self.pAyuda = 1
			self.ayuda_bt.set_tooltip(_('Help'))
			self.ayuda_bt.set_icon('ayuda')
			self.proc.updFondo()


	def acerca(self, boton):
		self.proc.updFondo()
		self.proc.tutorial(4, 1)

	def uno (self, boton):
		self.proc.setVel(1)

	def dos (self, boton):
		self.proc.setVel(2)

	def tres (self, boton):
		self.proc.setVel(3)

	def cuatro (self, boton):
		self.proc.setVel(4)

if __name__=='__main__':
	sys.path.insert(0, "lib")
	from Procesador import Procesador
	estado = gtk.Label("Press start!")
	procesador = Procesador(estado)
	procesador.iniciar()
	procesador.iniciarCalibrado(0)