From 944ec824f8fe3bb5017366098342c9662ee15ae8 Mon Sep 17 00:00:00 2001 From: Gabriel Eirea Date: Sat, 16 Jun 2012 19:19:29 +0000 Subject: Merge branch 'master' of git.sugarlabs.org:~geirea/legojam/legojam-linux-pynxc --- diff --git a/LegoJAM.py b/LegoJAM.py index 868a39a..7a49ea7 100755 --- a/LegoJAM.py +++ b/LegoJAM.py @@ -12,7 +12,7 @@ sys.path.append("nxt_plugin") # Import the API functions # Importamos las funciones de la API import nxt -from nxt import * +from nxt import Motor from interface.window import Window @@ -37,33 +37,50 @@ class LegoJAM(Window): def set_layout(self): canvas = gtk.VBox() - box = gtk.HBox() + store = gtk.ListStore(str, int) + combobox = gtk.ComboBox(store) + cell = gtk.CellRendererText() + combobox.pack_start(cell) + combobox.add_attribute(cell, 'text', 0) + canvas.pack_start(combobox, True, False) + combobox.show() num = 0 for i in ['A', 'B', 'C']: - motor_button = gtk.ToggleButton("Motor %s" % i) - motor_button.id = num - motor_button.show() - motor_button.connect("clicked", self.change_status) - box.pack_start(motor_button) - num += 1 - canvas.pack_start(box, True, True) + store.append(['Motor %s' % i, num]) + combobox.set_active(0) + + vbox = gtk.VBox() + run_button = gtk.Button("Encender") + run_button.show() + run_button.connect_object("clicked", self.run_motor, combobox) + vbox.pack_start(run_button) + stop_button = gtk.Button("Apagar") + stop_button.show() + stop_button.connect_object("clicked", self.stop_motor, combobox) + vbox.pack_start(stop_button) + vbox.show() + num += 1 + + canvas.pack_start(vbox, True, True) self.set_canvas(canvas) - def change_status(self, widget): - if widget.get_active(): - function = self.robot.run_motor - - elif not widget.get_active(): - function = self.robot.stop_motor - - if widget.id == 0: - function("A") - elif widget.id == 1: - function("B") - elif widget.id == 2: - function("C") + def run_motor(self, combobox): + if combobox.get_active() == 0: + self.robot.run_motor("A") + elif combobox.get_active() == 1: + self.robot.run_motor("B") + elif combobox.get_active() == 2: + self.robot.run_motor("C") + + def stop_motor(self, combobox): + if combobox.get_active() == 0: + self.robot.stop_motor("A") + elif combobox.get_active() == 1: + self.robot.stop_motor("B") + elif combobox.get_active() == 2: + self.robot.stop_motor("C") def delete_event(self, widget, event): self.salir() @@ -91,7 +108,7 @@ class Pancho(): def set_up(self): try: - self.robot = nxt.locator.find_one_brick(debug=True) + self.robot = nxt.locator.find_one_brick() for funcion in dir(self.robot): self.funciones.append(funcion) print funcion @@ -99,9 +116,9 @@ class Pancho(): except: print "El Robot se Encuentra Desconectado o Apagado" sys.exit(0) - self.motorA = Mimotor("A", self.robot, PORT_A) - self.motorB = Mimotor("B", self.robot, PORT_B) - self.motorC = Mimotor("C", self.robot, PORT_C) + self.motorA = Mimotor("A", self.robot, nxt.PORT_A) + self.motorB = Mimotor("B", self.robot, nxt.PORT_B) + self.motorC = Mimotor("C", self.robot, nxt.PORT_C) def run_motor(self, motor): if motor == "A": -- cgit v0.9.1