By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,588 Members | 1,086 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,588 IT Pros & Developers. It's quick & easy.

Icons in wxTreeCtrl using py2exe

P: 1
I have implemented the following simple python script by means of the BOA Constructor 0.6.1:

Expand|Select|Wrap|Line Numbers
  1. #Boa:Frame:Frame1
  2.  
  3. import wx
  4.  
  5. def create(parent):
  6.     return Frame1(parent)
  7.  
  8. [wxID_FRAME1, wxID_FRAME1TREECTRL1, 
  9. ] = [wx.NewId() for _init_ctrls in range(2)]
  10.  
  11. [wxID_FRAME1TOOLBAR1TOOLS0] = [wx.NewId() for _init_coll_toolBar1_Tools in range(1)]
  12.  
  13.  
  14. class Frame1(wx.Frame):
  15.     def _init_coll_imageList1_Images(self, parent):
  16.         # generated method, don't edit
  17.  
  18.         parent.Add(bitmap=wx.Bitmap(u'D:/tmp/IconExe/treeCtrl/Icon.bmp',
  19.               wx.BITMAP_TYPE_BMP), mask=wx.NullBitmap)
  20.  
  21.     def _init_utils(self):
  22.         # generated method, don't edit
  23.         self.imageList1 = wx.ImageList(height=16, width=16)
  24.         self._init_coll_imageList1_Images(self.imageList1)
  25.  
  26.     def _init_ctrls(self, prnt):
  27.         # generated method, don't edit
  28.         wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
  29.               pos=wx.Point(642, 398), size=wx.Size(400, 250),
  30.               style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
  31.         self._init_utils()
  32.         self.SetClientSize(wx.Size(392, 216))
  33.  
  34.         self.treeCtrl1 = wx.TreeCtrl(id=wxID_FRAME1TREECTRL1, name='treeCtrl1',
  35.               parent=self, pos=wx.Point(0, 0), size=wx.Size(392, 216),
  36.               style=wx.TR_HAS_BUTTONS)
  37.  
  38.     def __init__(self, parent):
  39.         self._init_ctrls(parent)
  40.  
  41.         self.treeCtrl1.SetImageList(self.imageList1)
  42.  
  43.         self.root = self.treeCtrl1.AddRoot("The Root Item")
  44.         self.treeCtrl1.SetPyData(self.root, None)
  45.         self.treeCtrl1.SetItemImage(self.root, 0, wx.TreeItemIcon_Normal)
  46.         self.treeCtrl1.SetItemImage(self.root, 0, wx.TreeItemIcon_Expanded)
  47.  
  48.  
  49. if __name__ == '__main__':
  50.     app = wx.App()
  51.     frame = create(None)
  52.     frame.Show()
  53.  
  54.     app.MainLoop()

This script creates a root item in a wxTreeCtrl with an Icon. If I start the script then it is working.
I am using:
- Windows XP
- python 2.7
- wxpython 2.9.4
- py2exe 0.6.9

If I generate an exe file from my python script by means of py2exe (without any error) then I cannot see the Icon before the root item.

I used the following setup.py python script:

from distutils.core import setup
import py2exe

Expand|Select|Wrap|Line Numbers
  1. setup(
  2.         options = {"py2exe": {"compressed": 1,
  3.                               "optimize": 2,
  4.                               "ascii": 1,
  5.                               "bundle_files": 1,
  6.  
  7.                              },
  8.                   },
  9.         zipfile = None,
  10.         windows = [
  11.             {
  12.                 "script": "./../Frame1.py",
  13.             }
  14.         ],
  15.      )
If I use python 2.5 with wxpython 2.8 for the same thing then the exe is working as well and I can see the Icon before the root item.

What shall I do to be able to see the icon before the root item during the exe file execution under python 2.7, wxpython 2.9.4???

Thanks in advance
Jan 10 '13 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.