OLD | NEW |
1 # Copyright (c) 2006,2007 Mitch Garnaat http://garnaat.org/ | 1 # Copyright (c) 2006,2007 Mitch Garnaat http://garnaat.org/ |
2 # | 2 # |
3 # Permission is hereby granted, free of charge, to any person obtaining a | 3 # Permission is hereby granted, free of charge, to any person obtaining a |
4 # copy of this software and associated documentation files (the | 4 # copy of this software and associated documentation files (the |
5 # "Software"), to deal in the Software without restriction, including | 5 # "Software"), to deal in the Software without restriction, including |
6 # without limitation the rights to use, copy, modify, merge, publish, dis- | 6 # without limitation the rights to use, copy, modify, merge, publish, dis- |
7 # tribute, sublicense, and/or sell copies of the Software, and to permit | 7 # tribute, sublicense, and/or sell copies of the Software, and to permit |
8 # persons to whom the Software is furnished to do so, subject to the fol- | 8 # persons to whom the Software is furnished to do so, subject to the fol- |
9 # lowing conditions: | 9 # lowing conditions: |
10 # | 10 # |
(...skipping 22 matching lines...) Expand all Loading... |
33 def choose_from_list(self, item_list, search_str='', | 33 def choose_from_list(self, item_list, search_str='', |
34 prompt='Enter Selection'): | 34 prompt='Enter Selection'): |
35 if not item_list: | 35 if not item_list: |
36 print 'No Choices Available' | 36 print 'No Choices Available' |
37 return | 37 return |
38 choice = None | 38 choice = None |
39 while not choice: | 39 while not choice: |
40 n = 1 | 40 n = 1 |
41 choices = [] | 41 choices = [] |
42 for item in item_list: | 42 for item in item_list: |
43 if isinstance(item, str): | 43 if isinstance(item, basestring): |
44 print '[%d] %s' % (n, item) | 44 print '[%d] %s' % (n, item) |
45 choices.append(item) | 45 choices.append(item) |
46 n += 1 | 46 n += 1 |
47 else: | 47 else: |
48 obj, id, desc = item | 48 obj, id, desc = item |
49 if desc: | 49 if desc: |
50 if desc.find(search_str) >= 0: | 50 if desc.find(search_str) >= 0: |
51 print '[%d] %s - %s' % (n, id, desc) | 51 print '[%d] %s - %s' % (n, id, desc) |
52 choices.append(obj) | 52 choices.append(obj) |
53 n += 1 | 53 n += 1 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 val = '' | 106 val = '' |
107 else: | 107 else: |
108 print 'Invalid value: %s' % val | 108 print 'Invalid value: %s' % val |
109 val = '' | 109 val = '' |
110 return val | 110 return val |
111 | 111 |
112 def get_int(self, prompt): | 112 def get_int(self, prompt): |
113 s = self.get_string(prompt, int_val_fn) | 113 s = self.get_string(prompt, int_val_fn) |
114 return int(s) | 114 return int(s) |
115 | 115 |
OLD | NEW |