class DGLabel(Label):
def __init__(self,app,master,row,col,**kw):
apply(Label.__init__,(self,master),kw)
self.app = app
self.row = row
self.col = col
self.menu = Menu(self)
self.menu.add_command(label="Only this value", command=self.test)
self.menu.add_command(label="Do That", command=self.test)
self.bind("<Button-3>", self.popup)
def get_position(self):
if self.row and self.col:
return (self.row,self.col)
else:
return (-1,-1)
def get_text(self):
return self.cget("text")
def get_head(self):
return self.app.titles[self.col].cget("text")
def popup(self,event):
self.menu.post(event.x_root, event.y_root)
def test(self):
self.app.app.reload(self)
class DataGrid:
def
__init__(self,app,parent,heads=[],data=[],titlebg="#ff5566",cellbg1="#eeeeee",cellbg2="#aaaaaa"):
self.app = app
self.parent = parent
self.titlebg = titlebg
self.cellbg1 = cellbg1
self.cellbg2 = cellbg2
self.titles = []
self.cells = []
self.cellsframe = ScrolledFrame(self.parent)
self.cellsframe.grid(row=1,column=0,sticky=E+W)
i = 0
for head in heads:
self.titles.append(Label(self.cellsframe.inner,text=head[1],bg=self.titlebg,relief=GROOVE))
self.titles[i].grid(row=0,column=i,sticky=E+W)
i = i + 1
j = 0
for record in data:
self.cells.append([])
if j % 2 == 0:
cellbg = self.cellbg1
else:
cellbg = self.cellbg2
i = 0
for field in record:
self.cells[j].append(DGLabel(self,self.cellsframe.inner,row=j,col=i,text=field,bg=cellbg,relief=GROOVE))
self.cells[j][i].grid(row=j+1,column=i,sticky=E+W)
i = i + 1
j = j + 1