wxPython控件学习之wx.grid.Grid (包括对GridCellEditor和GridCelRender的扩展,以支持更多的grid cell 样式, 以GridCellColorEditor为例)


wx.Grid 及其相关的类是用来显示和编辑类表格样式的数据。该控件为显示,编辑数据源提及交互供了丰富的特征。

wx.GridTableBase类控制要显示的实际数据。可以call CreateGrid()产生一个该类的实例对象。

wx.GridCellRenderer 基类,负责对单元格进行绘画。现在提供了默认的几种派生。

wx.GridCellEditor 基类,负责在cell editing状态下,显示对应的控件。现在提供了默认的几种派生。

如何添加、删除行,列和单元格?

本例中使用SetTable() 作为grid 的数据源。 那么重点来研究在这个情况下如何对grid 和 数据源进行增删改。

GridTableMessage 类,可以用来向表发送一些message,本例中 是对行的增删改操作, 那么我们只需要用其中的3个message:

GRIDTABLE_NOTIFY_ROWS_INSERTED 行插入的消息
GRIDTABLE_NOTIFY_ROWS_APPENDED
附近新行的消息
GRIDTABLE_NOTIFY_ROWS_DELETED 删除行的消息

GRIDTABLE_REQUEST_VIEW_GET_VALUES cell 值如果有更改的消息

1.在index插入一新行

grd.GridTableMessage(self,
grd.GRIDTABLE_NOTIFY_ROWS_INSERTED
,index
 改行所在的索引
,1 插入一行记录
)

2. 删除rowIndex行

grd.GridTableMessage(self,grd.GRIDTABLE_NOTIFY_ROWS_DELETED,
rowIndex,
 改行所在的索引
1 只删除一行

)

3. 附加一新行

grd.GridTableMessage(self,
grd.GRIDTABLE_NOTIFY_ROWS_APPENDED,
1
附近的新行个数
)


 1 #-*-coding:utf-8

 #-------------------------------------------------------------------------------
# Name: 模块1
# Purpose:
#
# Author: ankier
#
# Created: 14/10/2012
# Copyright: (c) ankier 2012
# Licence: <your licence>
#------------------------------------------------------------------------------- import wx, wx.grid as grd #定购的Grid cell ComboBox editor
class GridCellComboBoxEditor(grd.PyGridCellEditor):
def __init__(self, choices = []):
grd.PyGridCellEditor.__init__(self)
self.__Choices = choices def Create(self, parent, id, evtHandler):
"""
Called to create the control, which must derive from wx.Control.
*Must Override*
"""
self.__Parent = parent
self.__ComboBoxDialog = None
self.__ComboBoxButton = wx.ComboBox(parent, id, value = "", choices =self.__Choices)
self.__ComboBoxButton.SetEditable(False)
self.SetControl(self.__ComboBoxButton)
#添加新的event handler, 防止 弹出窗口后, cell 自动editor
newEventHandler = wx._core.EvtHandler()
if evtHandler:
self.__ComboBoxButton.PushEventHandler(newEventHandler)
self.__ComboBoxButton.Bind(wx.EVT_COMBOBOX, self.OnClick) def OnClick(self, event):
self.endValue = self.__ComboBoxButton.GetStringSelection() def SetSize(self, rect):
"""
Called to position/size the edit control within the cell rectangle.
If you don't fill the cell (the rect) then be sure to override
PaintBackground and do something meaningful there.
"""
self.__ComboBoxButton.SetDimensions(rect.x,rect.y,rect.width+2,rect.height+2,wx.SIZE_ALLOW_MINUS_ONE) def Clone(self):
"""
Create a new object which is the copy of this one
*Must Override*
"""
return GridCellComboBoxEditor() def BeginEdit(self, row, col, grid):
"""
Fetch the value from the table and prepare the edit control
to begin editing. Set the focus to the edit control.
*Must Override*
"""
self.startValue = grid.GetTable().GetValue(row, col)
self.endValue = self.startValue
self.__ComboBoxButton.SetStringSelection(self.startValue) def EndEdit(self, row, col, grid):
"""
Complete the editing of the current cell. Returns True if the value
has changed. If necessary, the control may be destroyed.
*Must Override*
"""
changed = False
if self.endValue != self.startValue:
changed = True
grid.GetTable().SetValue(row, col, self.endValue) # update the table
self.startValue = ''
return changed #定购颜色cell colour column
class GridCellComboBoxRender(grd.GridCellStringRenderer):
def __init__(self):
grd.GridCellStringRenderer.__init__(self) 转自http://www.cnblogs.com/ankier/archive/2012/10/14/2723364.html

wxPython控件学习之wx.grid.Grid 表格控件的更多相关文章

  1. Ext入门学习系列(五)表格控件(1)

    上节学习了Ext面板控件,为后面的各个控件学习奠定基础,在此基础上本章将学习网络开发最期待的功能——表格控件. 我们都知道网络编程语言中,除了.net其他的基本没有提供网格控件,而最近的asp.net ...

  2. Ext入门学习系列(五)表格控件(3)

    上节学习了Ext中如何绑定服务器端传递的数据.分别用asp.net和asp.net MVC.PHP.XML为例.本节主要介绍绑定之后的分页功能. 一.Ext的表格控件如何绑定? 分页是Ext自带的一个 ...

  3. Ext入门学习系列(五)表格控件(2)

    上节学习了Ext中表格控件,从创建,到定义数据源.绑定显示,大体明白了一个基本的表格控件是怎么实现的.而我们用表格控件多用于从各种数据源接收数据并显示出来,并不是写死的.本章我们就不同数据源的不同实现 ...

  4. 深入浅出ExtJS 第三章 表格控件

    3.1 表格的特性简介 >.Ext中的表格功能:包括排序/缓存/拖动/隐藏某一列/自动显示行号/列汇总/单元格编辑等实用功能; >.表格由类Ext.grid.GridPanel定义,继承自 ...

  5. Flutter 分页功能表格控件

    老孟导读:前2天有读者问到是否有带分页功能的表格控件,今天分页功能的表格控件详细解析来来. PaginatedDataTable PaginatedDataTable是一个带分页功能的DataTabl ...

  6. Silverlight 2学习笔记二:三个基本布局控件(Canvas、StackPanel、Grid )

    这篇文章主要是翻译了ScottGu博客的文章:Silverlight Tutorial Part 2: Using Layout Management.虽然是翻译,但通过笔记记录,我发现对这三个布局控 ...

  7. wxPython中基本控件学习

    wxPython工具包提供了多种不同的窗口部件,包括了本章所提到的基本控件.我们涉及静态文本.可编辑的文本.按钮.微调.滑块.复选框.单选按钮.选择器.列表框.组合框和标尺.对于每种窗口部件,我们将提 ...

  8. 向WPF的Grid里面增加控件

    在c#中,有时需要通过代码创建面板控件,但是对于面板的操作与之前的控件并不是很直观,因此记下方法,以供后来复习使用: 创建两行两列的表格: 第一种方法: Grid grid = new Grid(); ...

  9. ExtJS4.2学习(九)属性表格控件PropertyGrid(转)

    鸣谢网址:http://www.shuyangyang.com.cn/jishuliangongfang/qianduanjishu/2013-11-15/178.html ------------- ...

随机推荐

  1. word的样式设置

    一般自己写文档就用typora了,便捷美观,但是在工作上又不得不用word写文档,我对审美.格式比较有强迫症,有的小公司没有形成自己的文档规范,或者所谓的规范也只是写好了格式的文档,你往里面填内容就可 ...

  2. python-day15---面向对象

    面向对象零:面向对象的说明: 面向过程和面向对象: 面向对象:一切以对象为中心(解决的问题本身) 面向过程:一切以过程为中心(解决问题的步骤) 面向对象我们用 “ class 类名:” 来表示面向对象 ...

  3. A. Little C Loves 3 I Codeforces Round #511 (Div. 2) 【数学】

    题目: Little C loves number «3» very much. He loves all things about it. Now he has a positive integer ...

  4. SGU - 495 概率DP

    题意:n个带礼物的盒子和m个人,每个人拿一个盒子并放回,如果里面有礼物就拿走(盒子还是留下),问m个人带走礼物的期望 #include<iostream> #include<algo ...

  5. HDU - 4763 找出特殊规律的串

    在一个Text串中找出Pattern串E以满足EAEBE,A B可以是任意串 看一眼觉得woc好难,后来看一下样例AB为空也可以 找观察一下E既是前缀也是后缀,很容易联想到next 最优情况EEE,那 ...

  6. 页面加载时的div动画

    用@keyframes(动画),实现页面加载时的div动画(不要用js控制,因为当页面加载的时候,js还不一定可以使用) 可以在https://daneden.github.io/animate.cs ...

  7. sublim text3中的一些设置

    {    "dictionary": "Packages/Language - English/en_US.dic",    "font_face&q ...

  8. poj2393tmp

    #include"iostream" #include"stdio.h" #include"algorithm" using namespa ...

  9. Sqlite CodeFirst的初级实现

    示例实体: using System; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnn ...

  10. zabbix 另一种方式取 zabbix-sender

    一,zabbix-sender介绍 这种模式是两主机并没有agent互联 使用zabbix-serder的话适用那种没有固定公网IP的,实时系统数据监控操作 还一个实用为零延迟数据监控, 本省zabb ...