Форум сайта python.su
Всем привет. есть такой код:
# -*- coding: cp1251 -*-
import wx
from wx.lib.mixins import listctrl
import locale
locale.setlocale(locale.LC_ALL,'Russian_Russia.1251')
import wx.lib.customtreectrl, wx.gizmos
from wx.lib.mixins import treemixin
from random import randint
class VirtualTreeListCtrl(treemixin.VirtualTree, wx.gizmos.TreeListCtrl,listctrl.ListCtrlAutoWidthMixin):
''' View:Виртуальное дерево
'''
def __init__(self, *args, **kwargs):
''' Виртуальное дерево
'''
self.model = kwargs.pop('treemodel')
kwargs['style'] = wx.TR_DEFAULT_STYLE | wx.TR_FULL_ROW_HIGHLIGHT | wx.TR_ROW_LINES | wx.TR_COLUMN_LINES
super(VirtualTreeListCtrl, self).__init__(*args, **kwargs)
listctrl.ListCtrlAutoWidthMixin.__init__(self)
size = (16, 16)
self.imageList = wx.ImageList(*size)
self.red16 = self.imageList.Add(wx.Bitmap('red16.gif', wx.BITMAP_TYPE_GIF))
self.silver16 = self.imageList.Add(wx.Bitmap('silver16.gif', wx.BITMAP_TYPE_GIF))
self.green16 = self.imageList.Add(wx.Bitmap('green16.gif' ,wx.BITMAP_TYPE_GIF))
self.ivory16 = self.imageList.Add(wx.Bitmap('ivory16.gif' ,wx.BITMAP_TYPE_GIF))
self.AssignImageList(self.imageList)
columns = ['0','1','2','3','4','5','6']
for item in columns:
self.AddColumn(item[0])
def UpdateAllData(self):
''' обновить данные в модели.
'''
self.model.UpdateAllData()
self.RefreshItems()
def OnGetChildrenCount(self,indices):
return self.model.GetChildrenCount(indices)
def OnGetItemBackgroundColour(self,indices):
if indices[0] % 2 == 0:
return wx.Colour(207,229,255)
if indices[0] % 2 == 1:
return wx.Colour(217,255,237)
def OnGetItemText(self, indices, column=0):
return '%s' % (self.model.GetText(indices,column))
def OnGetItemImage(self, indices, which, column=0):
''' вернуть имидж в колонке
'''
return -1
class TreeModel(object):
''' Model:Модель обеспечивающая данные для виртуального дерева
'''
def __init__(self, *args, **kwargs):
self._DoSort()
super(TreeModel, self).__init__(*args, **kwargs)
self.k = 0
def UpdateAllData(self):
self._DoSort()
def GetItem(self, indices):
return self.jobs[indices[0]][0]
def _DoSort(self):
self.orig_items = []
count = 1000
for i in xrange(count):
a = [i,]
for i in xrange(6):
a.append(randint(0, 1000))
self.orig_items.append(a)
self.jobs = self.orig_items
def GetText(self, indices,column):
""" Запрос отображения строки, колонки
"""
return self.jobs[indices[0]][column]
def GetChildren(self, indices):
return "GetChildren"
def GetChildrenCount(self, indices):
try:
self.jobs
except:
return 0
if indices == ():
return len(self.jobs)
else:
return 0
class Job2Panel(wx.Panel):
def __init__(self, parent):
super(Job2Panel, self).__init__(parent)
self.treemodel = TreeModel()
sizer = wx.BoxSizer()
self.tree = VirtualTreeListCtrl(self,treemodel=self.treemodel)
sizer.Add(self.tree, proportion=1, flag=wx.EXPAND)
self.SetSizer(sizer)
# #зарядка дерева
self.tree.RefreshItems()
self.tree.SetFocus()
def UpdateAllData(self):
self.tree.UpdateAllData()
class App(wx.App):
def __init__(self):
wx.App.__init__(self, True, 'log.txt')
frame = wx.Frame(None, size=(800, 500))
frame.panel = Job2Panel(frame)
self.SetTopWindow(frame)
frame.Show()
if __name__ == "__main__":
app = App()
app.MainLoop()
Отредактировано (Окт. 8, 2008 11:00:21)
Офлайн