[英]Suppress wxPython GridTableBase refresh?
如果需要,如何使下面的代码段刷新?
例如,如果我按原样运行,则table.SetValue(0,0,'test')
行将立即更table.SetValue(0,0,'test')
格。 无论如何,有没有改变这种行为,以便我可以对GridTableBase进行任意数量的更改,然后请求刷新? 如果是这样,如何更改下面的代码以获得该功能?
import wx
import wx.grid
class TestTable(wx.grid.PyGridTableBase):
def __init__(self):
wx.grid.PyGridTableBase.__init__(self)
self.data = { (1,1) : "Here", (2,2) : "is", (3,3) : "some", (4,4) : "data"}
self.odd=wx.grid.GridCellAttr()
self.odd.SetBackgroundColour("sky blue")
self.odd.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD))
self.even=wx.grid.GridCellAttr()
self.even.SetBackgroundColour("sea green")
self.even.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD))
def GetNumberRows(self):
return 50
def GetNumberCols(self):
return 50
def IsEmptyCell(self, row, col):
return self.data.get((row, col)) is not None
def GetValue(self, row, col):
value = self.data.get((row, col))
if value is not None:
return value
else:
return ''
def SetValue(self, row, col, value):
self.data[(row,col)] = value
def GetAttr(self, row, col, kind):
attr = [self.even, self.odd][row % 2]
attr.IncRef()
return attr
class TestFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title="Grid Table", size=(640,480))
grid = wx.grid.Grid(self)
table = TestTable()
grid.SetTable(table, True)
table.SetValue(0,0,'test')
app = wx.PySimpleApp()
frame = TestFrame()
frame.Show()
app.MainLoop()
BeginBatch
EndBatch
的BeginBatch
和EndBatch
网格方法,但它们不能与自定义网格表一起使用。
您可以尝试将grid.SetTable
调用延迟到填充数据之后。 对于连续的批次,您可以克隆当前的网格表,对克隆进行必要的修改,然后将克隆设置为当前的网格表。
如果尝试这种方法,则可能要自己管理这些表格,因此不要像在示例中那样使表格获得它们的所有权( SetTable
调用中的True
参数)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.