Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/Widgets.py
diff options
context:
space:
mode:
Diffstat (limited to 'Widgets.py')
-rw-r--r--Widgets.py221
1 files changed, 221 insertions, 0 deletions
diff --git a/Widgets.py b/Widgets.py
new file mode 100644
index 0000000..9eb90f0
--- /dev/null
+++ b/Widgets.py
@@ -0,0 +1,221 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+# CeibalJAM! - Uruguay
+
+import gtk
+import os
+import cairo
+import gobject
+import Globales as G
+
+class CanvasRobot(gtk.VBox):
+ def __init__(self):
+ gtk.VBox.__init__(self)
+ self.motores_sensores = Motores_Sensores()
+ self.bateria = Bateria()
+
+ self.pack_start(self.motores_sensores, True, True, 0)
+ self.pack_start(self.bateria, False, False, 0)
+
+ self.show_all()
+
+class Motores_Sensores(gtk.HBox):
+ def __init__(self):
+ gtk.HBox.__init__(self)
+ self.motores = Motores()
+ self.sensores = Sensores()
+ self.pack_start(self.motores, True, True, 0)
+ self.pack_start(self.sensores, True, True, 0)
+ self.show_all()
+
+class Motores(gtk.VBox):
+ def __init__(self):
+ gtk.VBox.__init__(self)
+ self.widgetMotorA = BotonMotor()
+ self.widgetMotorA.set_tooltip("Motor A")
+ self.widgetMotorB = BotonMotor()
+ self.widgetMotorB.set_tooltip("Motor B")
+ self.widgetMotorC = BotonMotor()
+ self.widgetMotorC.set_tooltip("Motor C")
+ motores = [self.widgetMotorA, self.widgetMotorB,
+ self.widgetMotorC]
+ for motor in motores:
+ motor.set_imagen(os.path.join(G.ICONOS, 'motor.png'))
+ self.pack_start(motor, True, True, 0)
+ self.show_all()
+
+class Sensores(gtk.VBox):
+ def __init__(self):
+ gtk.VBox.__init__(self)
+
+ self.widget_presion = ControlSensor()
+ self.widget_presion.set_imagen(os.path.join(G.ICONOS, 'presion.png'))
+ self.widget_presion.set_tooltip("Sensor de Presión")
+ self.widget_sonido = ControlSensor()
+ self.widget_sonido.set_imagen(os.path.join(G.ICONOS, 'sonido.png'))
+ self.widget_sonido.set_tooltip("Sensor de Sonido")
+ self.widget_ultrasonido = ControlSensor()
+ self.widget_ultrasonido.set_imagen(os.path.join(G.ICONOS, 'ultrasonido.png'))
+ self.widget_ultrasonido.set_tooltip("Sensor de Ultrasonido")
+ self.widget_luz = ControlSensor()
+ self.widget_luz.set_imagen(os.path.join(G.ICONOS, 'luz.png'))
+ self.widget_luz.set_tooltip("Sensor de Luz")
+
+ hbox1 = gtk.HBox()
+ hbox1.pack_start(self.widget_presion, True, True, 0)
+ hbox1.pack_start(self.widget_sonido, True, True, 0)
+ hbox2 = gtk.HBox()
+ hbox2.pack_start(self.widget_ultrasonido, True, True, 0)
+ hbox2.pack_start(self.widget_luz, True, True, 0)
+
+ self.pack_start(hbox1, True, True, 0)
+ self.pack_start(hbox2, True, True, 0)
+ self.show_all()
+
+class ControlSensor(gtk.VBox):
+ def __init__(self):
+ gtk.VBox.__init__(self)
+ self.botonsensor = BotonSensor()
+ self.barradeprogreso = Barra_de_Progreso()
+ self.pack_start(self.botonsensor, True, True, 0)
+ self.pack_start(self.barradeprogreso, False, False, 0)
+ self.show_all()
+
+ def set_tooltip(self, texto):
+ self.botonsensor.set_tooltip(texto)
+
+ def set_imagen(self, archivo):
+ self.botonsensor.set_imagen(archivo)
+
+class BotonSensor(gtk.EventBox):
+ def __init__(self):
+ gtk.EventBox.__init__(self)
+ self.set_visible_window(True)
+ self.modify_bg(gtk.STATE_NORMAL, G.BLANCO)
+ self.set_border_width(1)
+ self.imagen = None
+ self.show_all()
+ self.connect('expose-event', self.repintar)
+
+ def set_tooltip(self, texto):
+ tooltips = gtk.Tooltips()
+ tooltips.set_tip(self, texto, tip_private=None)
+
+ def set_imagen(self, archivo):
+ self.imagen = cairo.ImageSurface.create_from_png(archivo)
+
+ def set_tamanio(self, w, h):
+ self.set_size_request(w,h)
+
+ def repintar(self, widget, senial):
+ imgpat = cairo.SurfacePattern(self.imagen)
+ scaler = cairo.Matrix()
+
+ x,y,w,h = self.get_allocation()
+ width = float(self.imagen.get_width())
+ height = float(self.imagen.get_height())
+ ws = float(width/float(w))
+ hs = float(height/float(h))
+
+ scaler.scale(ws, hs)
+ imgpat.set_matrix(scaler)
+ imgpat.set_filter(cairo.FILTER_BEST)
+
+ cr = self.window.cairo_create()
+ cr.set_source(imgpat)
+ cr.paint()
+
+ return True
+
+class BotonMotor(BotonSensor):
+ __gsignals__ = {"clicked":(gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT, ))}
+ def __init__(self):
+ BotonSensor.__init__(self)
+ self.add_events(gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.BUTTON_RELEASE_MASK | gtk.gdk.POINTER_MOTION_MASK |
+ gtk.gdk.ENTER_NOTIFY_MASK | gtk.gdk.LEAVE_NOTIFY_MASK)
+ self.on = False
+ self.normal = G.BLANCO
+ self.clicked = G.NARANJA
+ self.enter = G.AMARILLO
+ self.connect("button_press_event", self.button_press)
+ self.connect("button_release_event", self.button_release)
+ self.connect("enter-notify-event", self.enter_notify_event)
+ self.connect("leave-notify-event", self.leave_notify_event)
+
+ def button_release(self, widget, event):
+ self.modify_bg(gtk.STATE_NORMAL, self.enter)
+ def leave_notify_event(self, widget, event):
+ self.modify_bg(gtk.STATE_NORMAL, self.normal)
+ def enter_notify_event(self, widget, event):
+ self.modify_bg(gtk.STATE_NORMAL, self.enter)
+ def button_press(self, widget, event):
+ if event.button == 1:
+ if not self.on:
+ self.modify_bg(gtk.STATE_NORMAL, self.clicked)
+ self.on = True
+ self.normal = G.NARANJA
+ self.enter = G.NARANJA
+ else:
+ self.modify_bg(gtk.STATE_NORMAL, G.AMARILLO)
+ self.on = False
+ self.normal = G.BLANCO
+ self.enter = G.AMARILLO
+ self.emit("clicked", event)
+
+class Bateria(gtk.HBox):
+ def __init__(self):
+ gtk.HBox.__init__(self)
+ etiqueta = gtk.Label("Batería: ")
+ self.barradeprogreso = Barra_de_Progreso()
+ self.pack_start(etiqueta, False, False, 0)
+ self.pack_start(self.barradeprogreso, True, True, 0)
+
+ self.show_all()
+
+class Barra_de_Progreso(gtk.EventBox):
+ def __init__(self):
+ gtk.EventBox.__init__(self)
+ self.scale = ProgressBar(gtk.Adjustment(0.0, 0.0, 101.0, 0.1, 1.0, 1.0))
+ self.valor = 0
+ self.add(self.scale)
+ self.show_all()
+
+ def set_progress(self, valor = 0):
+ self.scale.set_value(valor)
+
+class ProgressBar(gtk.HScale):
+ def __init__(self, ajuste):
+ gtk.HScale.__init__(self, ajuste)
+ self.ajuste = ajuste
+ self.set_digits(0)
+ self.set_draw_value(False)
+ self.x, self.y, self.w, self.h = (0,0,200,40)
+ self.borde, self.ancho = (15, 10)
+ self.connect("expose_event", self.expose)
+ self.connect("size-allocate", self.size_allocate)
+
+ def expose( self, widget, event ):
+ x, y, w, h = (self.x, self.y, self.w, self.h)
+ ancho, borde = (self.ancho, self.borde)
+ gc = gtk.gdk.Drawable.new_gc(self.window)
+ gc.set_rgb_fg_color(G.BLANCO)
+ self.window.draw_rectangle( gc, True, x, y, w, h )
+ gc.set_rgb_fg_color(G.AMARILLO)
+ ww = w- borde*2
+ xx = x+ w/2 - ww/2
+ hh = ancho
+ yy = y+ h/2 - ancho/2
+ self.window.draw_rectangle( gc, True, xx, yy, ww, hh )
+ anchoimagen, altoimagen = (25,25)
+ ximagen = int((xx- anchoimagen/2) + self.get_value() * (ww / (self.ajuste.upper - self.ajuste.lower)))
+ yimagen = yy + hh/2 - altoimagen/2
+ gc.set_rgb_fg_color(G.NARANJA)
+ self.window.draw_rectangle( gc, True, xx, yy, ximagen, hh)
+ gc.set_rgb_fg_color(G.BLANCO)
+ self.window.draw_rectangle( gc, False, xx, yy, ww, hh )
+ return True
+
+ def size_allocate( self, widget, allocation ):
+ self.x, self.y, self.w, self.h= allocation
+ return False \ No newline at end of file