Package actions ::
Module ModeController
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 import sys
17
18 try:
19 PY3 = sys.version_info.major >= 3
20 raw_input = input
21 except AttributeError:
22 PY3 = False
23
24
27
28
29
32 self.mode_list = {}
33 self.force = False
34
35
36 - def on(self, mode_name):
41
42
43 - def off(self, mode_name):
48
49
51 for m in self.mode_list.keys():
52 self.mode_list[m].on()
53
54 if self.mode_list['all'].is_on():
55 self.mode_list['all'].off()
56
57
59 for m in self.mode_list.keys():
60 self.mode_list[m].off()
61
62
63 - def is_on(self, mode_name):
64 if mode_name in self.mode_list:
65 return self.mode_list[mode_name].is_on()
66 else:
67 return 0
68
69
71 if mode_name in self.mode_list:
72 return self.mode_list[mode_name].is_off()
73 else:
74 return 0
75
76
78 mode_name = mode_obj.get_name()
79
80 if not mode_name in self.mode_list:
81 self.mode_list[mode_name] = mode_obj
82
83
85 mode_name = mode_obj.get_name()
86 if mode_name in self.mode_list:
87 del self.mode_list[mode_name]
88
89
92
96
97 - def is_on(self, mode_name):
102
108
109
110
111 - def on(self, mode_name):
112 if mode_name != 'all':
113 if self.is_off('all'):
114 ModeController.on(self, mode_name)
115
116
117 all_modes_on = 1
118 for m in self.mode_list.keys():
119 if m != 'all' and self.mode_list[m].is_off():
120 all_modes_on = 0
121 if all_modes_on:
122 self.all_on()
123 else:
124 self.all_on()
125
126
127
128 - def off(self, mode_name):
129 if mode_name != 'all':
130 if self.is_on('all'):
131 if not self.force:
132 ask_before_continuing("All modes are currently enabled. Continue? (y or n):")
133
134
135 self.all_off()
136
137
138 for m in self.mode_list.keys():
139 if m != 'all':
140 self.mode_list[m].on()
141
142
143 self.mode_list[mode_name].off()
144 else:
145 self.all_off()
146
147
148
149
151
152 self.all_off()
153
154 self.mode_list['all'].on()
155
157 if question is None:
158 the_question = "Continue? (y or n):"
159 else:
160 the_question = question
161
162 answer = '-1'
163
164 while answer != 'y' and answer != 'n':
165 answer = raw_input(the_question)
166 answer = answer.lower()[0]
167
168 if answer == 'n':
169 sys.exit(0)
170