[PyQt] [PyKDE4] Default value for the second argument of KAction.setShortcut() does not seem to work

Jim Bublitz jbublitz at nwinternet.com
Sat Jan 12 18:21:39 GMT 2008


On Saturday 12 January 2008 02:40, Simon Edwards wrote:
> Hi,
>
> Adeodato Simó wrote:
> > This one time, I'm finding that KAction.setShortcut() can't work in
> > Python without passing a value for the second argument, whereas this
> > works in C++. Any chance you'd know why? Thanks.
>
> Looks like a bug in PyKDE4. The second arg doesn't have a default value
> like in the C++ version. I'll try to get this fixed in 4.0.1.

It's a feature :)

More accurately it's a feature in presip that won't handle the typesafe 
enumerator expression that's the default value.  You can try adding it 
manually for both setShortcut methods in kaction.sip. Not sure if sip will 
handle it, but I think it will.

The current behavior for Python is covered in the docs (no default value is 
shown). It should be covered in the 'Getting Started' tutorial too, but it 
looks like I didn't finish writing the last section of that.

> > This:
> >
> > -8<-
> > #! /usr/bin/env python
> >
> > from PyKDE4 import kdeui
> >
> > action = kdeui.KAction(None)
> > action.setShortcut(kdeui.KShortcut('Ctrl+F'))
>
> Add the second arg like this (and close your eyes):
>
> action.setShortcut(kdeui.KShortcut('Ctrl+F'),
>    kdeui.KAction.ShortcutTypes( \
>      kdeui.KAction.ShortcutTypes(kdeui.KAction.ActiveShortcut) | \
>      kdeui.KAction.ShortcutTypes(kdeui.KAction.DefaultShortcut)))
>
> This fix will work in the future and has the same effect as the fixed
> version.
>
> mmm... it would be nice if PyQt4's QFlags() accepted a uint mask in its
> constructor. If would save a lot of ugly Python code, for the price of a
> little bit of runtime type safety...

You can save some verbosity by doing

from PyKDE4.kdeui import KAction

and then define some constant

default = KAction.ShortcutTypes   
    (KAction.ShortcutTypes(KAction.ActiveShortcut) \
    |    .KAction.ShortcutTypes.KAction.DefaultShortcut))

and use that in the method call.

At the moment I don't think there's any way to get around the type safety 
stuff. KDE4 expects a class object for the second argument.

-------------------

I should get together an update for you (Simon) - I've been tied up on a lot 
of other stuff the last few months and haven't made much progress. The new 
code generator is about 85% complete. I believe it handles the problem above, 
but it needs about another month or so to complete, and it looks like a few 
more weeks before I can get back to working on it.

Jim



More information about the PyQt mailing list