Example program:
import sys
import wx
from wx.lib.embeddedimage import PyEmbeddedImage
img = PyEmbeddedImage(
"iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABmJLR0QAAAAAAAD5Q7t/
AAAA"
"CXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH1QYGDS8dXc5KpwAAADV0RVh0Q29tbWVudAAo"
"YykgMjAwNCBKYWt1YiBTdGVpbmVyCgpDcmVhdGVkIHdpdGggVGhlIEdJTVCQ2YtvAAAB
+klE"
"QVQ4y52TwWpTQRSGvzkzwV7S1pI2CFptC3VhUkjabsSlrxBKF0UQdONW3BsK7sQnUPA9pLos"
"WtskzW3AgopKi6jtxYQSY3LnuEi8pYsidjbD8M98c/7/
zJil5dJDoMzZRtksLZf0zt3bZzr9"
"7Olz3N/F5tbLUze2Wkek0wHtdgdrhaGhcywu3AQ4BjSbB6cCPrzfw1ohOmzRbB5x/
cZcoiWA"
"mZm5UwFTUzmMMagqxhiMMYlmlpZLGjXbPLh/
77/8rz56wqULmX4F3W6P8upjfnU6fVUV/QdA"
"RI4t3FpZ4dXaC7yHi5OTfN3fx/uYkfNjtH5GqPcE6RGMCNHhASKG/
g0eFwQBla03XJ2dRVUJ"
"w5B8Po
+1ljAMyeVyiAiNRgPFsDhfJJVK0e12qdUrSLvdxsceVU1CAojjGDB0Oh289wB4Vay1"
"6GBOLFyZmuH1+joYw0Q2y85OA+9jxjLjvNvdBVXGMhMoUKvVEkgC+PzpI8VioW
+h0SCXu4Zz"
"jnq9znyxiIhQrdZwzlEoFJIqNysbyCB2nHN47/
G9HtZanHOISNJ3EQP0S0+lUie7MHl5msrm"
"W8Awns2yXa/jrCU9PMx2GGJUGQoCfg/aPDo6ShRFJ1/i/
MICANZa4ulpDGBE0EGARoS9vS98"
"//GNw+hgEHIfUK5WN878nf8AhFzLEABZzNIAAAAASUVORK5CYII=")
class MyFrame(wx.Frame):
def __init__(self, parent, id=-1, title='Popup image test',
pos=wx.DefaultPosition, size=(200, 200),
style=wx.DEFAULT_FRAME_STYLE):
wx.Frame.__init__(self, parent, id, title, pos, size, style)
lst = wx.ListCtrl(self,-1,style=wx.LC_REPORT)
lst.InsertColumn(0, "Column 01")
for i in range(100):
lst.InsertStringItem(sys.maxint, "Right click me %s"%i)
lst.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.onPopupMenu, lst)
self.Bind(wx.EVT_CLOSE, self.OnClose)
def OnClose(self, event):
self.Destroy()
def onPopupMenu(self,evt):
global img
menu = wx.Menu()
item = wx.MenuItem(None,-1,u"Test")
item.SetBitmap(img.GetBitmap())
menu.AppendItem(item)
#menu.Bind(wx.EVT_MENU,self.onPopupMenuItemSelected,item)
self.PopupMenu( menu, evt.GetPoint())
menu.Destroy()
app = wx.App()
frame = MyFrame(None)
frame.Show()
app.MainLoop()
Here are different try-outs:
* Under Windows 7 + Python 2.7 + wxPython 2.9, everything is fine for
me.
* Under Ubuntu 11 amd64, Python 2.7.1+, wxPython 2.8.11.0, the icon
does NOT show up! (this is my main problem) I personally tested this
one.
Others reported:
* Under Ubuntu 9.04 with wx 2.8.9.1 - icon shows up
* OS X 10.6 with wx 2.8.12.0 throws this:
Traceback (most recent call last):
File "x.py", line 46, in onPopupMenu
item = wx.MenuItem(None,-1,u"Test")
File "/usr/local/lib/wxPython-unicode-2.8.12.0/lib/python2.6/site-
packages/wx-2.8-mac-unicode/wx/_core.py", line 11481, in __init__
_core_.MenuItem_swiginit(self,_core_.new_MenuItem(*args,
**kwargs))
wx._core.PyAssertionError: C++ assertion "parentMenu != NULL" failed
at /BUILD/wxPython-src-2.8.12.0/src/common/menucmn.cpp(389) in
wxMenuItemBase(): menuitem should have a menu
* XP with wx 2.8.10.1 - same exception raised
(The last two was tested by somebody else.)
Question is of course, why the icon is not showing up? Is this a known
bug?
Thanks,
Laszlo