commit ab8736ac5c902cb3672ce97a116759a3d06c463c
Author: Yuyang Guo <yuyang@yuyang-VirtualBox.(none)>
Date:   Wed Feb 13 01:00:50 2013 -0500

    added teleop to GUI, should be able to choose which scout to control now

diff --git a/scout/scoutsim/GUI.py b/scout/scoutsim/GUI.py
index c761e51..9bfacee 100755
--- a/scout/scoutsim/GUI.py
+++ b/scout/scoutsim/GUI.py
@@ -132,6 +132,18 @@ class Scout(object):
                             (self.name, Behaviors.getNumber(self.behavior)))
         self.process = subprocess.Popen(roscommand, shell=False)
 
+    def teleop(self):
+        # teleop involved only one command \
+        self.terminateOldBehavior()
+        self.process = None
+        cmd = "rosservice call /set_teleop %s"%self.name
+        try:
+            subprocess.Popen(shlex.split(cmd), shell=False)
+        except:
+            #not sure why this is happening....
+            # seems to be a ros thing
+            print "warning, socket error, ignored"
+
     def killSelf(self):
         # terminate its current behavior
         self.terminateOldBehavior()
@@ -144,7 +156,7 @@ class Scout(object):
             Scout.numOfScouts -= 1
             self.valid = False
         except rospy.ServiceException, e:
-            print "warning: kill scout unsuccessful" # TODO: change to alert
+            print "warning: kill scout unsuccessful" 
             self.valid = True
         # remove from the class
 
@@ -236,33 +248,23 @@ class GUI(wx.Frame):
             self.window.Update()
         else:
             raise Exception
-
+    
+    # runPressed
     # change UI display and invoke change Behavior in scout
     def changeBehavior(self, name, currBehaviorLabel, 
                         pauseButton, newBehavior):
         
         # to handle user pressing "Run" during pause
         if (newBehavior != "Pause" and self.scouts[name].paused == True):
-            print "trying to do stuff!!!"
             self.correctPauseButton(name, 
                                         pauseButton, pauseToResume=True)
         
         currBehaviorLabel.SetLabel(" | Current Behavior: %s"%newBehavior)
         scout = self.scouts[name]
         scout.changeBehavior(newBehavior)
+        self.correctTeleopButton(None)
 
 
-    def correctPauseButton(self, name, pauseButton, pauseToResume):
-        if (pauseToResume):
-            print "correcting button!"
-            self.scouts[name].paused = False
-            pauseButton.SetValue(False) # unpress it
-            pauseButton.SetLabel("Pause")
-        else:
-            self.scouts[name].paused = True
-            pauseButton.SetValue(True) # press it
-            pauseButton.SetLabel("Resume")
-
     def buttonDown(button):
         return button.GetValue()
 
@@ -281,12 +283,35 @@ class GUI(wx.Frame):
                         dropMenu.GetStringSelection())
             self.correctPauseButton(name, 
                                         pauseButton, pauseToResume=True)
-            
+
+    def teleop(self, name):
+        self.correctTeleopButton(name)
+        self.scouts[name].teleop()
 
     ############################ UI stuff here ###########################
     
     def initUI(self):
+        self.allTeleopButtons = {}
         self.initAddScoutArea()
+    
+    def correctTeleopButton(self, teleopingName):
+        for name in self.allTeleopButtons:
+            if name == teleopingName:
+                self.allTeleopButtons[name].SetValue(True)
+            else:
+                self.allTeleopButtons[name].SetValue(False)
+                
+
+    def correctPauseButton(self, name, pauseButton, pauseToResume):
+        if (pauseToResume):
+            print "correcting button!"
+            self.scouts[name].paused = False
+            pauseButton.SetValue(False) # unpress it
+            pauseButton.SetLabel("Pause")
+        else:
+            self.scouts[name].paused = True
+            pauseButton.SetValue(True) # press it
+            pauseButton.SetLabel("Resume")
 
     # the labels and input boxes for adding a scout through GUI
     def initAddScoutArea(self):
@@ -360,7 +385,7 @@ class GUI(wx.Frame):
         runButton = wx.Button(self.window, label="Run")
         killButton = wx.Button(self.window, label="Kill")
         teleopButton = wx.ToggleButton(self.window, label="Teleop")
-
+        self.allTeleopButtons[name] = teleopButton
         # row 0
         self.sizer[name].Add(scoutName)
         self.sizer[name].Add(currBehaviorLabel, wx.EXPAND | wx.ALIGN_RIGHT)
@@ -383,6 +408,8 @@ class GUI(wx.Frame):
         pauseButton.Bind(wx.EVT_TOGGLEBUTTON, 
             lambda event: self.pauseResumeScout(name, pauseButton,
                                         currBehaviorLabel, scoutChoices))
+        teleopButton.Bind(wx.EVT_TOGGLEBUTTON, 
+                                lambda event: self.teleop(name))
 
         self.mainArea.Add(self.sizer[name], proportion=1,
             flag=wx.ALL | wx.EXPAND, border=10)
