wxPython中如何让继承使用了PyGridTableBase的grid切换数据

小记以前一个QQ农场偷菜软件

我的展示农作物的表格有点复杂,

数据类继承Grid.PyGridTableBase,
显示类继承Grid.PyGridCellRenderer

问题是当我在运行时要切换表格中的数据时,表格并不随之动态更新。这个问题困扰了我很久,曾经逼得我建了3个表格,切换数据时隐藏另外两个。可这个解决方案实在不漂亮。一次次Google加一次偶然的灵机一动,I hack it !!!


此过程需要以下三步的配合,我写成一个方法:

 

  1. def SwitchData(self, rows)  
  2.     #1.删除原来所有的数据  
  3.     self.DeleteRows(0, self.GetNumberRows())  
  4.     _msg = Grid.GridTableMessage(self.GetTable(),  
  5.                                 Grid.GRIDTABLE_NOTIFY_ROWS_DELETED,  
  6.                                 0,                          #index of the first row  
  7.                                 self.GetNumberRows()        #the number of rows to be removed  
  8.                                 )  
  9.     self.ProcessTableMessage(_msg)  
  10.     #2.添加新的数据  
  11.     self.GetTable().AppendRows(rows)   #数据类中的一个增加行的函数,自定义  
  12.     _msg = Grid.GridTableMessage(self.GetTable(),   
  13.                      Grid.GRIDTABLE_NOTIFY_ROWS_APPENDED, # what we did to it  
  14.                      self.GetTable().GetNumberRows()      # how many  
  15.                      )  
  16.     self.ProcessTableMessage(_msg)  
  17.     #3.强制更新表格视图  
  18.     self.AutoSizeColumns()  
  19.     self.AutoSizeRows()  

 

posted @ 2017-02-12 17:43  ZRHW菜鸟  阅读(1772)  评论(1编辑  收藏  举报