wxPython控件学习之UltimateListCtrl空间中使用ComboBox时,该控件一直在重绘的问题
例子:
#-*- coding: UTF-8 -*- #------------------------------------------------------------------------------- # Name: 模块mainFrame # Purpose: 应用程序的主界面 # # Author: ankier # # Created: 16-12-2012 # Copyright: (c) ankier 2012 # Licence: <your licence> #------------------------------------------------------------------------------- try: from agw import floatspin as FS except ImportError: # if it's not there locally, try the wxPython lib. import wx.lib.agw.floatspin as FS try: from agw import ultimatelistctrl as ULC except ImportError: # if it's not there locally, try the wxPython lib. from wx.lib.agw import ultimatelistctrl as ULC import wx import sys ## @detail MainFrame主界面窗口类 class MainFrame(wx.Frame): def __init__(self): #重新定向wxpython的输出输入和错误输出到系统标准输入输出 sys.stdin = sys.__stdin__ sys.stdout = sys.__stdout__ sys.stderr = sys.__stderr__ wx.Frame.__init__(self, None, wx.ID_ANY, 'Ultimate list ctrl demo', pos=wx.DefaultPosition, size=(800, 600), style=wx.DEFAULT_FRAME_STYLE) self.CreateStatusBar() panel = wx.Panel(self, -1) box = wx.FlexGridSizer(10, 2, 5, 5) button = wx.Button(panel, -1, 'Add') box.Add(button, 0, wx.ALIGN_CENTRE) button.Bind(wx.EVT_BUTTON, self.__OnAddClicked) self.listCtrls = ULC.UltimateListCtrl(panel, -1, size =(200, 100), style = ULC.ULC_MASK_TYPE, agwStyle = ULC.ULC_REPORT|ULC.ULC_HAS_VARIABLE_ROW_HEIGHT|ULC.ULC_NO_FULL_ROW_SELECT) self.listCtrls.InsertColumn(0, 'Name', ULC.ULC_FORMAT_CENTRE) self.listCtrls.InsertColumn(1, 'Selection', ULC.ULC_FORMAT_CENTRE) box.Add(self.listCtrls, 0, wx.ALIGN_CENTRE) panel.SetSizerAndFit(box) def __OnAddClicked(self, event): index = self.listCtrls.InsertStringItem(sys.maxint, 'name 1') panel = wx.Panel(self.listCtrls, -1) sizer = wx.BoxSizer(wx.VERTICAL) cbb = wx.ComboBox(panel, -1, value = '1', choices = ['1', '2', '3', '4', '5'], style = wx.CB_DROPDOWN|wx.TE_PROCESS_ENTER) sizer.Add(cbb, 1, wx.EXPAND) panel.SetSizer(sizer) #cbb = wx.Button(self.listCtrls, -1, 'Add') cbb.Bind(wx.EVT_PAINT, self.__OnPaint) self.listCtrls.SetItemWindow(index, 1, panel, expand = True) self.listCtrls.Update() def __OnPaint(self, event): event.Skip()
解决方法如代码中,SetItemWindow(),添加control到列中的时候,可以先用wx.Panel做位其父控件。这样control不会被一直重绘。我在项目中用到ComboBox时候,遇到了这个情况。其他控件暂时没有遇到过。wxPython 还是有许多问题的。