I'm struggling with generating key press events in a program that I'd
like to interface with a remote.
Here's the synopsis pylirc is a package that ties python and lirc
together and it works very well from a more or less linear script
perspective however it presents a challenge when moving to an event
driven GUI system. This being that pylirc doesn't generate events it
needs to be polled which I plan to adapt code from http://wiki.wxpython.org/LongRunningTasks to take care of the polling
portion but the real problem I'm running into is how to translate the
return from the remote into an event that the GUI can act on. So for
example I have a list box that I'd like to be able to scroll up and
down with the remote. Pylirc will return 'up' and 'down' from the
navigation keys on the remote I'll pass this into the GUI thread using
a custom event the handler then in the gui thread needs to generate a
new event passing WXK_UP or WXK_DOWN.
I've looked at using :e = wx.CommandEvent(wx.EVT_KEY_DOWN.evtType[0],
self.GetId() )
but this doesn't expose a method for e.setkeycode
I'm sure I'm probably missing something but I've just never had much
luck getting my head wrapped around this custom event stuff, so any
help would be greatly appreciated.
First of all, key-down events do not send wx.CommandEvent objects, but wx.KeyEvents.
But most importantly, wx is not designed to allow what you are trying to do to work as you are expecting it to. When a native message/event arrives from the system wx takes info from it to construct a wx event object and then sends it to the appropriate wx windows. If there are no matching event bindings (or the handler(s) call Skip) then wx simply tells the original native system message that it was not processed. There is no code that can go the other way. In other words, something that will take a wx.Event that did not originate from the system and then translate it to a native system message/event and send it as if it originated from the user or some system action in such a way that it will fool the native widgets.
However there is some good news. In 2.9.2 we will have the wx.UIActionSimulator class that *does* cause the native mouse and keyboard events to be sent in a way that the native (and wx) widgets are able to process them as if they were real events. Last I played with it there were still some rough edges on the other platforms but it works well on Windows.
I'm struggling with generating key press events in a program that I'd
like to interface with a remote.
Here's the synopsis pylirc is a package that ties python and lirc
together and it works very well from a more or less linear script
perspective however it presents a challenge when moving to an event
driven GUI system. This being that pylirc doesn't generate events it
needs to be polled which I plan to adapt code from LongRunningTasks - wxPyWiki to take care of the polling
portion but the real problem I'm running into is how to translate the
return from the remote into an event that the GUI can act on. So for
example I have a list box that I'd like to be able to scroll up and
down with the remote. Pylirc will return 'up' and 'down' from the
navigation keys on the remote I'll pass this into the GUI thread using
a custom event the handler then in the gui thread needs to generate a
new event passing WXK_UP or WXK_DOWN.
I've looked at using :e = wx.CommandEvent(wx.EVT_KEY_DOWN.evtType[0],
self.GetId() )
but this doesn't expose a method for e.setkeycode
I'm sure I'm probably missing something but I've just never had much
luck getting my head wrapped around this custom event stuff, so any
help would be greatly appreciated.