From the wx.AcceleratorEntry documentation it seems that...
accel = wx.AcceleratorEntry()
... followed by something like...
accel.FromString("X")
... or...
accel.FromString("Ctrl-Z")
... or even...
accel.FromString("Shift-F12")
... should initialize the AcceleratorEntry with the given keystroke, but
it doesn't seem to work like that (i.e. the FromString method returns
False whatever I try). This is with python 2.6.4 and wxPython 2.8.10.1.
Did I misunderstand the docs? Am I doing it wrong? Is this a bug?
BTW, If I use the tuple method to initialize the AcceleratorEntry and
then use accel.ToString() I do get the above strings back.
Groeten, - Jacco
···
--
+--------------------------+ It's 09:40 MEST on Tuesday September 28
Jacco van Schaik | 2010. Outside it's 13 degrees and mostly
jacco@jaccovanschaik.net | cloudy with a light breeze from the north-
www.jaccovanschaik.net | northeast.
From the wx.AcceleratorEntry documentation it seems that...
accel = wx.AcceleratorEntry()
... followed by something like...
accel.FromString("X")
... or...
accel.FromString("Ctrl-Z")
... or even...
accel.FromString("Shift-F12")
... should initialize the AcceleratorEntry with the given keystroke, but
it doesn't seem to work like that (i.e. the FromString method returns
False whatever I try). This is with python 2.6.4 and wxPython 2.8.10.1.
Did I misunderstand the docs? Am I doing it wrong? Is this a bug?
BTW, If I use the tuple method to initialize the AcceleratorEntry and
then use accel.ToString() I do get the above strings back.
Appears to be an oversite in the implementation of FromString. It uses
the ParseAccel method to get the values from the string and is
expecting to see a '\t' character before acclerator string such as
when you make a menu item i.e) "Copy\tCtrl+C".
Snippet from wxAcceleratorEntry::ParseAccel
// check for accelerators: they are given after '\t'
int posTab = label.Find(wxT('\t'));
if ( posTab == wxNOT_FOUND )
{
return false;
}
So you can work around it be prepending a tab character '\t'
entry.FromString("\tCtrl-C")
Cody
···
On Tue, Sep 28, 2010 at 3:04 AM, Jacco van Schaik <jacco@jaccovanschaik.net> wrote:
> Hi,
>
> From the wx.AcceleratorEntry documentation it seems that...
>
> �accel = wx.AcceleratorEntry()
>
> ... followed by something like...
>
> �accel.FromString("X")
>
> ... or...
>
> �accel.FromString("Ctrl-Z")
>
> ... or even...
>
> �accel.FromString("Shift-F12")
>
> ... should initialize the AcceleratorEntry with the given keystroke, but
> it doesn't seem to work like that (i.e. the FromString method returns
> False whatever I try). This is with python 2.6.4 and wxPython 2.8.10.1.
>
> Did I misunderstand the docs? Am I doing it wrong? Is this a bug?
>
> BTW, If I use the tuple method to initialize the AcceleratorEntry and
> then use accel.ToString() I do get the above strings back.
Appears to be an oversite in the implementation of FromString. It uses
the ParseAccel method to get the values from the string and is
expecting to see a '\t' character before acclerator string such as
when you make a menu item i.e) "Copy\tCtrl+C".
Snippet from wxAcceleratorEntry::ParseAccel
// check for accelerators: they are given after '\t'
int posTab = label.Find(wxT('\t'));
if ( posTab == wxNOT_FOUND )
{
return false;
}
So you can work around it be prepending a tab character '\t'
entry.FromString("\tCtrl-C")
Well, at least that returns True, and doing ToString() on the result
returns "Ctrl-C" as you'd expect. But the accelerator still doesn't work
(the button action isn't triggered).
Which, in retrospect, isn't all that surprising because the FromString
method doesn't take a cmdID parameter like the __init__() and Set()
methods do. So presumably wxPython wouldn't know which button to
trigger.
Anyone know how the FromString method is supposed to be used?
Groeten, - Jacco
···
On Tue, Sep 28, 2010 at 3:04 AM, Jacco van Schaik > <jacco@jaccovanschaik.net> wrote:
--
+--------------------------+ It's 09:33 MEST on Wednesday September 29
Jacco van Schaik | 2010. Outside it's 10 degrees and mostly
jacco@jaccovanschaik.net | clear with a light breeze from the east.
www.jaccovanschaik.net |
I assumed it was used in code that was parsing menu items, but a quick search makes it look like it is not used anywhere in wx, so it may just be left over from an earlier time. Now the static method Create is used in various places like this:
So it is creating the item and then using Set to set the ID if the Create was successful, but also passing the flags and keycode to Set so they will be set to the same value they already have... So yes, a bit of a poor API choice, but it is probably something that has morphed several times over the years.
···
On 9/29/10 12:55 AM, Jacco van Schaik wrote:
Well, at least that returns True, and doing ToString() on the result
returns "Ctrl-C" as you'd expect. But the accelerator still doesn't work
(the button action isn't triggered).
Which, in retrospect, isn't all that surprising because the FromString
method doesn't take a cmdID parameter like the __init__() and Set()
methods do. So presumably wxPython wouldn't know which button to
trigger.
Anyone know how the FromString method is supposed to be used?