Differences between revisions 11 and 20 (spanning 9 versions)
Revision 11 as of 2004-06-16 11:41:16
Size: 4290
Editor: 61
Comment:
Revision 20 as of 2007-02-07 03:30:13
Size: 4858
Editor: Gnurd
Comment: added some simple GUI stuff for adding large/small icons.
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
Icons are added as {{{icon_resources}}} Icons are added as {{{icon_resources}}} 
Line 4: Line 4:
setup(  setup(
Line 17: Line 17:
Line 20: Line 21:
[[http://liuhecai.100free.com 六合彩]]
[[http://liuhecai.100free.com/liuhecai1.htm 外围玩法]]
[[http://liuhecai.100free.com/liuhecai2.htm 奖金分配]]
[[http://liuhecai.100free.com/liuhecai3.htm 獎金領取]]
[[http://liuhecai.100free.com/liuhecai4.htm 六合彩简介]]
[[http://liuhecai.100free.com/liuhecai5.htm 马会简介]]
[[http://liuhecai.100free.com/liuhecai6.htm 合彩知识]]
[[http://liuhecai.100free.com/liuhecai7.htm 版权声明]]
[[http://liuhecai.100free.com/liuhecai8.htm 六合彩搅珠系统软件]]
[[http://liuhecai.100free.com/liuhecai9.htm 六合彩]]
[[http://liuhecai.100free.com/liuhecai10.htm 六合彩]]
[[http://liuhecai.hostrocket.com 六合彩]]
[[http://liuhecai.hostrocket.com/liuhecai1.htm 外围玩法]]
[[http://liuhecai.hostrocket.com/liuhecai2.htm 奖金分配]]
[[http://liuhecai.hostrocket.com/liuhecai3.htm 獎金領取]]
[[http://liuhecai.hostrocket.com/liuhecai4.htm 六合彩简介]]
[[http://liuhecai.hostrocket.com/liuhecai5.htm 马会简介]]
[[http://liuhecai.hostrocket.com/liuhecai6.htm 合彩知识]]
[[http://liuhecai.hostrocket.com/liuhecai7.htm 版权声明]]
[[http://liuhecai.hostrocket.com/liuhecai8.htm 六合彩搅珠系统软件]]
[[http://liuhecai.hostrocket.com/liuhecai9.htm 六合彩]]
[[http://liuhecai.hostrocket.com/liuhecai10.htm 六合彩]]
[[http://www.angelfire.com/un/liuhecai 六合彩]]
[[http://www.angelfire.com/un/liuhecai/liuhecai1.htm 外围玩法]]
[[http://www.angelfire.com/un/liuhecai/liuhecai2.htm 奖金分配]]
[[http://www.angelfire.com/un/liuhecai/liuhecai3.htm 獎金領取]]
[[http://www.angelfire.com/un/liuhecai/liuhecai4.htm 六合彩简介]]
[[http://www.angelfire.com/un/liuhecai/liuhecai5.htm 马会简介]]
[[http://www.angelfire.com/un/liuhecai/liuhecai6.htm 合彩知识]]
[[http://www.angelfire.com/un/liuhecai/liuhecai7.htm 版权声明]]
[[http://www.angelfire.com/un/liuhecai/liuhecai8.htm 六合彩搅珠系统软件]]
[[http://www.angelfire.com/un/liuhecai/liuhecai9.htm 六合彩]]
[[http://www.angelfire.com/un/liuhecai/liuhecai10.htm 六合彩]]
Line 55: Line 23:
Line 62: Line 31:
Almost all popular icon editors can create complex icon with small and large part in one.  For instance, [http://www.x2studios.com/index.php?page=products&id=11 LiquidIcon] is a freeware icon editor that lets you combine multiple ico files of different sizes and bit-depths into a single ico file. Almost all popular icon editors can create complex icon with small and large part in one. For instance, [http://www.x2studios.com/index.php?page=products&id=11 LiquidIcon] is a freeware icon editor that lets you combine multiple ico files of different sizes and bit-depths into a single ico file. Also available is [http://www.winterdrache.de/freeware/png2ico/ png2ico], a GPL'ed command line-only {{{.ico}}} creator capable of generating icons with multiple sizes, bit depths, and transparency settings.
Line 64: Line 33:
Now I've managed to give an icon to my program, but when the program starts, a standard Windows icon shows up in the window's title bar and in the task bar button (instead of my custom icon). Is there a way I can fix that myself, or is that a current limitation of py2exe? Now I've managed to give an icon to my program, but when the program starts, a standard Windows icon shows up in the window's title bar and in the task bar button (instead of my custom icon). Is there a way I can fix that myself, or is that a current limitation of py2exe?

As far as putting icons on your window itself (above is just for the file in explorer I think) it depends on the gui library you are using.
For wxWindows 2.4 it would be something like this where self is a wx.Frame derived class instance
Example: {{{
#!python
    _icon = wx.EmptyIcon()
    _icon.CopyFromBitmap(wx.Bitmap("MyIcon.ico", wx.BITMAP_TYPE_ANY))
    self.SetIcon(_icon)
}}}

The following also works, at least in wxPython 2.5.2.8 and other recent ones. {{{
#!python
    _icon = wx.Icon('MyIcon.ico', wx.BITMAP_TYPE_ICO)
    self.SetIcon(_icon)
}}}


This should allow the system to pick an appropriate icon. ( only tested with 2.5.3 ) {{{
#!python
    ib=wx.IconBundle()
    ib.AddIconFromFile("MyIcon.ico",wx.BITMAP_TYPE_ANY)
    self.SetIcons(ib)
}}}

'''Simple icon embedding (full)'''

I have found that this works just fine with the latest python/py2exe install...{{{
from distutils.core import setup
import py2exe

setup(
    console = [
        {
            "script": "main.py", ### Main Python script
            "icon_resources": [(0, "icon.ico")] ### Icon to embed into the PE file.
        }
    ],
) }}}

as far as I can tell this works just fine. small/large icons are detectable in a resource editor like Xn resource editor.

-- Morgan Gangwere

'''How to access a Win32 .exe's or .dll's icons from wxPython 2.6.1.0'''
The following information was discovered by looking at gdiimage.cpp in the wxPython source.

Supposing your py2exe setup.py file had the following icons:

{{{
"icon_resources": [(1, "myicon1.ico"), (42, "myicon2.ico")]
}}}

To programmatically determine the path of the currently running .exe, use:

{{{
import win32api
exeName = win32api.GetModuleFileName(win32api.GetModuleHandle(None))
}}}

You can get the first icon (myicon1.ico) in the .exe with the following:

{{{
icon = wx.Icon(exeName, wx.BITMAP_TYPE_ICO)
}}}

You can also get the first icon (myicon1.ico) with a zero based index:

{{{
icon = wx.Icon(exeName + ";0", wx.BITMAP_TYPE_ICO)
}}}

Likewise, you can get the second icon (myicon2.ico) with:

{{{
icon = wx.Icon(exeName + ";1", wx.BITMAP_TYPE_ICO)
}}}

You can get an icon based on it's icon id, just specify the negated id number (myicon2.ico):

{{{
icon = wx.Icon(exeName + ";-42", wx.BITMAP_TYPE_ICO)
}}}

Because of the way it's implemented, you cannot specify ";-1", you will get incorrect operation or a crash.

If you wanted to set your window's title bar and task switch icons you would do the following in your wx.Frame _ _init_ _:

{{{
self.SetIcon(icon)
}}}

Here's an example program:

{{{
#!python
import wx, win32api

class MyFrame(wx.Frame):
    def __init__(self, parent=None):
        wx.Frame.__init__(self, parent, wx.ID_ANY)

        # set window icon
        exeName = win32api.GetModuleFileName(win32api.GetModuleHandle(None))
        icon = wx.Icon(exeName, wx.BITMAP_TYPE_ICO)
        self.SetIcon(icon)

if __name__ == '__main__':
    app = wx.App(redirect=False)
    frame = MyFrame()
    frame.Show(True)
    app.MainLoop()
}}}

Icons are added as icon_resources

setup(
    windows = [
        {
            "script": "with_gui.py",
            "icon_resources": [(1, "myicon.ico")]
        }
    ],
)

The same practice works as well for console and windows scripts. The resource number does not seem to matter. Windows just takes the first existing icon.

/!\ if somebody knows how to add small and large icons, speak up...

Hm, doesn't the .ico file contain them?

does the resource number refers to the icon's index in the .ico file (if containing > 1 icons) ?

-- [mailto:dswsh@plasa.com dody wijaya]

How to add small and large icons

You must create ico file with two icons in one. Your icon file must contain small ico (size: 16*16 pixels) and large ico (size: 32*32 pixels). For WindowsXP you probably may create a big ico (48*48) - but it's only for XP. Almost all popular icon editors can create complex icon with small and large part in one. For instance, [http://www.x2studios.com/index.php?page=products&id=11 LiquidIcon] is a freeware icon editor that lets you combine multiple ico files of different sizes and bit-depths into a single ico file. Also available is [http://www.winterdrache.de/freeware/png2ico/ png2ico], a GPL'ed command line-only .ico creator capable of generating icons with multiple sizes, bit depths, and transparency settings.

Now I've managed to give an icon to my program, but when the program starts, a standard Windows icon shows up in the window's title bar and in the task bar button (instead of my custom icon). Is there a way I can fix that myself, or is that a current limitation of py2exe?

As far as putting icons on your window itself (above is just for the file in explorer I think) it depends on the gui library you are using. For wxWindows 2.4 it would be something like this where self is a wx.Frame derived class instance Example:

   1     _icon = wx.EmptyIcon()
   2     _icon.CopyFromBitmap(wx.Bitmap("MyIcon.ico", wx.BITMAP_TYPE_ANY))
   3     self.SetIcon(_icon)

The following also works, at least in wxPython 2.5.2.8 and other recent ones.

   1     _icon = wx.Icon('MyIcon.ico', wx.BITMAP_TYPE_ICO)
   2     self.SetIcon(_icon)

This should allow the system to pick an appropriate icon. ( only tested with 2.5.3 )

   1     ib=wx.IconBundle()
   2     ib.AddIconFromFile("MyIcon.ico",wx.BITMAP_TYPE_ANY)
   3     self.SetIcons(ib)

Simple icon embedding (full)

I have found that this works just fine with the latest python/py2exe install...

from distutils.core import setup
import py2exe

setup(
    console = [
        {
            "script": "main.py",                    ### Main Python script    
            "icon_resources": [(0, "icon.ico")]     ### Icon to embed into the PE file.
        }
    ],
) 

as far as I can tell this works just fine. small/large icons are detectable in a resource editor like Xn resource editor.

-- Morgan Gangwere

How to access a Win32 .exe's or .dll's icons from wxPython 2.6.1.0 The following information was discovered by looking at gdiimage.cpp in the wxPython source.

Supposing your py2exe setup.py file had the following icons:

"icon_resources": [(1, "myicon1.ico"), (42, "myicon2.ico")]

To programmatically determine the path of the currently running .exe, use:

import win32api
exeName = win32api.GetModuleFileName(win32api.GetModuleHandle(None))

You can get the first icon (myicon1.ico) in the .exe with the following:

icon = wx.Icon(exeName, wx.BITMAP_TYPE_ICO)

You can also get the first icon (myicon1.ico) with a zero based index:

icon = wx.Icon(exeName + ";0", wx.BITMAP_TYPE_ICO)

Likewise, you can get the second icon (myicon2.ico) with:

icon = wx.Icon(exeName + ";1", wx.BITMAP_TYPE_ICO)

You can get an icon based on it's icon id, just specify the negated id number (myicon2.ico):

icon = wx.Icon(exeName + ";-42", wx.BITMAP_TYPE_ICO)

Because of the way it's implemented, you cannot specify ";-1", you will get incorrect operation or a crash.

If you wanted to set your window's title bar and task switch icons you would do the following in your wx.Frame _ _init_ _:

self.SetIcon(icon)

Here's an example program:

   1 import wx, win32api
   2 
   3 class MyFrame(wx.Frame):
   4     def __init__(self, parent=None):
   5         wx.Frame.__init__(self, parent, wx.ID_ANY)
   6 
   7         # set window icon
   8         exeName = win32api.GetModuleFileName(win32api.GetModuleHandle(None))
   9         icon = wx.Icon(exeName, wx.BITMAP_TYPE_ICO)
  10         self.SetIcon(icon)
  11 
  12 if __name__ == '__main__':
  13     app = wx.App(redirect=False)
  14     frame = MyFrame()
  15     frame.Show(True)
  16     app.MainLoop()

CustomIcons (last edited 2011-08-05 21:58:17 by SunjayVarma)