1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
|
# gui_list.py
#
# openipmi GUI handling for a list
#
# Author: MontaVista Software, Inc.
# Corey Minyard <minyard@mvista.com>
# source@mvista.com
#
# Copyright 2006 MontaVista Software Inc.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public License
# as published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
#
#
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the Free
# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
try:
import Tix
except:
import tkinter
from tkinter import tix as Tix
from openipmigui import gui_errstr
from openipmigui import gui_winsys
# A list widget that can be embedded in something else
class SubList(Tix.ScrolledHList):
def __init__(self, parent, columns, options, width, height):
Tix.ScrolledHList.__init__(self, parent,
options=options, width=width, height=height)
i = 0
for c in columns:
self.hlist.header_create(i, text=c[0])
self.hlist.column_width(i, c[1])
i += 1
pass
self.list_hash = { }
self.currkey = 0
self.hlist.bind("<Button-3>", self.ListMenu)
self.bind("<Destroy>", self.OnDestroy)
self.hlist.bind("<MouseWheel>", self.Wheel)
if (gui_winsys.winsys == "x11"):
self.hlist.bind("<Button-4>", self.ButtonUp)
self.hlist.bind("<Button-5>", self.ButtonDown)
pass
return
def Wheel(self, event):
self.hlist.yview("scroll", -(event.delta / 20), "units")
return
def ButtonUp(self, event):
event.delta = 120
self.Wheel(event);
return
def ButtonDown(self, event):
event.delta = -120
self.Wheel(event);
return
def OnDestroy(self, event):
self.list_hash = None
return
def ListMenu(self, event):
w = event.widget
key = w.nearest(event.y)
data = self.list_hash[key]
if (data and hasattr(data, "HandleMenu")):
data.HandleMenu(event, key, event)
pass
return
def DelItem(self, key):
self.hlist.delete_entry(key)
del self.list_hash[key]
return
def Append(self, name, values, data=None):
key = str(self.currkey)
self.currkey += 1
self.hlist.add(key, text=name)
self.list_hash[key] = data
i = 1
for v in values:
if (v != None):
self.hlist.item_create(key, i, text=str(v))
i += 1
pass
return key
def SetColumn(self, idx, colnum, value):
self.hlist.item_configure(idx, colnum, text=value)
return
def SetColumnStyle(self, node, colnum, style):
self.hlist.item_configure(node, colnum, style=style)
return
def add_data(self, name, values, data=None):
idx = self.Append(name, values, data);
if (data != None):
data.SetItem(idx)
pass
return idx
def DeleteAllItems(self):
self.hlist.delete_all()
self.list_hash = { }
self.currkey = 0
return
pass
# A top-level list
class List(Tix.Toplevel):
def __init__(self, name, columns):
Tix.Toplevel.__init__(self)
self.title(name)
slist = SubList(self,
columns,
options=("hlist.header 1"
+ " hlist.itemtype text"
+ (" hlist.columns "
+ str(len(columns)))
+ " hlist.selectForeground black"
+ " hlist.selectBackground beige"),
width=600, height=500)
slist.pack(side=Tix.TOP, fill=Tix.BOTH, expand=1)
self.slist = slist
self.errstr = gui_errstr.ErrStr(self)
self.errstr.pack(side=Tix.TOP, fill=Tix.BOTH, expand=1)
bbox = Tix.ButtonBox(self)
if hasattr(self, "ok"):
bbox.add("ok", text="Ok", command=self.ok)
pass
if hasattr(self, "save"):
bbox.add("save", text="Save", command=self.save)
pass
if hasattr(self, "cancel"):
bbox.add("cancel", text="Cancel", command=self.cancel)
pass
if hasattr(self, "clear"):
bbox.add("clear", text="Clear", command=self.clear)
pass
bbox.pack(side=Tix.TOP, fill=Tix.BOTH, expand=1)
self.bind("<Destroy>", self.OnDestroy)
return
def AfterDone(self):
return
def Close(self):
self.destroy()
return
def OnDestroy(self, event):
if (hasattr(self, "do_on_close")):
self.do_on_close()
pass
return
def DelItem(self, key):
self.slist.DelItem(key)
return
def Append(self, name, values, data=None):
return self.slist.Append(name, values, data)
def SetColumn(self, idx, colnum, value):
self.slist.SetColumn(idx, colnum, value)
return
def add_data(self, name, values, data=None):
return self.slist.add_data(name, values, data)
def DeleteAllItems(self):
return self.slist.DeleteAllItems()
return
def SetError(self, str):
self.errstr.SetError(str)
return
# Pass the rest of the functions on to the base list.
def DelItem(self, key):
self.slist.DelItem(key)
return
def Append(self, name, values, data=None):
return self.slist.Append(name, values, data)
def SetColumn(self, idx, colnum, value):
self.slist.SetColumn(idx, colnum, value)
return
def add_data(self, name, values, data=None):
return self.slist.add_data(name, values, data)
def DeleteAllItems(self):
return self.slist.DeleteAllItems()
return
pass
|