2013/1/8 dhyams dhy...@gmail.com:
vbr:
Thanks so much for your reply…it helped a lot! I took your sample and
slightly modified it…basically, all I did was add a bitmap to the menu
item. As soon as the bitmap is added, the menu width refuses to change
width wider than the first invocation, leading to the problem that I posted
about.
Somehow, adding a bitmap anywhere in the menu is freezing its width.
I have attached the sample code and the one bitmap that needs to go with
it…just put both in the same directory and run.
On Tuesday, January 8, 2013 10:23:01 AM UTC-5, vbr wrote:
2013/1/5 dhyams dhy...@gmail.com:
I have a undo/redo mechanism, so when the user clicks the “Edit” menu, I
want to display something like “Undo move”, or “Undo resize” or
something as
appropriate for the action that is to be undone.
So I’m using wx.EVT_UPDATE_UI, and calling evt.SetText() appropriately.
That parts works just fine.
The problem, and it’s windows only, is that Windows apparently only
calculates the menu width once ever. So, let’s say that the first time
the
user opens the menu, it says “Undo move”, and the second time the user
opens
the menu, it says “Undo your last thing”. The second time the menu
opens,
the menu still has the same width as it did on the first, so the "Undo
your
last thing" runs into the accelerator key text (“Ctrl+Z”).
I have messed with this for hours and dug into the wxWidgets source, but
I
still don’t see a workaround. Does anyone have any suggestions?
I have a couple of pictures attached to illustrate.
–
To unsubscribe, send email to wxPython-user...@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en
Hi,
as your gui looks rather complex and fine tuned, I am not sure the
following trivial approach would be applicable,
but simply changing the respective label seems to work for me (python
2.7, wxPython 2.9; win 7, not sure for others). In this simplified
sample the menu item is referenced globally; you could likely use
menu.FindItemById( … ) etc.
hth,
vbr
[…]
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)
menu_bar = wx.MenuBar()
menu_bar.Append(test_menu,“&Testmenu”)
frm.SetMenuBar(menu_bar)
frm.Bind(wx.EVT_MENU_OPEN, OnMenuOpen)
frm.Bind(wx.EVT_MENU, OnUndo, undo_menu_item)
frm.Show(True)
app.MainLoop()
##################################################