Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAgustin Zubiaga <aguz@sugarlabs.org>2012-06-16 21:03:13 (GMT)
committer Agustin Zubiaga <aguz@sugarlabs.org>2012-06-16 21:03:13 (GMT)
commit286f48f744718ca21abdb0a78eed8b4766c76f1b (patch)
treede45bdcbb1c91f4b7e6db49a698f967ac4c334c2
parent6f35a689e896c1fa3c1c9faa57c580f0da9148e2 (diff)
Usando iconos en el treeview inicial
-rw-r--r--LegoJAM.py42
-rw-r--r--icons/bluetooth.pngbin0 -> 5632 bytes
-rw-r--r--icons/usb.pngbin0 -> 1910 bytes
3 files changed, 27 insertions, 15 deletions
diff --git a/LegoJAM.py b/LegoJAM.py
index 8913a2e..ad0cf16 100644
--- a/LegoJAM.py
+++ b/LegoJAM.py
@@ -34,20 +34,32 @@ class LegoJAM(Window):
robots = list(nxt.locator.find_bricks())
- liststore = gtk.ListStore(int, str)
+ liststore = gtk.ListStore(gtk.gdk.Pixbuf, int, str)
treeview = gtk.TreeView(liststore)
column = gtk.TreeViewColumn('Robots')
- cell = gtk.CellRendererText()
- column.pack_start(cell)
- column.set_attributes(cell, text=1)
+ celltext = gtk.CellRendererText()
+ cellicon = gtk.CellRendererPixbuf()
+ column.pack_start(cellicon, expand=False)
+ column.pack_start(celltext, expand=False)
+ column.add_attribute(cellicon, 'pixbuf', 0)
+ column.add_attribute(celltext, 'text', 2)
treeview.append_column(column)
self.canvas.pack_start(treeview, True, True, 0)
for num, robot in enumerate(robots):
- robot_id = robot.host if robot.type == 'bluetooth' else num+1
- robot_str = '%s %s' % (robot.type, robot_id)
- liststore.append([num, robot_str])
+ if robot.type == 'bluetooth':
+ robot_id = robot.host
+ icon = gtk.gdk.pixbuf_new_from_file_at_size(
+ ' icons/bluetooth.png', 24, 24)
+
+ elif robot.type == 'usb':
+ robot_id = num + 1
+ icon = gtk.gdk.pixbuf_new_from_file_at_size(
+ 'icons/usb.png', 24, 24)
+
+ robot_str = ' %s: %s' % (robot.type.upper(), robot_id)
+ liststore.append([icon, num, robot_str])
treeview.connect('row-activated', self.select_robot, robots)
@@ -85,7 +97,7 @@ class LegoJAM(Window):
battery_status = gtk.Label(
'Estado de la bateria: %s' % self.robot.robot.get_battery_level())
vbox.pack_end(battery_status)
-
+
self.robot.connect('battery-label-changed',
lambda w, l: battery_status.set_text('Estado de la bateria: %s' % l))
@@ -125,7 +137,7 @@ class Robot(gobject.GObject):
def __init__(self, robot):
gobject.GObject.__init__(self)
-
+
self.motorA = None
self.motorB = None
self.motorC = None
@@ -142,9 +154,9 @@ class Robot(gobject.GObject):
self.sonido = Sound(self.robot, PORT_2)
self.ultrasonido = Ultrasonic(self.robot, PORT_4)
self.luz = Light(self.robot, PORT_3)
-
+
gobject.timeout_add(1000, self.handle)
-
+
def run_motor(self, motor):
method_name = 'motor%s' % motor
method = getattr(self, method_name)
@@ -154,22 +166,22 @@ class Robot(gobject.GObject):
method_name = 'motor%s' % motor
method = getattr(self, method_name)
method.brake()
-
+
def handle(self):
valor_boton = self.presion.get_sample()
print 'Botón: ', valor_boton
valor_sonido = self.sonido.get_sample()
print 'Botón: ', valor_sonido
-
+
valor_ultrasonido = self.ultrasonido.get_sample()
print 'Ultrasónico: ', valor_ultrasonido
valor_luz = self.luz.get_sample()
print 'luz: ', valor_luz
-
+
self.emit('battery-label-changed', str(self.robot.get_battery_level()))
-
+
return True
diff --git a/icons/bluetooth.png b/icons/bluetooth.png
new file mode 100644
index 0000000..2667c48
--- /dev/null
+++ b/icons/bluetooth.png
Binary files differ
diff --git a/icons/usb.png b/icons/usb.png
new file mode 100644
index 0000000..2433889
--- /dev/null
+++ b/icons/usb.png
Binary files differ