Dear Mike and Frank,
Thank you both for your answer. Mike, I investigated yours but ultimately, I think Frank is right saying the icons referred to by the wx.ID_XYZ are to be used only for Buttons and for MenuItems while the ones referred to by wx.ART_WHATEVER are to be used only with the wx.ArtProvider class.
For instance, one can create a button by writing:
btn = wx.Button(panel, wx.ID_OK)
In the other cases when one needs a “bitmap” object, then indeed there are several ways, like:
wx.Image(‘ico_16.png’, …) followed by ConvertToBitmap()
or, following Robin’s demo, where:
data (almost a pure raw string) are fed into cStringIO.StringIO() to get a stream, fed in turn to wx.ImageFromStream() to obtain an image, finally passed to wx.BitmapFromImage() to obtain a bitmap.
This bitmap can then either be passed to a SetBitmap() method - if it exists for the class of objects one is looking at, e.g. wx.MenuItem - or pushed on the ArtProvider stack.
I will probably use Robin’s demo technique for my prototype: I downloaded from the web a few icons that I fine attractive and will convert them into one data file (using img2py I guess).
If you don’t mind, I add a few extra comments / questions that might lead into improving the documentation:
- I was confused because I read the wxWidgets documentation instead of the wxPython documentation.
The first ( http://docs.wxwidgets.org/trunk/page_stockitems.html) says:
The following is the list of the window IDs for which stock buttons and menu items are created. See the wxButton constructor and the wxMenuItem constructor for classes which automatically add stock bitmaps when using stock IDs. Also note that you can retrieve stock bitmaps using wxArtProvider.
The second (http://wxpython.org/onlinedocs.php > constants > Stock items) says:
Window IDs for which stock buttons and menu items are created (see wxButton constructor and wxMenuItem constructor):
The first one say one phrase more. Now that I read wxWidgets doc for the nth time, it says “you can retrieve stock bitmaps” and it doesn’t say “you can retrieve these stock bitmaps” … Most probably it was me assuming it talked about the same !? I’m red with confusion. Sorry all if I made you lose your time.
- When I use the code:
** btn = wx.Button(panel, wx.ID_OK)**
the button is indeed created with the right text but without the icon. I guess this is because I run on Windows XP and Windows does probably not know what is GTk (am I correct to say this ?) or the gtk-xyz.png files have been misplaced on my PC ?
3) When dealing with a bitmap object, for instance:
** bmp = wx.Image(‘my_icon.png’, …).ConvertToBitmap()**
are the the 2 methods bmp.IsOK() and bmp.Ok() the same ?
4) The documentation says that 2 objects are predefined: wx.NullBitmap and wx.NullIcon. Are wx.EmptyBitmap and wx.EmptyIcon synonyms ?
Thank you very much.
Wish you the Peace and Blessings of a Merry Christmas
Rene
···
On Tue, Dec 23, 2008 at 5:00 AM, Mike Driscoll mike@pythonlibrary.org wrote:
Hi Rene,
Dear All,
After many attempts I haven’t been able to figure out how to use Stock ID with ArtProvider.
The documentation says:
/Stock items/
//
/The following is the list of the window IDs for which stock buttons and menu items are created./
//
/See the wxButton constructor and the *wxMenuItem *constructor for classes which automatically add stock bitmaps when using stock IDs. Also note that you can retrieve stock bitmaps using wxArtProvider./
(underline is mine) and then follows a long table with very nice icons, each one referred to by a name (actually a number) like wx.ID_ABOUT, wx.ID_ADD, … till wx.ID_ZOOM_OUT
** The usual way to obtain a bitmap is to write:
/bmp = wx.ArtProvider(wx.ART_HELP, wx.ART_MENU, (16,16))/
where wx.ART_HELP is the name of the icon, ART_MENU is the name of the category and (16,16) is the (x,y) dimension of the required bitmap.
If I candidly write:
/ bmp = wx.ArtProvider(wx.ID_ABOUT, wx.ART_OTHER (16,16))/
I obviously receive the error message:
/File “C:_Python25\Lib\site-packages\wx-2.8-msw-unicode\wx_misc.py”, line 2717, in GetBitmap
return misc.ArtProvider_GetBitmap(*args, **kwargs)
TypeError: String or Unicode type required/
as indeed:
/>>> type(wx.ID_ABOUT)
<type ‘int’>
type(wx.ART_HELP)
<type ‘unicode’>/
// I tried to figure out the right code to write. Well … so far no success. How to retrieve a Stock Bitmap when one knows the Stock ID ? Can somebody please help me ?
Thanks in advance.
Regards, Rene
I usually do it like this:
save_ico = wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE, wx.ART_TOOLBAR, (16,16))
I wrote a little bit about the process here: http://www.blog.pythonlibrary.org/?p=44 In this case, it’s written for toolbars, hence the wx.ART_TOOLBAR.
See also:
http://www.wxpython.org/docs/api/wx.ArtProvider-class.html http://xoomer.alice.it/infinity77/wxPython/Widgets/wx.ArtProvider.html?highlight=artprovider
http://wiki.wxpython.org/BoxSizerTutorial
I hope that helps you some.
Mike Driscoll
Blog: http://blog.pythonlibrary.org
Python Extension Building Network: http://www.pythonlibrary.org
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users