[PyKDE] KDE XML GUI ActionLists

Jim Bublitz jbublitz at nwinternet.com
Tue Apr 22 07:04:01 BST 2003


On 22-Apr-03 Gordon Tyler wrote:
> Continuing from my experiments with KDE's XML GUI stuff and popup
> menu's, I'm 
> now trying to get ActionLists to work, but with no success.
 
> In the attached ui.rc file, I have an ActionList defined in the
> "Open With..." 
> submenu of File menu and in a popup menu. In the script, I'm
> attempting to 
> update the contents of the ActionList with the following code
> (reformatted 
> for email):
 
>     def updateOpenWithActions(self, selectedFileItems):
>         print "updateOpenWithActions"
>         self.unplugActionList("file_open_with_list")
>         self.openWithActions = []
>         if len(selectedFileItems) == 1:
>             fileItem = selectedFileItems[0]
>             offers =
> KServiceTypeProfile.offers(fileItem.mimetype(), \
>                     "Application")
>             offers.sort(lambda x,y: cmp(x.preference(),
> y.preference()))
>             for offer in offers:
>                 service = offer.service()
>                 print "updateOpenWithActions: service=%s,
> preference=%d" % \
>                         (str(service.name()), offer.preference())
>                 action = KAction(service.name(), KShortcut(), \
>                         self.fileOpenWith, None,
> "file_open_with_" + \
>                         str(service.desktopEntryName()))
>                 self.openWithActions.append(action)
>         self.plugActionList("file_open_with_list",
> self.openWithActions)
 
> I've verified that the KActions are being created and added to
> the self.openWithActions list. However, when I run the
> scriptand open either of the menus that contain the ActionList,
> there are no items. No errors, just an  empty menu.
 
> Has anybody else used ActionLists in PyKDE?

I haven't gotten as far as writing a unit test for this (it's in
KXMLGUIFactory, and I'm going alphabetically), but it's probably an
error in the KActionList mapped type. It's an easy one, so I'll do
it next and let you know - at the moment it looks incorrect to me.
Probably should have an answer in an hour or so.

I'm not sure if this fits your application, but KMainWindow owns a
KActionCollection, so assuming the above is a KMainWindow method,
you could replace the 'None' with 'self.actionCollection ()' and
then change the call to:

    self.plugActionList (<string>, self.actions ())

HOWEVER, there is a bug in the mapped type for KActionPtrList as
well, so that won't work right now either. If you want to try it,
in kaction.sip:

%Mapped Type KActionPtrList
   ...
%ConvertFromTypeCode
   ...

line 1007:

change:

    if (((inst = sipNewCppToSelf (new KAction (*it),
          sipClass_KAction, SIP_SIMPLE | SIP_PY_OWNED)) == NULL)

to:

    if (((inst = sipMapCppToSelf (*it, sipClass_KAction)) ==
        NULL)

(they're both a single line in the kaction.sip file).

If you don't want to use KMainWindows KActionCollection, you could
instantiate your own, but in that case the list is less overhead
than the KActionCollection object (but a few extra lines of code).

Sorry for the bugs - I'm killing 'em as fast as I can.


Jim




More information about the PyQt mailing list