[PyKDE] KTrader woes?

Jim Bublitz jbublitz at nwinternet.com
Fri Oct 31 22:37:01 GMT 2003


On Friday October 31 2003 09:55, Paul Evans wrote:
> Sundance sundance_at_ierne.eu.org:
> >Well, more precisely, it works if I copy the
> > KCmdLineArgs.init line from mimetype.py. If I call
> > KApplication([], "SomeName") it dies. Apparently
> > KApplication REQUIRES a non-empty list as its first
> > argument, unlike QApplication (with which the [] trick
> > works).

> sorry if this has been fixed in newer versions than the 3.7-3
> version - I haven't been able to follow some of the discussion
> on the topic (c++).

> I recently had to change one program from QApplication to
> KApplication to support a kde widget and found that not only
> does it require a non-empty list as Sundance noted, but there
> can only be One element in that list or it will fail on
> 'Unexpected argument '. Of course, the program still works
> fine when its main class is instantiated from another script
> with args.

> I got around it by passing [sys.argv[0]] to KApplication when
> run stand-alone. This way it starts fine and the main class
> can pick off the args it needs. However, the kde crash handler
> kicks in when the program exits now.

> Sorry if this is fixed, I can certainly handle it for the time
> being until I upgrade. If not, can you suggest a proper cure
> over my work around?

The following works fine for me on PyKDE-3.8 which isn't released 
yet, but the change has been in place for a while. 

8< --------------------------

import sys

from kdecore import KApplication
from kdeui import KMainWindow

class MainWin (KMainWindow):
    def __init__ (self, *args):
        apply (KMainWindow.__init__, (self,) + args)


#----- main --------
appName = "template"
app = KApplication (sys.argv, appName)
mainWindow = MainWin (None, "main window")
mainWindow.show()
app.exec_loop()

8< --------------------------

I don't have a copy of 3.7-3 handy at the moment so I can't check 
it. The modified code is in kapplication.sip - the relevant 
section of member code should have the "real" constructor call 
commented out as shown:

KApplication (int&, char**, const QCString&, bool = 1, bool = 1);
%MemberCode

        ...

        Py_BEGIN_ALLOW_THREADS

        // The following two lines simulate the actual ctor call
        // which is commented out below
        KCmdLineArgs::init (nargc, argv, a0, "unknown", 
                                      "KDE  Application", false);

        sipNew = new sipKApplication((bool)a1,(bool)a2);

// This method calls KCmdLineArgs::initIgnore, which is a private 
// method
//   ==> sipNew = new KApplication (nargc,argv, qc, a1, a2);  <==

        Py_END_ALLOW_THREADS

    ...

It's possible this code won't work with an empty list or 
len(list) > 1 - I'll have to check that out. At any rate, all it 
does is duplicate the KCmdLineArgs.init stuff in C++, since the 
actual constructor can't be wrapped via sip (due to the private 
method call).

Otherwise, this should always work (obviously you want to edit it 
a little):

8< ----------------------

description = "A basic application template"
version     = "1.0"
aboutData   = KAboutData ("", "",\
    version, description, KAboutData.License_GPL,\
    "(C) 2003 whoever the author is")

# you can probably omit these if you don't need them
aboutData.addAuthor ("author1", "whatever they did",\ 
"email at somedomain")
aboutData.addAuthor ("author2", "they did something else",\ 
"another at email.address")

KCmdLineArgs.init (sys.argv, aboutData)

# this isn't necessary either (?)
KCmdLineArgs.addCmdLineOptions ([("+files", "File to open")])

app = KApplication ()
mainWindow = MainWin (None, "main window")
mainWindow.show()
app.exec_loop()

8< --------------------------

If you're getting a segfault at exit, there may be a different 
issue causing it - I'm not really sure without doing some 
testing. I'll check it out before the next release (which should 
be any day now).

Jim




More information about the PyQt mailing list