Revision 6350051e scout/scoutsim/GUI.py

View differences:

scout/scoutsim/GUI.py
19 19
# ros imports for spawning and killing scout
20 20
import rospy
21 21
import roslib
22
import os
22 23
roslib.load_manifest("scoutsim")
23 24

  
24 25
# scoutsim imports
......
36 37
                          "Navigation Map", "Scheduler", "Warehouse",
37 38
                          "Line Follow", "WL Test", "Maze Solve"]
38 39
    @classmethod
40
    def getListFromDir(self):
41
        behaviors = []
42
        for path, dirname, fnames in os.walk('../libscout/src'):
43
            if 'src/behaviors' in path or 'src/test_behaviors' in path:
44
                path_parts = path.split('/')
45

  
46
                for f in sorted(fnames):
47
                    # The pause_scout behavior needs to go first!
48
                    if f.endswith('.h') and 'pause_scout' in f:
49
                        behaviors.insert(0, f.split('.')[0])
50
                    # Everything else goes in alphabetical order
51
                    elif f.endswith('.h'):
52
                        behaviors.append(f.split('.')[0])
53
        return behaviors
54

  
55
    @classmethod
39 56
    def getNumber(self, behaviorName):
40
        if (behaviorName in Behaviors.behaviors):
41
            return Behaviors.behaviors.index(behaviorName)
57
        behaviors = self.getListFromDir()
58
        if (behaviorName in behaviors):
59
            return behaviors.index(behaviorName)
42 60
    
43 61
    @classmethod
44 62
    def getName(self, index):
63
        behaviors = self.getListFromDir()
45 64
        if (0 <= index < len(self.Behavior)):
46
            return Behaviors.behaviors[index]
65
            return behaviors[index]
47 66
        else:
48 67
            return -1
49 68
    
50 69
    @classmethod
51 70
    def getBehaviors(self):
52 71
        # "Pause" is not considered a behavior in GUI
53
        return Behaviors.behaviors[1:]
72
        behaviors = self.getListFromDir()
73
        return behaviors[1:]
54 74

  
55 75
# each scout is represented by this class
56 76
class Scout(object):

Also available in: Unified diff