> 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
2008/12/23 Rene Heymans <rene.h...@gmail.com>:
> 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 wx.ArtProvider documentation
(http://www.wxpython.org/onlinedocs.php) lists constants that start
with wx.ART_, like wx.ART_ADD_BOOKMARK, wx.ART_DEL_BOOKMARK, etc.
I think the wx.ID_* constants are for use with buttons and menu items only.
Cheers, Frank
not necessarily -- A == B if A and B have the same value. Actually, you
can override the definition of == if you like for custom objects. But
anyway, if you really want to know if A and B are the same object, use is:
>>> A = "a string"
>>> B = A
>>> A == B
True
>>> A is B
True
>>> A = 5.6
>>> B = 5.6
>>> A == B
True
>>> A is B
False
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Frank's a smart man and I was likely confused about what exactly you
needed. However, you can do what you want with some of the generic
buttons...like this:
<code>
import wx
import wx.lib.buttons as buttons
class MyForm(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "Tutorial")
# Add a panel so it looks the correct on all platforms
panel = wx.Panel(self, wx.ID_ANY)
bmp = wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE,
wx.ART_TOOLBAR, (16,16))
self.btn = buttons.GenBitmapTextButton(panel, -1, bmp, "My
Text", size=(175, 75))
# Run the program
if __name__ == "__main__":
app = wx.PySimpleApp()
frame = MyForm().Show()
app.MainLoop()
</code>
>
> <snip>
>
> If you don't mind, I add a few extra comments / questions that might
> lead into improving the documentation:
>
> 1) 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/
> <http://mail.google.com/mail/classwx_button.html>/ constructor and
> the //wxMenuItem/
> <http://mail.google.com/mail/classwx_menu_item.html>/ constructor for
> classes which automatically add stock bitmaps when using stock IDs.
> Also note that you can retrieve stock bitmaps using //wxArtProvider/
> <http://mail.google.com/mail/classwx_art_provider.html>/./
>
> 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/
> <http://mail.google.com/mail/wx_wxbutton.html#wxbuttonctor>/ and //wxMenuItem
> constructor/
> <http://mail.google.com/mail/wx_wxmenuitem.html#wxmenuitemctor>/):/
>
> 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.
You gotta watch out for that. Whenever I look up something for wxPython
with Google, I do something like this in the search box: wxPython wx.Button
If you always preface it with wxPython, it seems to return the correct
results in most cases.
>
> 2) 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 ?*
Windows just doesn't have pictures associated with the default id. I
think you CAN do it if you're using standard dialogs though. It might
work if you subclass wx.Dialog as well, but I'm not sure.
> **
> *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 ?*
I don't know. Robin (or another more knowledgeable wx guru) will
hopefully be able to answer this and the next question...
> **
> *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
Merry Christmas to you as well.
Mike
Comparing the id of the objects makes it a little bit clearer:
>>> A = 5.6
>>> B = 5.6
>>> id(A)
12788672
>>> id(B)
12788784
Notice that each object has a different id. Now if we do the other
example that Chris gave us you'll see that they end up pointing at the
same object (i.e. they have the same id)
A = "a string"
>>> B = A
>>> id(A)
31770464
>>> id(B)
31770464
Isn't introspection fun?
_______________________________________________
wxpython-users mailing list
wxpytho...@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
2) 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 ?
Hmmm...I'd forgotten that tidbit of Chun's. Then again, his book was
almost as big as Lutz's "Programming Python". Interesting.
- Mike
>
> Yes, introspection is fun ! And also it is sometime very good to go
> back to basics or, as we say in French, the "B, A, BA"
>
> Thanks again.
> Cheers, Rene
> Blog: http://blog.pythonlibrary.org <http://blog.pythonlibrary.org/>
> Python Extension Building Network:
> http://www.pythonlibrary.org <http://www.pythonlibrary.org/>
>
> _______________________________________________
> wxpython-users mailing list
> wxpytho...@lists.wxwidgets.org
> <mailto:wxpytho...@lists.wxwidgets.org>
> http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
>
>
> ------------------------------------------------------------------------
_______________________________________________