How to get arbitrary text after a tab in a menu item text?

Two things:

It sounds like you are trying to do something with the menu that isn't
part of a standard GUI guideline. What is this extra text for? A help
string? That would appear in a status bar if your frame has one.

If you must do this, look at the string formatting methods like ljust
and rjust. If you know the longest string, add one or two character
spaces to that, and use the ljust method, you can reproduce this. (I
use it for printing tables.) I'm not sure why you would want to.

Josh

···

On Tue, Jul 29, 2008 at 4:07 AM, Maarten Stol <maarten.stol@neonova.nl> wrote:

Hi,

This is about the use of \t in the text of a menu item.

when i call wx.MenuItem like this:
item = wx.MenuItem(menu_Actions, self.ID_AN_ENTER, _('Some action:\tEnter'),
_("Some action"))

an accelerator is created automatically because i use the \t character in
the menu item text. (see p. 309, Ch 10.2.3 in the wxPython in action book)

However, i would like to use the \t tab character **without** wxPython
processing what follows automatically.

I.e., I would like to disable processing of what follows after the \t, and
put any text I like there. Right now, when I put some text there that
wxPython does not recognize, that text is ignored, and the remainder of the
menu item text is left blanc.

I can get the accelerator to work anyway via an accelerator table, but
somehow wxPython does not allow me to put arbitrary text after the \t
character.

I **do need** the \t however, to get my menu texts aligned properly.

Is there an easy way to disable the \t processing?
Is there another easy workaround?

many thanks,
Maarten

Python 2.5.1 (r251:54863, Oct 30 2007, 13:54:11)
[GCC 4.1.2 20070925 (Red Hat 4.1.2-33)] on linux2

wx.version()

'2.8.4.0 (gtk2-unicode)'

--
NeoNova BV, The Netherlands
Professional internet and VoIP solutions

http://www.neonova.nl Kruislaan 419 1098 VA Amsterdam
info: 020-5628292 servicedesk: 020-5628292 fax: 020-5628291

The following disclamer applies to this email:
http://www.neonova.nl/maildisclaimer
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

--
Josh English
Joshua.R.English@gmail.com

thanks for your reply Josh,

my current problem is solved, although part of my question still stands.

Josh English wrote:

Two things:

It sounds like you are trying to do something with the menu that isn't
part of a standard GUI guideline. What is this extra text for? A help
string? That would appear in a status bar if your frame has one.

The extra text would not have been a help string, that is indeed in the statusbar. It would just have been a name for a menu item, a name that i wanted to prevent from being interpreted by wxpython.

The problem arose because i was trying to make the enter button do different things than the numpad enter. using an accelerator table it almost worked. and if i removed the "\tenter" from the menu item's text it all worked well. what remained was to put the right text **after a \t** in the menu item text, ie, "Numpad-enter" vs. "Enter".

In the end i decided that making a difference between enter and numpad-enter would be confusing for the end user, and i now let the function be triggered by a space bar key event. Better for me, better for the end user. :slight_smile:

If you must do this, look at the string formatting methods like ljust
and rjust. If you know the longest string, add one or two character
spaces to that, and use the ljust method, you can reproduce this. (I
use it for printing tables.) I'm not sure why you would want to.

ljust and rjust would not have been ideal, since i fear that cross platform issues, and different fonts, would have made the menu look bad on some platforms/fonts that i cannot anticipate at code time.

I do still wonder how to get \t characters in the menu item text **without** the text after the \t being a special name, like those in table 10.6 on p.310 of the "wxPython in action" book. (2006 edition)

What if i have a special key called "blah" on my keyboard, and i want the menu text to read "Action\tblah"?

Right now wxPython will leave the text after the \t blanc because it does not recognize "blah".

yours,
Maarten

ps: this is my very first wxpython project :slight_smile:

···

Josh

On Tue, Jul 29, 2008 at 4:07 AM, Maarten Stol <maarten.stol@neonova.nl> wrote:

Hi,

This is about the use of \t in the text of a menu item.

when i call wx.MenuItem like this:
item = wx.MenuItem(menu_Actions, self.ID_AN_ENTER, _('Some action:\tEnter'),
_("Some action"))

an accelerator is created automatically because i use the \t character in
the menu item text. (see p. 309, Ch 10.2.3 in the wxPython in action book)

However, i would like to use the \t tab character **without** wxPython
processing what follows automatically.

I.e., I would like to disable processing of what follows after the \t, and
put any text I like there. Right now, when I put some text there that
wxPython does not recognize, that text is ignored, and the remainder of the
menu item text is left blanc.

I can get the accelerator to work anyway via an accelerator table, but
somehow wxPython does not allow me to put arbitrary text after the \t
character.

I **do need** the \t however, to get my menu texts aligned properly.

Is there an easy way to disable the \t processing?
Is there another easy workaround?

many thanks,
Maarten

Python 2.5.1 (r251:54863, Oct 30 2007, 13:54:11)
[GCC 4.1.2 20070925 (Red Hat 4.1.2-33)] on linux2

wx.version()

'2.8.4.0 (gtk2-unicode)'

--
NeoNova BV, The Netherlands
Professional internet and VoIP solutions

http://www.neonova.nl Kruislaan 419 1098 VA Amsterdam
info: 020-5628292 servicedesk: 020-5628292 fax: 020-5628291

The following disclamer applies to this email:
http://www.neonova.nl/maildisclaimer

Maarten Stol wrote:

I do still wonder how to get \t characters in the menu item text **without** the text after the \t being a special name

It's currently not possible, but I agree that it would be nice to be able to do it. Also to have standard keys listed without them being added to the accelerator table.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

I don't think it's possible to prevent wxPython from automatically
adding things to the accelerator table. I don't mess with the tables,
because I haven't figured out how to manipulate them. It looks like
all you can do is replace them, which is clunky.

Josh

···

On Fri, Aug 1, 2008 at 3:11 AM, Maarten Stol <maarten.stol@neonova.nl> wrote:

thanks for your reply Josh,

my current problem is solved, although part of my question still stands.

--
Josh English
Joshua.R.English@gmail.com

Robin Dunn wrote:

Maarten Stol wrote:

I do still wonder how to get \t characters in the menu item text **without** the text after the \t being a special name

It's currently not possible, but I agree that it would be nice to be able to do it. Also to have standard keys listed without them being added to the accelerator table.

allright, thank you.

That is good to know, at least i know now that i will not have to look any further into this, for the time being.

···

--
NeoNova BV, The Netherlands
Professional internet and VoIP solutions

http://www.neonova.nl Kruislaan 419 1098 VA Amsterdam
info: 020-5628292 servicedesk: 020-5628292 fax: 020-5628291

The following disclamer applies to this email:
http://www.neonova.nl/maildisclaimer