Python 表格的MVC 模式

#-*- coding:utf8 -*-
import wx
import wx.grid

class GeneralTable(wx.grid.PyGridTableBase):
    def __init__(self,data,rowLabels=None, colLabels=None):
        wx.grid.PyGridTableBase.__init__(self)
        self.data = data
        self.rowLabels = rowLabels
        self.colLabels =colLabels
    def GetNumberRows(self):
        return len(self.data)
    def GetNumberCols(self):
        return len(self.data[0])
    def GetColLabelValue(self,col):
        if self.colLabels:
            return self.colLabels[col]
    def GetRowLabelValue(self,row):
        if self.rowLabels:
            return self.rowLabels[row]
    def IsEmptyCell(self,row,col):
        return False
    def GetValue(self,row,col):
        return self.data[row][col]
    def SetValue(self,row,col,value):
        pass


# -*- coding:utf8 -*-
__author = 'shencheng'
import wx.grid
import wx
import generaltable

data = ((u"张三" , u"李四" , u"王五" , u"赵六") ,
        (u"张三" , u"李四" , u"王五" , u"赵六") ,
        (u"张三" , u"李四" , u"王五" , u"赵六") ,
        (u"张三" , u"李四" , u"王五" , u"赵六") ,
        (u"张三" , u"李四" , u"王五" , u"赵六") ,
        (u"张三" , u"李四" , u"王五" , u"赵六") ,
        (u"张三" , u"李四" , u"王五" , u"赵六") ,
        (u"张三" , u"李四" , u"王五" , u"赵六") ,
        (u"张三" , u"李四" , u"王五" , u"赵六") ,)

rowLabels = ("Last " , "First" , "Second" , "Third")
colLabels = ("CF" , "2B" , "LF" , "1B" , "RF" , "3B" , "C" , "SS" , "P")


class MyGrid ( wx.grid.Grid ):
    def __init__(self , parent):
        wx.grid.Grid.__init__ ( self , parent )
        tableBase = generaltable.GeneralTable ( data , colLabels , rowLabels )
        self.SetTable ( tableBase )


class MyFrame ( wx.Frame ):
    def __init__(self , parent):
        wx.Frame.__init__ ( self , parent , -1 , "A Grid" ,
                            size=(300 , 300) )
        grid = MyGrid ( self )


if __name__ == '__main__':
    app = wx.PySimpleApp ( )
    frame = MyFrame ( None )
    frame.Show ( )
    app.MainLoop ( )

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值