wxPython控件学习之wx.grid.Grid 表格控件
wxPython控件学习之wx.grid.Grid (包括对GridCellEditor和GridCelRender的扩展,以支持更多的grid cell 样式, 以GridCellColorEditor为例)
wx.Grid 及其相关的类是用来显示和编辑类表格样式的数据。该控件为显示,编辑数据源提及交互供了丰富的特征。
wx.GridTableBase类控制要显示的实际数据。可以call CreateGrid()产生一个该类的实例对象。
wx.GridCellRenderer 基类,负责对单元格进行绘画。现在提供了默认的几种派生。
- wxGridCellBoolRenderer 显示CheckBox样式
- wxGridCellFloatRenderer
- wxGridCellNumberRenderer
- wxGridCellStringRenderer
wx.GridCellEditor 基类,负责在cell editing状态下,显示对应的控件。现在提供了默认的几种派生。
- wxGridCellBoolEditor
- wxGridCellChoiceEditor
- wxGridCellFloatEditor
- wxGridCellNumberEditor
- wxGridCellTextEditor
如何添加、删除行,列和单元格?
本例中使用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 表格控件的更多相关文章
- Ext入门学习系列(五)表格控件(1)
上节学习了Ext面板控件,为后面的各个控件学习奠定基础,在此基础上本章将学习网络开发最期待的功能——表格控件. 我们都知道网络编程语言中,除了.net其他的基本没有提供网格控件,而最近的asp.net ...
- Ext入门学习系列(五)表格控件(3)
上节学习了Ext中如何绑定服务器端传递的数据.分别用asp.net和asp.net MVC.PHP.XML为例.本节主要介绍绑定之后的分页功能. 一.Ext的表格控件如何绑定? 分页是Ext自带的一个 ...
- Ext入门学习系列(五)表格控件(2)
上节学习了Ext中表格控件,从创建,到定义数据源.绑定显示,大体明白了一个基本的表格控件是怎么实现的.而我们用表格控件多用于从各种数据源接收数据并显示出来,并不是写死的.本章我们就不同数据源的不同实现 ...
- 深入浅出ExtJS 第三章 表格控件
3.1 表格的特性简介 >.Ext中的表格功能:包括排序/缓存/拖动/隐藏某一列/自动显示行号/列汇总/单元格编辑等实用功能; >.表格由类Ext.grid.GridPanel定义,继承自 ...
- Flutter 分页功能表格控件
老孟导读:前2天有读者问到是否有带分页功能的表格控件,今天分页功能的表格控件详细解析来来. PaginatedDataTable PaginatedDataTable是一个带分页功能的DataTabl ...
- Silverlight 2学习笔记二:三个基本布局控件(Canvas、StackPanel、Grid )
这篇文章主要是翻译了ScottGu博客的文章:Silverlight Tutorial Part 2: Using Layout Management.虽然是翻译,但通过笔记记录,我发现对这三个布局控 ...
- wxPython中基本控件学习
wxPython工具包提供了多种不同的窗口部件,包括了本章所提到的基本控件.我们涉及静态文本.可编辑的文本.按钮.微调.滑块.复选框.单选按钮.选择器.列表框.组合框和标尺.对于每种窗口部件,我们将提 ...
- 向WPF的Grid里面增加控件
在c#中,有时需要通过代码创建面板控件,但是对于面板的操作与之前的控件并不是很直观,因此记下方法,以供后来复习使用: 创建两行两列的表格: 第一种方法: Grid grid = new Grid(); ...
- ExtJS4.2学习(九)属性表格控件PropertyGrid(转)
鸣谢网址:http://www.shuyangyang.com.cn/jishuliangongfang/qianduanjishu/2013-11-15/178.html ------------- ...
随机推荐
- Domoticz 接入苹果的 HomeKit 实现 Siri 控制
前言 接上次的折腾,这次尝试将 Domoticz 接入到苹果的 HomeKit,也就是在 iPhone 的 Siri 中可以语音控制.参考官方文档 步骤 安装 nodejs curl -sL http ...
- 【算法笔记】B1036 跟奥巴马一起编程
1036 跟奥巴马一起编程 (15 分) 美国总统奥巴马不仅呼吁所有人都学习编程,甚至以身作则编写代码,成为美国历史上首位编写计算机代码的总统.2014 年底,为庆祝“计算机科学教育周”正式启动,奥巴 ...
- POJ_3414 Pots 【复杂BFS】
一.题面 You are given two pots, having the volume of A and B liters respectively. The following operati ...
- Echarts图表横坐标显示不全
xAxis: { "axisLabel":{ //加上这个强制显示 interval: 0 }, type: 'category', data: self[theDataKey]. ...
- java的长字符串转化为短字符串
public class CustomEncrypt{ public static void main( String[] args ) { /* * c#给的正确测试用例: id=>mid * ...
- java 并发完成任务之CountDownLatch
1.CountDownLatch是一个同步辅助类,犹如倒计时计数器,创建对象时通过构造方法设置初始值,调用CountDownLatch对象的await()方法则处于等待状态,调用countDown() ...
- [转] 前后端分离之JWT用户认证
[From] http://www.jianshu.com/p/180a870a308a 在前后端分离开发时为什么需要用户认证呢?原因是由于HTTP协定是不储存状态的(stateless),这意味着当 ...
- DVWA1.9平台XSS小结
LOW级别就不写了...... 直接上中高级别(结合源码更好理解) 1.XSS Reflected(Medium) 从源码中可以清楚的看到,输入的<script>标签被过滤掉了,看清了,只 ...
- Python基础 (上)
参考:菜鸟教程 Python用途 目录 一.数据类型 二.运算符 三.条件和循环控制语句 四.函数 五.模块 六.输入与输出 一.数据类型 string.list和tuple都属于sequenc ...
- Java中使用nextLine(); 没有输入就自动跳过的问题
转自:https://www.cnblogs.com/1020182600HENG/p/6564795.html [问题分析] 必要的知识:in.nextLine();不能放在in.nextInt() ...