3
# openipmi GUI handling for controls
5
# Author: MontaVista Software, Inc.
6
# Corey Minyard <minyard@mvista.com>
9
# Copyright 2005 MontaVista Software Inc.
11
# This program is free software; you can redistribute it and/or
12
# modify it under the terms of the GNU Lesser General Public License
13
# as published by the Free Software Foundation; either version 2 of
14
# the License, or (at your option) any later version.
17
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
18
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
22
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
23
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
25
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
26
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
# You should have received a copy of the GNU Lesser General Public
29
# License along with this program; if not, write to the Free
30
# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
38
class ControlRefreshData:
39
def __init__(self, c):
43
def control_cb(self, control):
44
if (self.c.control_type == OpenIPMI.CONTROL_IDENTIFIER):
45
control.identifier_get_val(self.c)
46
elif (self.c.setting_light):
47
control.get_light(self.c)
49
control.get_val(self.c)
56
def __init__(self, c):
60
def HandleMenu(self, event):
61
gui_popup.popup(self.c.ui, event,
62
[ [ "Modify Value", self.modval ],
63
[ "Set to 0", self.SetTo0 ],
64
[ "Set to 1", self.SetTo1 ] ])
67
def modval(self, event):
69
while (len(vals) < self.c.num_vals):
72
gui_setdialog.SetDialog("Set Control Values for " + self.c.name,
78
def SetTo0(self, event):
80
self.c.control_id.to_control(self)
83
def SetTo1(self, event):
85
self.c.control_id.to_control(self)
91
self.ival.append(int(val))
93
self.c.control_id.to_control(self)
96
def control_cb(self, control):
97
if (self.c.control_type == OpenIPMI.CONTROL_IDENTIFIER):
98
control.identifier_set_val(self.ival)
100
control.set_val(self.ival)
104
def do_on_close(self):
110
def __init__(self, c):
114
def HandleMenu(self, event):
115
gui_popup.popup(self.c.ui, event, [ [ "Modify Value", self.modval ] ])
118
def modval(self, event):
119
gui_lightset.LightSet("Set Light Values for " + self.c.name,
120
self.c.num_vals, self.c.lights, self.c.vals,
125
self.ival = ';'.join(val)
126
self.c.control_id.to_control(self)
129
def control_cb(self, control):
130
rv = control.set_light(self.ival)
132
raise ValueError("set_light failed: " + str(rv))
136
def __init__(self, e, control):
138
self.name = control.get_name()
139
e.controls[self.name] = self
140
self.control_type_str = control.get_type_string()
141
self.control_id = control.get_id()
143
self.updater = ControlRefreshData(self)
145
self.ui.add_control(self.e, self)
146
self.control_type = control.get_type()
147
self.destroyed = False
148
if (self.control_type == OpenIPMI.CONTROL_IDENTIFIER):
149
self.num_vals = control.identifier_get_max_length();
151
self.num_vals = control.get_num_vals();
154
if ((self.control_type == OpenIPMI.CONTROL_LIGHT)
155
and (control.light_set_with_setting())):
156
self.setting_light = True
158
for i in range (0, self.num_vals):
159
lc = control.light_has_local_control(i)
161
for j in range (0, OpenIPMI.CONTROL_NUM_COLORS):
162
if control.light_is_color_supported(i, j):
163
colors.append(OpenIPMI.color_string(j))
166
self.lights.append((lc, colors))
170
self.setting_light = False
173
self.is_settable = control.is_settable()
174
self.is_readable = control.is_readable()
175
if (self.is_settable):
176
if (self.setting_light):
177
self.setter = LightSet(self)
179
self.setter = ControlSet(self)
186
self.ui.prepend_item(self, "Control Type", self.control_type_str)
188
if (control.has_events()):
189
cs.append("generates_events")
191
if (self.is_settable):
192
cs.append("settable")
194
if (self.is_readable):
195
cs.append("readable")
197
self.ui.append_item(self, "Control Capabilities", ' '.join(cs))
198
if (self.control_type == OpenIPMI.CONTROL_LIGHT):
199
self.ui.append_item(self, "Num Lights", str(self.num_vals))
200
if (self.setting_light):
201
self.ui.append_item(self, "Light Type", "setting")
202
for i in range(0, self.num_vals):
204
if control.light_has_local_control(i):
205
cap.append("local_control")
207
for j in range (0, OpenIPMI.CONTROL_NUM_COLORS):
208
if control.light_is_color_supported(i, j):
209
cap.append(OpenIPMI.color_string(j))
212
self.ui.append_item(self, "Light" + str(i), ' '.join(cap))
216
self.ui.append_item(self, "Light Type", "transition")
217
for i in range(0, self.num_vals):
219
for j in range (0, control.get_num_light_values(i)):
221
for k in range (0,control.get_num_light_transitions(i, j)):
223
val = control.get_light_color(i, j, k)
224
cap3.append(OpenIPMI.color_string(val))
225
val = control.get_light_color_time(i, j, k)
226
cap3.append(OpenIPMI.color_string(val))
231
self.ui.append_item(self, "Light" + str(i), str(cap))
235
elif (self.control_type == OpenIPMI.CONTROL_IDENTIFIER):
236
self.ui.append_item(self, "Max Length", str(self.num_vals))
238
self.ui.append_item(self, "Num Vals", str(self.num_vals))
246
if (self.is_readable):
247
self.control_id.to_control(self.updater)
251
def HandleMenu(self, event):
252
if (self.setter != None):
253
self.setter.HandleMenu(event)
257
def control_get_val_cb(self, control, err, vals):
261
self.ui.set_item_text(self.treeroot, None)
263
self.num_vals = control.get_num_vals();
265
self.ui.set_item_text(self.treeroot, str(vals))
268
def control_get_id_cb(self, control, err, val):
272
self.ui.set_item_text(self.treeroot, None)
274
self.num_vals = control.identifier_get_max_length();
276
self.ui.set_item_text(self.treeroot, str(val))
279
def control_get_light_cb(self, control, err, vals):
283
self.ui.set_item_text(self.treeroot, None)
285
self.num_vals = control.get_num_vals();
295
self.ui.set_item_text(self.treeroot, str(self.vals))
299
self.e.controls.pop(self.name)
300
self.ui.remove_control(self)
301
self.destroyed = True