2013/1/8 dhyams <
dhy...@gmail.com>:
>> [...]
>
Hi,
just another take... - it looks quite clumsy, but deleting and
reinserting the respective menuitem seems to work.
I'd rather expect some drawbacks of this approach, but maybe you could
elaborate this trick and test it in your program.
I am not sure, whether the repeated event binding could cause problems
(hopefully the handlers are unbound on deleting the menuitem, but it
could possibly be done explicitely too.
hth,
vbr
##################################################
#! Python
# -*- coding: utf-8 -*-
import wx
words = "x xxxxxxxxxx xxxxxxxxxxxxxxxxxxxx".split()
indx = 0
def OnMenuOpen(evt):
global indx
global undo_menu_item
test_menu.DeleteItem(undo_menu_item)
undo_menu_item = wx.MenuItem(test_menu,-1,"&Undo\tCtrl+Z"," Undo last item")
test_menu.InsertItem(0, undo_menu_item)
undo_menu_item.SetItemLabel(u"&Undo %s\tCtrl+Z" % (words[indx%3]))
undo_menu_item.SetBitmap(wx.Bitmap("edit-undo.png",wx.BITMAP_TYPE_PNG))
frm.Bind(wx.EVT_MENU, OnUndo, undo_menu_item)
indx += 1
def OnUndo(evt):
txt_field.SetValue(undo_menu_item.GetText())
app = wx.App()
frm = wx.Frame(None, -1, u"test menu label")
txt_field = wx.TextCtrl(frm, 1, style=wx.TE_MULTILINE)
frm.CreateStatusBar()
test_menu= wx.Menu()
undo_menu_item = wx.MenuItem(test_menu,-1,"&Undo\tCtrl+Z"," Undo last item")
undo_menu_item.SetBitmap(wx.Bitmap("edit-undo.png",wx.BITMAP_TYPE_PNG))
dummy_menu_item = wx.MenuItem(test_menu,-1,"&Dummy\tCtrl+D"," Dummy
menu item 1")
test_menu.AppendItem(undo_menu_item)
test_menu.AppendItem(dummy_menu_item)