编写环境:
1、ActivePython-2.7.2.5-win32-x86
2、wxPython2.8-win32-unicode-2.8.12.1-py27
3、wxFormBuilder_v3.3.3-beta
以下代码是演示如何在wxGrid中增加wxDataPickerCtrl控件的代码,是我查了好久才找到的。
import wx
import wx.grid
class DatePickerCellEditor(wx.grid.PyGridCellEditor):
def __init__(self):
wx.grid.PyGridCellEditor.__init__(self)
def Create(self, parent, id, evtHandler):
"""
Called to create the control, which must derive from wx.Control.
*Must Override*
"""
self._tc = wx.DatePickerCtrl(parent, id, size=(120,-1), style=wx.DP_DROPDOWN | wx.DP_SHOWCENTURY)
self.SetControl(self._tc)
if evtHandler:
self._tc.PushEventHandler(evtHandler)
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._tc.SetDimensions(rect.x, rect.y, rect.width+2, rect.height+2, wx.SIZE_ALLOW_MINUS_ONE)
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*
"""
s = grid.GetTable().GetValue(row, col)
d = wx.DateTime.Now()
try:
d.SetDay(int(s[:2]))
d.SetMonth(int(s[2:4])-1)
d.SetYear(int(s[4:8]))
self._tc.SetValue(d)
except:
pass
self.startValue = s
print self.startValue
#print 'self.startValue', self.startValue, type(self.startValue)
self._tc.SetValue(d)
#self._tc.SetInsertionPointEnd()
self._tc.SetFocus()
#self._tc.SetSelection(0, self._tc.GetLastPosition())
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
#val = str(self._tc.GetValue())
d = self._tc.GetValue()
print 'd', d
month = d.GetMonth()
month = month+1
month = str(month)
if len(month)<2:
month = '0'+month
#val = str(d.GetDay()) + '-'+month + '-'+str(d.GetYear())
val = str(d.GetYear()) + '-' + month + '-' + str(d.GetDay())
print 'val, self.startValue',val, self.startValue
if val != self.startValue:
changed = True
grid.GetTable().SetValue(row, col, val) # update the table
self.startValue = ''
#self._tc.SetValue('')
return changed
def Reset(self):
"""
Reset the value in the control back to its starting value.
*Must Override*
"""
self._tc.SetValue(self.startValue)
#self._tc.SetInsertionPointEnd()
def Clone(self):
"""
Create a new object which is the copy of this one
*Must Override*
"""
return DatePickerCellEditor()
class TestFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title="Grid Editor",
size=(640,480))
grid = wx.grid.Grid(self)
grid.CreateGrid(50,50)
grid.SetDefaultEditor(DatePickerCellEditor())
app = wx.PySimpleApp()
frame = TestFrame()
frame.Show()
app.MainLoop()
分享到:
相关推荐
讲述如何在eclipse的Visual Editor中增加自定义控件到面板上以便可以在编程时拖到窗口中。 语言:英语
项目需要,从mysql里查询数据,批量写入memcached里, 主要介绍VirtualTrees控件的使用,排序,增加日期控件,批量增加数据 等。 给VirtualTrees控件使用者以做demo
vba 中引入mscomm控件 vba 中引入mscomm控件 vba 中引入mscomm控件
海康威视OCX控件,首先在Windows系统中用Regsvr32命令注册该控件,然后可以在Wincc平台下,在ActiveX中添加该控件即可使用.
动态增加控件 Web控件 Winform控件 动态增加
在 .net C#,在panel上动态增加控件示例子,简单,一看就会.
可以在labview中动态的添加控件。其中的send.vi为发送程序,可以在运行时在receive.vi中添加一个字符串控件。
如何最简单在C#中,richTextBox,控件,中放入图片 如何最简单在C#中,richTextBox,控件,中放入图片 如何最简单在C#中,richTextBox,控件,中放入图片 如何最简单在C#中,richTextBox,控件,中放入图片 如何最...
VC列表list上增加edit控件和combo控件实现。博客地址:http://blog.csdn.net/bingdianlanxin,有问题欢迎留言!
上传的是一个库存盘点表自定义控件,它是在在ObjectListView中嵌入了一个下拉框控件和按钮控件,并通过按钮打开选择窗体,源代码中有详细说明嵌入原理,以此可以在ObjectListView 嵌入任何控件,同时还说明了...
增加word 控件的源码,实现增加印章验证、编辑文档、手工签名、插入模板、文字套红等操作的实例
将opencv中的Mat格式的图片显示在mfc中的picture控件上,该程序已经被放在了一个函数中间,只需调用该函数ShowMatImgToWnd(CWnd* pWnd, cv::Mat img)就可以将所需的图片显示在picture控件上了,其中CWnd* pWnd参数中...
在MFC中利用Tab控件实现了选项卡的功能呢给,同时在子对话框中利用图像控件显示图像,图像大小根据控件大小进行缩放!
pyqt5 实现 主窗口中动态添加控件 自己使用的笨方法,但是效果一样
wps中excel日期控件下载
在窗体上双击任意位置创建文本框控件,并要求文本框中显示序号,在窗体上右键单击,在鼠标点击位置创建ComboBox,并要求为每个ComboBox自动添加选项
C#的ListView添加各种自定义控件,CheckBox,ComboBox等
datagridview单元格增加日期控件.rar
压缩包中包含源码,主要功能是:在搜索框中输入你想遍历的窗体标题所包含的字符,然后点击搜索,MEMO框中就能显示出这个窗体中所有的控件
当QTwidget的控件不满足开发者的需求的时候,如何在QT中快捷的添加自定义控件