~ubuntu-branches/ubuntu/vivid/openipmi/vivid

« back to all changes in this revision

Viewing changes to swig/python/openipmigui/_control.py

  • Committer: Bazaar Package Importer
  • Author(s): Noèl Köthe
  • Date: 2006-09-15 17:56:24 UTC
  • mfrom: (1.1.2 upstream) (2.1.1 etch)
  • Revision ID: james.westby@ubuntu.com-20060915175624-ljk0mg3xtcm65tvm
Tags: 2.0.7-1
* new upstream release from 2006-06-08
  Thanks to John Wright <john.wright hp.com> for initial work
  (closes: Bug#380149)
* updated Standards Version
* new binaries openipmicmd, openipmish, rmcp_ping

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# _control.py
 
2
#
 
3
# openipmi GUI handling for controls
 
4
#
 
5
# Author: MontaVista Software, Inc.
 
6
#         Corey Minyard <minyard@mvista.com>
 
7
#         source@mvista.com
 
8
#
 
9
# Copyright 2005 MontaVista Software Inc.
 
10
#
 
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.
 
15
#
 
16
#
 
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.
 
27
#
 
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.
 
31
#
 
32
 
 
33
import OpenIPMI
 
34
import gui_popup
 
35
import gui_setdialog
 
36
import gui_lightset
 
37
 
 
38
class ControlRefreshData:
 
39
    def __init__(self, c):
 
40
        self.c = c
 
41
        return
 
42
 
 
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)
 
48
        else:
 
49
            control.get_val(self.c)
 
50
            pass
 
51
        return
 
52
    
 
53
    pass
 
54
 
 
55
class ControlSet:
 
56
    def __init__(self, c):
 
57
        self.c = c;
 
58
        return
 
59
 
 
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 ] ])
 
65
        return
 
66
 
 
67
    def modval(self, event):
 
68
        vals = self.c.vals
 
69
        while (len(vals) < self.c.num_vals):
 
70
            vals.append(0)
 
71
            pass
 
72
        gui_setdialog.SetDialog("Set Control Values for " + self.c.name,
 
73
                                vals,
 
74
                                self.c.num_vals,
 
75
                                self)
 
76
        return
 
77
 
 
78
    def SetTo0(self, event):
 
79
        self.ival = [ 0 ]
 
80
        self.c.control_id.to_control(self)
 
81
        return
 
82
 
 
83
    def SetTo1(self, event):
 
84
        self.ival = [ 1 ]
 
85
        self.c.control_id.to_control(self)
 
86
        return
 
87
 
 
88
    def ok(self, vals):
 
89
        self.ival = [ ]
 
90
        for val in vals:
 
91
            self.ival.append(int(val))
 
92
            pass
 
93
        self.c.control_id.to_control(self)
 
94
        return
 
95
 
 
96
    def control_cb(self, control):
 
97
        if (self.c.control_type == OpenIPMI.CONTROL_IDENTIFIER):
 
98
            control.identifier_set_val(self.ival)
 
99
        else:
 
100
            control.set_val(self.ival)
 
101
            pass
 
102
        return
 
103
 
 
104
    def do_on_close(self):
 
105
        self.c = None
 
106
 
 
107
    pass
 
108
        
 
109
class LightSet:
 
110
    def __init__(self, c):
 
111
        self.c = c;
 
112
        return
 
113
 
 
114
    def HandleMenu(self, event):
 
115
        gui_popup.popup(self.c.ui, event, [ [ "Modify Value", self.modval ] ])
 
116
        return
 
117
 
 
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,
 
121
                              self);
 
122
        return
 
123
 
 
124
    def ok(self, val):
 
125
        self.ival = ';'.join(val)
 
126
        self.c.control_id.to_control(self)
 
127
        return
 
128
 
 
129
    def control_cb(self, control):
 
130
        rv = control.set_light(self.ival)
 
131
        if (rv != 0):
 
132
            raise ValueError("set_light failed: " + str(rv))
 
133
        return
 
134
        
 
135
class Control:
 
136
    def __init__(self, e, control):
 
137
        self.e = e
 
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()
 
142
        self.ui = e.ui;
 
143
        self.updater = ControlRefreshData(self)
 
144
        self.vals = [ ]
 
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();
 
150
        else:
 
151
            self.num_vals = control.get_num_vals();
 
152
            pass
 
153
 
 
154
        if ((self.control_type == OpenIPMI.CONTROL_LIGHT)
 
155
            and (control.light_set_with_setting())):
 
156
            self.setting_light = True
 
157
            self.lights = [ ]
 
158
            for  i in range (0, self.num_vals):
 
159
                lc = control.light_has_local_control(i)
 
160
                colors = [ ]
 
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))
 
164
                        pass
 
165
                    pass
 
166
                self.lights.append((lc, colors))
 
167
                pass
 
168
            pass
 
169
        else:
 
170
            self.setting_light = False
 
171
            pass
 
172
 
 
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)
 
178
            else:
 
179
                self.setter = ControlSet(self)
 
180
                pass
 
181
            pass
 
182
        else:
 
183
            self.setter = None
 
184
            pass
 
185
 
 
186
        self.ui.prepend_item(self, "Control Type", self.control_type_str)
 
187
        cs = [ ]
 
188
        if (control.has_events()):
 
189
            cs.append("generates_events")
 
190
            pass
 
191
        if (self.is_settable):
 
192
            cs.append("settable")
 
193
            pass
 
194
        if (self.is_readable):
 
195
            cs.append("readable")
 
196
            pass
 
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):
 
203
                    cap = [ ]
 
204
                    if control.light_has_local_control(i):
 
205
                        cap.append("local_control")
 
206
                        pass
 
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))
 
210
                            pass
 
211
                        pass
 
212
                    self.ui.append_item(self, "Light" + str(i), ' '.join(cap))
 
213
                    pass
 
214
                pass
 
215
            else:
 
216
                self.ui.append_item(self, "Light Type", "transition")
 
217
                for i in range(0, self.num_vals):
 
218
                    cap = [ ]
 
219
                    for j in range (0, control.get_num_light_values(i)):
 
220
                        cap2 = [ ]
 
221
                        for k in range (0,control.get_num_light_transitions(i, j)):
 
222
                            cap3 = [ ]
 
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))
 
227
                            cap2.append(cap3)
 
228
                            pass
 
229
                        cap.append(cap2)
 
230
                        pass
 
231
                    self.ui.append_item(self, "Light" + str(i), str(cap))
 
232
                    pass
 
233
                pass
 
234
            pass
 
235
        elif (self.control_type == OpenIPMI.CONTROL_IDENTIFIER):
 
236
            self.ui.append_item(self, "Max Length", str(self.num_vals))
 
237
        else:
 
238
            self.ui.append_item(self, "Num Vals", str(self.num_vals))
 
239
            pass
 
240
        return
 
241
    
 
242
    def __str__(self):
 
243
        return self.name
 
244
 
 
245
    def DoUpdate(self):
 
246
        if (self.is_readable):
 
247
            self.control_id.to_control(self.updater)
 
248
            pass
 
249
        return
 
250
 
 
251
    def HandleMenu(self, event):
 
252
        if (self.setter != None):
 
253
            self.setter.HandleMenu(event)
 
254
            pass
 
255
        return
 
256
        
 
257
    def control_get_val_cb(self, control, err, vals):
 
258
        if (self.destroyed):
 
259
            return
 
260
        if (err != 0):
 
261
            self.ui.set_item_text(self.treeroot, None)
 
262
            return
 
263
        self.num_vals = control.get_num_vals();
 
264
        self.vals = vals
 
265
        self.ui.set_item_text(self.treeroot, str(vals))
 
266
        return
 
267
        
 
268
    def control_get_id_cb(self, control, err, val):
 
269
        if (self.destroyed):
 
270
            return
 
271
        if (err != 0):
 
272
            self.ui.set_item_text(self.treeroot, None)
 
273
            return
 
274
        self.num_vals = control.identifier_get_max_length();
 
275
        self.val = val
 
276
        self.ui.set_item_text(self.treeroot, str(val))
 
277
        return
 
278
 
 
279
    def control_get_light_cb(self, control, err, vals):
 
280
        if (self.destroyed):
 
281
            return
 
282
        if (err != 0):
 
283
            self.ui.set_item_text(self.treeroot, None)
 
284
            return
 
285
        self.num_vals = control.get_num_vals();
 
286
        v1 = vals.split(":")
 
287
        self.vals = [ ]
 
288
        for s1 in v1:
 
289
            v1 = s1.split()
 
290
            if (v1[0] != "lc"):
 
291
                v1.insert(0, "")
 
292
                pass
 
293
            self.vals.append(v1)
 
294
            pass
 
295
        self.ui.set_item_text(self.treeroot, str(self.vals))
 
296
        return
 
297
 
 
298
    def remove(self):
 
299
        self.e.controls.pop(self.name)
 
300
        self.ui.remove_control(self)
 
301
        self.destroyed = True
 
302
        self.e = None
 
303
        self.updater = None
 
304
        self.ui = None
 
305
        return
 
306
 
 
307
    pass