13.07.2015 Views

The wxPython tutorial

The wxPython tutorial

The wxPython tutorial

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Application skeletons in <strong>wxPython</strong>http://www.zetcode.com/wxpython/skeletons/#!/usr/bin/pythonimport wximport osimport timeID_BUTTON=100ID_EXIT=200ID_SPLITTER=300class MyListCtrl(wx.ListCtrl):def __init__(self, parent, id):wx.ListCtrl.__init__(self, parent, id, style=wx.LC_REPORT)files = os.listdir('.')images = ['images/empty.png', 'images/folder.png', 'images/source_py.png','images/image.png', 'images/pdf.png', 'images/up16.png']self.InsertColumn(0, 'Name')self.InsertColumn(1, 'Ext')self.InsertColumn(2, 'Size', wx.LIST_FORMAT_RIGHT)self.InsertColumn(3, 'Modified')self.SetColumnWidth(0, 220)self.SetColumnWidth(1, 70)self.SetColumnWidth(2, 100)self.SetColumnWidth(3, 420)self.il = wx.ImageList(16, 16)for i in images:self.il.Add(wx.Bitmap(i))self.SetImageList(self.il, wx.IMAGE_LIST_SMALL)j = 1self.InsertStringItem(0, '..')self.SetItemImage(0, 5)for i in files:(name, ext) = os.path.splitext(i)ex = ext[1:]size = os.path.getsize(i)sec = os.path.getmtime(i)self.InsertStringItem(j, name)self.SetStringItem(j, 1, ex)self.SetStringItem(j, 2, str(size) + ' B')self.SetStringItem(j, 3, time.strftime('%Y-%m-%d %H:%M',time.localtime(sec)))if os.path.isdir(i):self.SetItemImage(j, 1)elif ex == 'py':self.SetItemImage(j, 2)elif ex == 'jpg':self.SetItemImage(j, 3)elif ex == 'pdf':self.SetItemImage(j, 4)else:self.SetItemImage(j, 0)if (j % 2) == 0:self.SetItemBackgroundColour(j, '#e6f1f5')2 de 11 27/04/2008 1:07

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!