Hi all,
I currently have a grid and custom PyGridTableBase that I am using as
a log file monitor. Information is periodically read from several
files, parsed and then the TableBase is notified it has new data to
add via the pubsub module. The TableBase adds the new data then fires
off a message that rows have been added and the table needs to redraw.
Is there a method I can overide or event I can catch so that when the
table redraws, it additionally calls another method? I would like to
automatically apply a set of attributes to specific rows on the
redraw. In theory I could do it with pubsub again but I feel it would
get a bit messy between Grid Events and pubsub.
class ChatGridData(wx.grid.PyGridTableBase):
def __init__(self, parent):
self.parent = parent
self.lines = []
pubsub.Publisher().subscribe(self.updateDataModel,
"LINE_ADDED")
gridlib.PyGridTableBase.__init__(self)
def updateDataModel(self,message):
self.lines.append(message.data)
msg = gridlib.GridTableMessage(self,
gridlib.GRIDTABLE_NOTIFY_ROWS_APPENDED,1)
self.GetView().ProcessTableMessage(msg)
--- Additional methods omitted ---
class ChatGridTable(gridlib.Grid):
def __init__(self,parent):
self.name_highlights = []
gridlib.Grid.__init__(self, parent, -1)
self.tableBase = ChatGridData(self)
self.SetTable(self.tableBase, True)
self.SetMargins(0,0)
self.AutoSizeColumns(True)
self.SetColSize(0, 28)
self.SetColSize(1, 62)
self.SetColSize(2, 52)
self.SetColSize(3, 120)
self.SetColSize(4, 600)
self.SetRowLabelSize(0)
self.SetColLabelSize(0)
pubsub.Publisher().subscribe(self.addHighlight, "HIGHLIGHT")
def addHighlight(self,message):
self.name_highlights.append(message.data)
self.performHighlighting()
def performHighlighting(self):
search = self.tableBase.GetNumberRows()
for i in range(0,search):
cell_name = self.tableBase.GetValue(i,3)
if cell_name in self.name_highlights:
attr = gridlib.GridCellAttr()
attr.SetBackgroundColour(wx.CYAN)
self.SetRowAttr(i, attr)
Would prefer that performHighlighting is fired on every redraw,
otherwise it only triggers when a new highlight is added.