[PyKDE] KDE XML GUI ActionLists

Jim Bublitz jbublitz at nwinternet.com
Wed Apr 23 06:35:01 BST 2003


Problem solved.

Change your KMainWindow to KParts.MainWindow and be sure to do this:

class MainWindow (KParts.MainWindow):
    def __init__ ( ... ):
        KParts.MainWindow (self, ...) <---- !!!!

I have a comment in a KParts based example that I was hacking on to
remember to change the KMainWindow ctor call to a KParts.MainWindow
call when changing the MainWindow type, and I still screwed it up
when I went back to original program I was trying to get to work. I
even went as far as modifying the PyKDE C++ code (and still crashed)
before figuring out I'd made the same dumb mistake again. Last time
I probably spent a day chasing it down, so I guess I'm improving.

All your other code (including the 'None') is correct - it's
exactly the way konqueror and other apps do it.

In addition, instead of specifying the XML file in createGUI, do

    self.setXMLFile (<path to file>)

and then

    self.createGUI (None)

(createGUI is overloaded to "void createGUI (KParts.Part *part)" )

Call the code that updates the action list actions after createGUI.
Those should be the only changes you need to make. KParts.MainWindow
is a subclass of KMainWindow, so nothing else needs to change.

Pretty cool for stuff like 'recent files' lists or modifying menus
on the fly. Thanks for bringing it up - I'll add an example to
PyKDE in the future.

It'd be nice if the KDE docs were more explicit about this - the
link you provided specifically says:

"KDE's class for toplevel windows, ***KMainWindow***, inherits
KXMLGUIClient and therefore supports XMLGUI out of the box."

which misled me at first.

All of the C++ action list examples I've looked at (mostly from
2.1.1 and KOffice) all use KParts.MainWindow too, but they all
import KParts too.


Jim




More information about the PyQt mailing list