Accelerator table and wx.NewId(): bug ?

Hi all.

I just noticed that setting an entry in an accelerator table with a custom id (an id that doesn't belong to an existing menu item) doesn't work anymore in wxPython 2.8.8.1 (I tried it with some previous version and it worked):

newId = wx.NewId()
self.Bind(wx.EVT_MENU, self.OnCtrlQ, id=newId)
acct = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord("q"), newId)])
self.SetAcceleratorTable(acct)

self.OnCtrlQ is never called (I tried all possible variations, such as using "Q", executing the code in __init__ or after the creation of all child controls, and so on).

Is that a bug ? If not, is there a solution ?
Thanks in advance, Diego.

I am wondering, is there a way in MediaCtrl to change the speed of the video so you can slow it down or speed it up?

Thanks,

Stuart

Hi Diego,

Hi all.

I just noticed that setting an entry in an accelerator table with a custom id (an id that doesn't belong to an existing menu item) doesn't work anymore in wxPython 2.8.8.1 (I tried it with some previous version and it worked):

newId = wx.NewId()
self.Bind(wx.EVT_MENU, self.OnCtrlQ, id=newId)
acct = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord("q"), newId)])
self.SetAcceleratorTable(acct)

self.OnCtrlQ is never called (I tried all possible variations, such as using "Q", executing the code in __init__ or after the creation of all child controls, and so on).

Is that a bug ? If not, is there a solution ?
Thanks in advance, Diego.

I'm getting the exact same behavior unless I actually have a menu instantiated. Uncomment the code below and it works (at least on WinXP, Py2.5.2, wx 2.8.8.1)

<code>

import wx
class MyForm(wx.Frame):
     def __init__(self):
        wx.Frame.__init__(self, None, wx.ID_ANY, "wx.Menu Tutorial")
         # Add a panel so it looks the correct on all platforms
        self.panel = wx.Panel(self, wx.ID_ANY)
## menuBar = wx.MenuBar()
## fileMenu = wx.Menu()
## exitMenuItem = fileMenu.Append(wx.NewId(), "Exit",
## "Exit the application")
## menuBar.Append(fileMenu, "File")
## self.SetMenuBar(menuBar)

        exitId = wx.NewId()
        self.Bind(wx.EVT_MENU, self.onExit, id=exitId )
        accel_tbl = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord('Q'), exitId )])
        self.SetAcceleratorTable(accel_tbl)
     def onExit(self, event):
        print 'in onExit'

# Run the program
if __name__ == "__main__":
    app = wx.PySimpleApp()
    frame = MyForm().Show()
    app.MainLoop()

</code>

I'm not sure what the deal is...

···

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org
Python Extension Building Network: http://www.pythonlibrary.org

Mike Driscoll ha scritto:

I'm getting the exact same behavior unless I actually have a menu instantiated. Uncomment the code below and it works (at least on WinXP, Py2.5.2, wx 2.8.8.1)

<code>

import wx

class MyForm(wx.Frame):

   def __init__(self):
       wx.Frame.__init__(self, None, wx.ID_ANY, "wx.Menu Tutorial")

       # Add a panel so it looks the correct on all platforms
       self.panel = wx.Panel(self, wx.ID_ANY)

## menuBar = wx.MenuBar()
## fileMenu = wx.Menu()
## exitMenuItem = fileMenu.Append(wx.NewId(), "Exit",
## "Exit the application")
## menuBar.Append(fileMenu, "File")
## self.SetMenuBar(menuBar)

       exitId = wx.NewId()
       self.Bind(wx.EVT_MENU, self.onExit, id=exitId )
       accel_tbl = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord('Q'), exitId )])
       self.SetAcceleratorTable(accel_tbl)

   def onExit(self, event):
       print 'in onExit'

# Run the program
if __name__ == "__main__":
   app = wx.PySimpleApp()
   frame = MyForm().Show()
   app.MainLoop()

</code>

I know this workaround... but I can't use it beacause I have a menu bar already set in the frame, so to get that code work I should create some hidden menu items, and the stuff would get tangled. Thanks anyway.

I'm not sure what the deal is...

Some idea ? ...

imho wrote:

<div class="moz-text-flowed" style="font-family: -moz-fixed">Mike Driscoll ha scritto:

I'm getting the exact same behavior unless I actually have a menu instantiated. Uncomment the code below and it works (at least on WinXP, Py2.5.2, wx 2.8.8.1)

<code>

import wx

class MyForm(wx.Frame):

   def __init__(self):
       wx.Frame.__init__(self, None, wx.ID_ANY, "wx.Menu Tutorial")

       # Add a panel so it looks the correct on all platforms
       self.panel = wx.Panel(self, wx.ID_ANY)

## menuBar = wx.MenuBar()
## fileMenu = wx.Menu()
## exitMenuItem = fileMenu.Append(wx.NewId(), "Exit",
## "Exit the application")
## menuBar.Append(fileMenu, "File")
## self.SetMenuBar(menuBar)

       exitId = wx.NewId()
       self.Bind(wx.EVT_MENU, self.onExit, id=exitId )
       accel_tbl = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord('Q'), exitId )])
       self.SetAcceleratorTable(accel_tbl)

   def onExit(self, event):
       print 'in onExit'

# Run the program
if __name__ == "__main__":
   app = wx.PySimpleApp()
   frame = MyForm().Show()
   app.MainLoop()

</code>

I know this workaround... but I can't use it beacause I have a menu bar already set in the frame, so to get that code work I should create some hidden menu items, and the stuff would get tangled. Thanks anyway.

If you already have a menubar, then why isn't this working? You're not using the same id in your menu that you are in your accelerator table are you? I'm not...

I'm not sure what the deal is...

Some idea ? ...

Not really. Hopefully Robin or one of the other very knowledgeable fellows will give some insight.

···

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org
Python Extension Building Network: http://www.pythonlibrary.org

wxMediaCtrl.SetPlaybackRate() works with wx.MEDIABACKEND_QUICKTIME and
wx.MEDIABACKEND_DIRECTSHOW, but I can't get it to work with
wx.MEDIABACKEND_WMP10.

As a result, my Windows users have to choose between support for speed
control (which is crucial to some) and support for some formats (such as
newer WMV and WMA content, which work with WMP10 but not DirectShow.)

David K. Woods, Ph.D.
Researcher, Transana Lead Developer
Wisconsin Center for Education Research
University of Wisconsin, Madison
http://www.transana.org

···

-----Original Message-----
From: wxpython-users-bounces@lists.wxwidgets.org
[mailto:wxpython-users-bounces@lists.wxwidgets.org] On Behalf
Of Stuart Thiessen
Sent: Sunday, September 07, 2008 12:00 PM
To: wxpython-users@lists.wxwidgets.org
Subject: [wxpython-users] MediaCtrl

I am wondering, is there a way in MediaCtrl to change the
speed of the
video so you can slow it down or speed it up?

Thanks,

Stuart
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Mike Driscoll ha scritto:

imho wrote:

<code>

import wx

class MyForm(wx.Frame):

   def __init__(self):
       wx.Frame.__init__(self, None, wx.ID_ANY, "wx.Menu Tutorial")

       # Add a panel so it looks the correct on all platforms
       self.panel = wx.Panel(self, wx.ID_ANY)

## menuBar = wx.MenuBar()
## fileMenu = wx.Menu()
## exitMenuItem = fileMenu.Append(wx.NewId(), "Exit",
## "Exit the application")
## menuBar.Append(fileMenu, "File")
## self.SetMenuBar(menuBar)

       exitId = wx.NewId()
       self.Bind(wx.EVT_MENU, self.onExit, id=exitId )
       accel_tbl = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord('Q'), exitId )])
       self.SetAcceleratorTable(accel_tbl)

   def onExit(self, event):
       print 'in onExit'

# Run the program
if __name__ == "__main__":
   app = wx.PySimpleApp()
   frame = MyForm().Show()
   app.MainLoop()

</code>

I know this workaround... but I can't use it beacause I have a menu bar already set in the frame, so to get that code work I should create some hidden menu items, and the stuff would get tangled. Thanks anyway.

If you already have a menubar, then why isn't this working? You're not using the same id in your menu that you are in your accelerator table are you? I'm not...

Exactly. I'd like to use a wholly new id, apart from those existing in my menus. And I wish I could avoid to insert an hidden menu item solely to make my accelerator table to work.

···

I'm not sure what the deal is...

Some idea ? ...

Not really. Hopefully Robin or one of the other very knowledgeable fellows will give some insight.

imho wrote:

Mike Driscoll ha scritto:

imho wrote:

<code>

import wx

class MyForm(wx.Frame):

   def __init__(self):
       wx.Frame.__init__(self, None, wx.ID_ANY, "wx.Menu Tutorial")

       # Add a panel so it looks the correct on all platforms
       self.panel = wx.Panel(self, wx.ID_ANY)

## menuBar = wx.MenuBar()
## fileMenu = wx.Menu()
## exitMenuItem = fileMenu.Append(wx.NewId(), "Exit",
## "Exit the application")
## menuBar.Append(fileMenu, "File")
## self.SetMenuBar(menuBar)

       exitId = wx.NewId()
       self.Bind(wx.EVT_MENU, self.onExit, id=exitId )
       accel_tbl = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord('Q'), exitId )])
       self.SetAcceleratorTable(accel_tbl)

   def onExit(self, event):
       print 'in onExit'

# Run the program
if __name__ == "__main__":
   app = wx.PySimpleApp()
   frame = MyForm().Show()
   app.MainLoop()

</code>

I know this workaround... but I can't use it beacause I have a menu bar already set in the frame, so to get that code work I should create some hidden menu items, and the stuff would get tangled. Thanks anyway.

If you already have a menubar, then why isn't this working? You're not using the same id in your menu that you are in your accelerator table are you? I'm not...

Exactly. I'd like to use a wholly new id, apart from those existing in my menus. And I wish I could avoid to insert an hidden menu item solely to make my accelerator table to work.

Maybe my code is confusing, but the id in my menu is different than the one in my accelerator table. First, I create a menu item:

exitMenuItem = fileMenu.Append(wx.NewId(), "Exit", "Exit the application")

Notice the wx.NewId() call. Then I create another id:

exitId = wx.NewId()

and bind it to EVT_MENU, which is what is needed for an accelerator to work:

self.Bind(wx.EVT_MENU, self.onExit, id=exitId )

I forgot to bind my menu item, so here's how I would do that:

self.Bind(wx.EVT_MENU, self.onExit, exitMenuItem)

Notice that both the menu item AND the accelerator table are bound to the same event handler, but have different ids. Can you provide a small runnable sample of the code that's giving you fits so the rest of us can take a look?

Mike

Mike Driscoll ha scritto:

If you already have a menubar, then why isn't this working? You're not using the same id in your menu that you are in your accelerator table are you? I'm not...

Exactly. I'd like to use a wholly new id, apart from those existing in my menus. And I wish I could avoid to insert an hidden menu item solely to make my accelerator table to work.

Maybe my code is confusing, but the id in my menu is different than the one in my accelerator table. First, I create a menu item:

exitMenuItem = fileMenu.Append(wx.NewId(), "Exit", "Exit the application")

Notice the wx.NewId() call. Then I create another id:

exitId = wx.NewId()

and bind it to EVT_MENU, which is what is needed for an accelerator to work:

self.Bind(wx.EVT_MENU, self.onExit, id=exitId )

I forgot to bind my menu item, so here's how I would do that:

self.Bind(wx.EVT_MENU, self.onExit, exitMenuItem)

Notice that both the menu item AND the accelerator table are bound to the same event handler, but have different ids. Can you provide a small runnable sample of the code that's giving you fits so the rest of us can take a look?

Oh, pardon! I didn't notice that... and to be honest I didn't try your code because I supposed that was analogous to what I was trying in my earlier tests...
Now I understand that the way is to have any menu bar set in the frame, even if it isn't useful.
Indeed, I reduced the issue to the fact that, if a menu bar is not present in the frame, one MUST set one as follows:

self.SetMenuBar(wx.MenuBar())

And then any created id can be used and bound to any handler by a wx.AcceleratorTable.
The following code works if the line "self.SetMenuBar(wx.MenuBar())" is uncommented:

<code>

import wx

class MyForm(wx.Frame):
     def __init__(self):
         wx.Frame.__init__(self, None, wx.ID_ANY, "wx.Menu Tutorial")

         # Add a panel so it looks the correct on all platforms
         self.panel = wx.Panel(self, wx.ID_ANY)

         self.SetMenuBar(wx.MenuBar())

         exitId = wx.NewId()
         self.Bind(wx.EVT_MENU, self.onExit, id=exitId )
         accel_tbl = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord('Q'), exitId )])
         self.SetAcceleratorTable(accel_tbl)

     def onExit(self, event):
         print 'in onExit'

# Run the program
if __name__ == "__main__":
     app = wx.PySimpleApp()
     frame = MyForm().Show()
     app.MainLoop()

</code>

Anyway, my question remains: Why one _must_ set a menubar in order to make an accelerator table to work ? Maybe the answer is "Because actually an accelerator entry is assumed to be strictly connected to something like a menu item" but I think it should work even without.

Mike

Thanks a lot.

Mike Driscoll wrote:

Hi Diego,

Hi all.

I just noticed that setting an entry in an accelerator table with a custom id (an id that doesn't belong to an existing menu item) doesn't work anymore in wxPython 2.8.8.1 (I tried it with some previous version and it worked):

newId = wx.NewId()
self.Bind(wx.EVT_MENU, self.OnCtrlQ, id=newId)
acct = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord("q"), newId)])
self.SetAcceleratorTable(acct)

self.OnCtrlQ is never called (I tried all possible variations, such as using "Q", executing the code in __init__ or after the creation of all child controls, and so on).

Is that a bug ? If not, is there a solution ?
Thanks in advance, Diego.

I'm getting the exact same behavior unless I actually have a menu instantiated.

Please create a bug report about this. An accelerator table is supposed to work without a menubar.

···

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

Robin Dunn ha scritto:

Mike Driscoll wrote:

Hi Diego,

Hi all.

I just noticed that setting an entry in an accelerator table with a custom id (an id that doesn't belong to an existing menu item) doesn't work anymore in wxPython 2.8.8.1 (I tried it with some previous version and it worked):

newId = wx.NewId()
self.Bind(wx.EVT_MENU, self.OnCtrlQ, id=newId)
acct = wx.AcceleratorTable([(wx.ACCEL_CTRL, ord("q"), newId)])
self.SetAcceleratorTable(acct)

self.OnCtrlQ is never called (I tried all possible variations, such as using "Q", executing the code in __init__ or after the creation of all child controls, and so on).

Is that a bug ? If not, is there a solution ?
Thanks in advance, Diego.

I'm getting the exact same behavior unless I actually have a menu instantiated.

Please create a bug report about this. An accelerator table is supposed to work without a menubar.

I had a look now at the submitted tickets and there's this:

http://trac.wxwidgets.org/ticket/9784