Revision ab8736ac scout/scoutsim/GUI.py

View differences:

scout/scoutsim/GUI.py
132 132
                            (self.name, Behaviors.getNumber(self.behavior)))
133 133
        self.process = subprocess.Popen(roscommand, shell=False)
134 134

  
135
    def teleop(self):
136
        # teleop involved only one command \
137
        self.terminateOldBehavior()
138
        self.process = None
139
        cmd = "rosservice call /set_teleop %s"%self.name
140
        try:
141
            subprocess.Popen(shlex.split(cmd), shell=False)
142
        except:
143
            #not sure why this is happening....
144
            # seems to be a ros thing
145
            print "warning, socket error, ignored"
146

  
135 147
    def killSelf(self):
136 148
        # terminate its current behavior
137 149
        self.terminateOldBehavior()
......
144 156
            Scout.numOfScouts -= 1
145 157
            self.valid = False
146 158
        except rospy.ServiceException, e:
147
            print "warning: kill scout unsuccessful" # TODO: change to alert
159
            print "warning: kill scout unsuccessful" 
148 160
            self.valid = True
149 161
        # remove from the class
150 162

  
......
236 248
            self.window.Update()
237 249
        else:
238 250
            raise Exception
239

  
251
    
252
    # runPressed
240 253
    # change UI display and invoke change Behavior in scout
241 254
    def changeBehavior(self, name, currBehaviorLabel, 
242 255
                        pauseButton, newBehavior):
243 256
        
244 257
        # to handle user pressing "Run" during pause
245 258
        if (newBehavior != "Pause" and self.scouts[name].paused == True):
246
            print "trying to do stuff!!!"
247 259
            self.correctPauseButton(name, 
248 260
                                        pauseButton, pauseToResume=True)
249 261
        
250 262
        currBehaviorLabel.SetLabel(" | Current Behavior: %s"%newBehavior)
251 263
        scout = self.scouts[name]
252 264
        scout.changeBehavior(newBehavior)
265
        self.correctTeleopButton(None)
253 266

  
254 267

  
255
    def correctPauseButton(self, name, pauseButton, pauseToResume):
256
        if (pauseToResume):
257
            print "correcting button!"
258
            self.scouts[name].paused = False
259
            pauseButton.SetValue(False) # unpress it
260
            pauseButton.SetLabel("Pause")
261
        else:
262
            self.scouts[name].paused = True
263
            pauseButton.SetValue(True) # press it
264
            pauseButton.SetLabel("Resume")
265

  
266 268
    def buttonDown(button):
267 269
        return button.GetValue()
268 270

  
......
281 283
                        dropMenu.GetStringSelection())
282 284
            self.correctPauseButton(name, 
283 285
                                        pauseButton, pauseToResume=True)
284
            
286

  
287
    def teleop(self, name):
288
        self.correctTeleopButton(name)
289
        self.scouts[name].teleop()
285 290

  
286 291
    ############################ UI stuff here ###########################
287 292
    
288 293
    def initUI(self):
294
        self.allTeleopButtons = {}
289 295
        self.initAddScoutArea()
296
    
297
    def correctTeleopButton(self, teleopingName):
298
        for name in self.allTeleopButtons:
299
            if name == teleopingName:
300
                self.allTeleopButtons[name].SetValue(True)
301
            else:
302
                self.allTeleopButtons[name].SetValue(False)
303
                
304

  
305
    def correctPauseButton(self, name, pauseButton, pauseToResume):
306
        if (pauseToResume):
307
            print "correcting button!"
308
            self.scouts[name].paused = False
309
            pauseButton.SetValue(False) # unpress it
310
            pauseButton.SetLabel("Pause")
311
        else:
312
            self.scouts[name].paused = True
313
            pauseButton.SetValue(True) # press it
314
            pauseButton.SetLabel("Resume")
290 315

  
291 316
    # the labels and input boxes for adding a scout through GUI
292 317
    def initAddScoutArea(self):
......
360 385
        runButton = wx.Button(self.window, label="Run")
361 386
        killButton = wx.Button(self.window, label="Kill")
362 387
        teleopButton = wx.ToggleButton(self.window, label="Teleop")
363

  
388
        self.allTeleopButtons[name] = teleopButton
364 389
        # row 0
365 390
        self.sizer[name].Add(scoutName)
366 391
        self.sizer[name].Add(currBehaviorLabel, wx.EXPAND | wx.ALIGN_RIGHT)
......
383 408
        pauseButton.Bind(wx.EVT_TOGGLEBUTTON, 
384 409
            lambda event: self.pauseResumeScout(name, pauseButton,
385 410
                                        currBehaviorLabel, scoutChoices))
411
        teleopButton.Bind(wx.EVT_TOGGLEBUTTON, 
412
                                lambda event: self.teleop(name))
386 413

  
387 414
        self.mainArea.Add(self.sizer[name], proportion=1,
388 415
            flag=wx.ALL | wx.EXPAND, border=10)

Also available in: Unified diff