wx MenuItem - icon is missing

Laszlo Nagy gandalf at shopzeus.com
Tue Jul 5 21:32:37 CEST 2011


> 1. Post a complete example that demonstrates the problem so that we don't have to dummy up a wx app ourselves to try your code.

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()

Under windows, this displays the icon for the popup menu item. Under GTK 
it doesn't and there is no error message, no exception.

Thanks

     L




More information about the Python-list mailing list