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. Qt 学习之路 2(38):存储容器

    Qt 学习之路 2(38):存储容器 豆子 2013年1月14日 Qt 学习之路 2 38条评论 存储容器(containers)有时候也被称为集合(collections),是能够在内存中存储其它特 ...

  2. python学习之路---day03

    一:数据类型转换 1:bool-->int 将bool转成 int型 True 是1 False是0 a=True c=int(a) print(c) b=False d=int(b) prin ...

  3. Spring Eureka的使用入门

    Eureka调度服务: Gradle依赖包: 基础框架依赖配置核心代码: buildscript { repositories { mavenCentral() } dependencies {cla ...

  4. Oracle分析函数系列之first_value/last_value:在记录集中查找第一条记录和最后一条记录

    [转自] http://blog.csdn.net/rfb0204421/article/details/7675911 注意:与max,min的区别,虽然也可以实现,但只是针对数字字段. 1.初始化 ...

  5. vim的多窗口功能与环境参数设置

    Vim的多窗口功能 多窗口情况下按键功能 :sp [filename] 打开一个新的窗口,如果有加filename,表示在新窗口打开一个新文件,否则表示两个窗口为同一文件内容 :[ctrl]+w+j( ...

  6. linux中终端字体样式显示不正常

    问题:Centos终端中,字体显示不正常,中间感觉有空格,空格和单词傻傻分不清. 解决办法: yum groupinstall "Chinese Support" yum grou ...

  7. jumpserver 安装详解

    一,下载软件 下载前安装依赖软件 yum install -y epel-release                        yum -y install git python-pip my ...

  8. 【3dsMax安装失败,如何卸载、安装3dMax 2011?】

    AUTODESK系列软件着实令人头疼,安装失败之后不能完全卸载!!!(比如maya,cad,3dsmax等).有时手动删除注册表重装之后还是会出现各种问题,每个版本的C++Runtime和.NET f ...

  9. Unity3D 发布成PC端常用设置

    本文,基于Unity 5.6pro版本来发布PC端.文中若有不妥之处,欢迎各位指出! 一.如何去掉Unity官方水印? 首先,你需要pro版本的Unity3D.如果,你是personal版本的话,就需 ...

  10. 已知tomcat应用名称,如何查询该应用端口号

    假设应用名称叫pear,并假设路径为:/datong/tomcat-pear/ 方法一,根据PID查找应用端口号,前提是应用已经运行 1,找到改应用的PID:ps -ef | grep pear | ...