[wxPython] wxAcceleratorTable

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[wxPython] wxAcceleratorTable

Daniel Glassey-6
As far as I can tell (from a quick look) a wxAcceleratorTable can only be
constructed from another wxAcceleratorTable. This isn't indicated in the
docs, and I can't see a way to add wxAcceleratorEntry's to one.

Is there any way to do this?

Sorry if I've missed something obvious

Daniel
--
"What quantity of cellulose fibre might one certain
american mammal throw supposing that said creature was
capable of lobbing chunks of tree?"

_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] wxAcceleratorTable

Robin Dunn
> As far as I can tell (from a quick look) a wxAcceleratorTable can only be
> constructed from another wxAcceleratorTable. This isn't indicated in the
> docs, and I can't see a way to add wxAcceleratorEntry's to one.
>
> Is there any way to do this?
>

It's supposed to be able to take a list of wxAcceleratorEntry objects, but I
see that there is a little bug in recogizing the objects as being the right
type.  It's now fixed for the next release.

As a work-around until then, there is an undocumented feature that you can
also use a list of 3-tuples to make the wxAxcelleratorTable.  The three
values in each tuple are the flags, keyCode, and cmd, just like in the
wxAcceleratorEntry constructor.

--
Robin Dunn
Software Craftsman
[hidden email]
http://AllDunn.com/robin/
http://AllDunn.com/wxPython/  Check it out!





_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] wxAcceleratorTable

Bruce Rabine
On Thu, 16 Sep 1999, Robin Dunn wrote:

> > As far as I can tell (from a quick look) a wxAcceleratorTable can only be
> > constructed from another wxAcceleratorTable. This isn't indicated in the
> > docs, and I can't see a way to add wxAcceleratorEntry's to one.
> >
> > Is there any way to do this?
> >
>
> It's supposed to be able to take a list of wxAcceleratorEntry objects, but I
> see that there is a little bug in recogizing the objects as being the right
> type.  It's now fixed for the next release.
>
> As a work-around until then, there is an undocumented feature that you can
> also use a list of 3-tuples to make the wxAxcelleratorTable.  The three
> values in each tuple are the flags, keyCode, and cmd, just like in the
> wxAcceleratorEntry constructor.
>
> --
> Robin Dunn
> Software Craftsman
> [hidden email]
> http://AllDunn.com/robin/
> http://AllDunn.com/wxPython/  Check it out!
>


So according to this last paragraph, I should be able to add the following
to the demo (in Main.py right after the creation of the File and Help
menus) to enable 'Ctrl-X' for 'exit' and 'Ctrl-H' for 'about'?:

self.SetAcceleratorTable([(wxACCEL_CTRL, 120, self.OnFileExit),
        (wxACCEL_CTRL, 104, self.OnHelpAbout)])


On NT 4.0 with Python 1.5.2, wxWindows 2.1 r9, and wxPython 2.1 b3, I get:


D:\Python\wxPython\demo>python.exe demo.py
Traceback (innermost last):
  File "demo.py", line 4, in ?
    Main.main()
  File "Main.py", line 285, in main
    app = MyApp(0)
  File "D:\Python\wxPython\wx.py", line 1447, in __init__
    _wxStart(self.OnInit)
  File "Main.py", line 277, in OnInit
    frame = wxPythonDemo(NULL, -1, "wxPython: (A Demonstration)")
  File "Main.py", line 87, in __init__
    self.SetAcceleratorTable([(wxACCEL_CTRL, 120, self.OnFileExit),
  File "D:\Python\wxPython\frames.py", line 59, in SetAcceleratorTable
    val = apply(framesc.wxFrame_SetAcceleratorTable,(self,) + _args, _kwargs)
TypeError: Type error in argument 2 of wxFrame_SetAcceleratorTable. Expected _wx
AcceleratorTable_p.

D:\Python\wxPython\demo>


If this problem is fixed for the next release, could you please put a
sample (or two) of how to use it in the next version of the demo?

Thanx,

Bruce Rabine





_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] wxAcceleratorTable

Robin Dunn
> >
> > It's supposed to be able to take a list of wxAcceleratorEntry objects,
but I
> > see that there is a little bug in recogizing the objects as being the
right
> > type.  It's now fixed for the next release.
> >
> > As a work-around until then, there is an undocumented feature that you
can
> > also use a list of 3-tuples to make the wxAxcelleratorTable.  The three
> > values in each tuple are the flags, keyCode, and cmd, just like in the
> > wxAcceleratorEntry constructor.
> >

> So according to this last paragraph, I should be able to add the following
> to the demo (in Main.py right after the creation of the File and Help
> menus) to enable 'Ctrl-X' for 'exit' and 'Ctrl-H' for 'about'?:
>
> self.SetAcceleratorTable([(wxACCEL_CTRL, 120, self.OnFileExit),
> (wxACCEL_CTRL, 104, self.OnHelpAbout)])
>


You need to create the Accelerator table first.  Like this:

    self.table = wxAcceleratorTable([(wxACCEL_CTRL, ord('X'), exitID),
                                     (wxACCEL_CTRL, ord('H'), helpID)])
    self.SetAcceleratorTable(self.table)

where exitID and helpID are the IDs of the menu items.

Another feature that I just discovered is that if your menu item labels look
like the following (with the keystroke as part of the label), then the
accelerators are automatically made for you.

    menu.Append(exitID, 'E&xit\tCtrl-X', 'Get the heck outta here!')

--
Robin Dunn
Software Craftsman
[hidden email]
http://AllDunn.com/robin/
http://AllDunn.com/wxPython/  Check it out!



_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] wxAcceleratorTable

Bruce Rabine
Thank You!  It finally works.

It's interesting to note that I had first attemped the following:

self.SetAcceleratorTable(wxAcceleratorTable(
        [(wxACCEL_CTRL, 120, exitID),
         (wxACCEL_CTRL, 104, helpID)]))

and it wouldn't work!?

I then switched out the 120 with 88 and the 104 with 72 and it worked!!!
It seems like the Accelerator Table only deals with CAPITALS!!


Thanx again!

Bruce


On Wed, 22 Sep 1999, Robin Dunn wrote:

>
> You need to create the Accelerator table first.  Like this:
>
>     self.table = wxAcceleratorTable([(wxACCEL_CTRL, ord('X'), exitID),
>                                      (wxACCEL_CTRL, ord('H'), helpID)])
>     self.SetAcceleratorTable(self.table)
>
> where exitID and helpID are the IDs of the menu items.
>
> Another feature that I just discovered is that if your menu item labels look
> like the following (with the keystroke as part of the label), then the
> accelerators are automatically made for you.
>
>     menu.Append(exitID, 'E&xit\tCtrl-X', 'Get the heck outta here!')
>




_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users