jbublitz at nwinternet.com
Mon May 15 23:22:35 BST 2006
On Monday 15 May 2006 02:12, Michał Woźniak wrote:
> Hi there,
> I am trying to get my script to register a global hotkey (or "accel" key,
> should I rather say) under KDE 3.4.3. I am using KGlobalAccel, but without
> any success.
> All that I have achieved so far is either:
> - freezing the app (and the keyboard, globally!) after I hit the accel key;
> - crashing the app when I hit the accel key;
> - or some other similar nice behaviour.
> (the code provided below)
> I must point out, though, that I am quite new to Python, and a total noob
> to programming GUI apps in it.
> Any help/pointers appreciated.
> The code I use is:
> import sys
> import time
> from kdecore import *
> from qt import *
> from kdeui import KMainWindow
> # the tester
> def tester():
> print '=== TESTER === TESTER === TESTER ==='
> class MainWin (KMainWindow):
> def __init__ (self, *args):
> apply (KMainWindow.__init__, (self,) + args)
> # create the hotkey object
> print 'start'
> shortcut = KShortcut('F11')
> if shortcut == None:
> print 'no, sir!'
> print shortcut.toString()
> accelObject = KGlobalAccel(self)
> accelObject.insert("Tester", "Tester AccelKey", "A tester accel key",
> shortcut, shortcut, tester)
> appName = "tester"
> app = KApplication (sys.argv, appName)
> mainWindow = MainWin (None, "main window")
> Send instant messages to your online friends http://uk.messenger.yahoo.com
shortcut is being deleted when you exit the __init__ function - it needs to be
self.shortcut. accelObject should be a QObject with a parent holding a
pointer to it (there's an error in the kglobalaccel.sip file, but it doesn't
change anything yet) - if you make accelObject persistent (self.accelObject),
then instead of locking up the keyboard, the program will segfault in
KGlobalaccelPrivate::activate() when you press the accel key. That's progress
I guess :(
The ctor for KGlobalAccel in sip/kglobalaccel.sip should look like:
KGlobalAccel (QObject*/Transfer/, const char* = 0);
(the /Transfer/ is missing), but that doesn't fix the problem or even change
the results (you also need to run configure.py and recompile if you make that
I'll have to play with is somemore and see what I can figure out. You might
try a C++ version and see if that works.
More information about the PyQt