Register Hotkey on Linux

Hello

I’m trying to run a simple Hotkey Register script on my freshly installed Arch Linux (+openbox). The code must be ok because it works on Windows XP, but it fails miserably on this distro/window manager.

The code is the following:

#! /usr/bin/python
import wx
import sys

class HotkeyFrame(wx.Frame):

def __init__(self):
    wx.Frame.__init__(self, None, -1, "", size = (1, 1),
        style=wx.FRAME_NO_TASKBAR|wx.NO_FULL_REPAINT_ON_RESIZE)

    self.Show(True)

def AddHotkey(self, key, mod, function):
    hotkey_id = wx.NewId()
    self.RegisterHotKey(hotkey_id, mod, key)
    self.Bind(wx.EVT_HOTKEY, function, id=hotkey_id)

def CreateApp():
app = wx.App()
frame = HotkeyFrame()
app.MainLoop()

if name == ‘main’:
print ‘The test hotkey is: ALT + SPACE’
def Test(event=None):
print “Hello!”
CreateApp()
frame.AddHotkey(32, 2, Test)

A tiny frame is created, the “The test hotkey is” message is printed, there are no errors… But nothing happens when I press the key combination.

Where is the problem? Python/wxPython build, script, distro, Openbox or the lack of a proper Desktop Environment?

Hello,

···

On Thu, Feb 12, 2009 at 3:11 PM, Lucas Boppre Niehues lucasboppre@gmail.com wrote:

A tiny frame is created, the “The test hotkey is” message is printed, there are no errors… But nothing happens when I press the key combination.

Where is the problem? Python/wxPython build, script, distro, Openbox or the lack of a proper Desktop Environment?

IIRC RegisterHotKey only works on Windows.

Cody

Oh noes.
Is there anything else to do? Or are the multiples linux’s desktop environments standards too much for python?
Or is there any way to simulate a hotkey? I can set some command - hotkey pairs, but they would re-run the application every time, making it slowish.

Lucas Boppre Niehues wrote:

Oh noes.

Is there anything else to do? Or are the multiples linux's desktop environments standards too much for python?

Or is there any way to *simulate* a hotkey? I can set some command - hotkey pairs, but they would re-run the application every time, making it slowish.

Why not use an Accelerator Table? Just be sure to include a menubar (which can be hidden if you like) as there's a bug in 2.8.9.1 that requires it for the AcceleratorTable to work.

Mike

Will it function globally? It’s for an application launcher, I have to be able to press the keystroke even when watching a full-screen movie with no focus whatsoever over the python application.

···

On Thu, Feb 12, 2009 at 8:25 PM, Mike Driscoll mike@pythonlibrary.org wrote:

Lucas Boppre Niehues wrote:

Oh noes.

Is there anything else to do? Or are the multiples linux’s desktop environments standards too much for python?

Or is there any way to simulate a hotkey? I can set some command - hotkey pairs, but they would re-run the application every time, making it slowish.

Why not use an Accelerator Table? Just be sure to include a menubar (which can be hidden if you like) as there’s a bug in 2.8.9.1 that requires it for the AcceleratorTable to work.

Mike


wxpython-users mailing list

wxpython-users@lists.wxwidgets.org

http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Hello,

Lucas Boppre Niehues wrote:

Oh noes.

Is there anything else to do? Or are the multiples linux’s desktop environments standards too much for python?

Or is there any way to simulate a hotkey? I can set some command - hotkey pairs, but they would re-run the application every time, making it slowish.

To avoid this it would probably require some sort of ipc. This is really up to communication between the desktop environment and apps that are running in it. Is there a standard api that is used for hotkeys on a linux desktop (or for your target environment)?

Its difficult for any toolkit to provide this type of functionality (when there is no set standard), for example in most cases wx only knows what gui toolkit it is built with. On linux this is (usually) gtk, it does not know what desktop environment it is running under, could be gnome, kde, xcfe, ect… If each one of them has their own standard for hotkeys then how is wx supposed to know which one to listen for?

One possiblilty (if there is no standard api for you to implement) is that you could create some small fast starting launcher app that you set the “command hotkey” to, then this app will only start your main app the first time it runs. Other times it will just send some command to your other main app to perform.

Why not use an Accelerator Table? Just be sure to include a menubar (which can be hidden if you like) as there’s a bug in 2.8.9.1 that requires it for the AcceleratorTable to work.
RegisterHotKey is a little different than using an AcceleratorTable. It creates a system level hotkey that will send an event to the app even if it doesn’t have the focus. An AcceleratorTable only works when the window/app is active.

···

On Thu, Feb 12, 2009 at 4:25 PM, Mike Driscoll mike@pythonlibrary.org wrote:

Lucas Boppre Niehues wrote:

Oh noes.

Is there anything else to do? Or are the multiples linux's desktop environments standards too much for python?

AFAIK each of the different linux desktops handle global hotkeys differently. One day there may be a freedesktop.org standard for it and wx could implement something for that.

···

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

Ok, I think I found the solution:

  • Start the tray bar application
  • Use it to listen to a port
  • Set a hotkey to open a simple python script
  • Make that script send a simple message through the port

And thanks for the answers people.

I am surprised nobody hasn't made a cross platform library for this
already that wraps xlib and others.

···

On Sat, Feb 14, 2009 at 1:14 PM, Lucas Boppre Niehues <lucasboppre@gmail.com> wrote:

Ok, I think I found the solution:

- Start the tray bar application
- Use it to listen to a port
- Set a hotkey to open a simple python script
- Make that script send a simple message through the port

And thanks for the answers people.

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

--
Thanks, Richie Ward