[PyQt] PyKDE: problems sending singals to KPART

Thomas Winkler tc at tomwinkler.net
Wed Jun 4 13:36:37 BST 2008


Dear List,

I'm working on integrating hte KPDF KPart int my PyKDE application. What I 
would like to do is to emit a signal to the "slotNextPage()" slot of the kpdf 
part (see: 
http://websvn.kde.org/branches/KDE/3.5/kdegraphics/kpdf/part.h?view=markup ).

A stripped down version of my code loos like this:


######################################

from qt import *
from kdecore import KCmdLineArgs, KURL, KApplication, KLibLoader, KShortcut
from kdeui import KMainWindow, KMessageBox, KAction, KStdAction, KKeyDialog
from kparts import KParts, createReadOnlyPart, createReadWritePart
import sys, os

FALSE = 0
TRUE  = not FALSE

class pyPartsMW (KParts.MainWindow):
 	def __init__ (self, *args):
		apply (KParts.MainWindow.__init__, (self,) + args)
		self.setGeometry (0, 0, 600, 500)
		self.part = createReadOnlyPart("libkpdfpart", 
self, "test", "KParts::ReadOnlyPart")
		self.setCentralWidget(self.part.widget())
	
		# TODO: point to valid PDF file
		self.part.openURL(KURL('file:///home/tom/test.pdf'))
		self.connect(self, PYSIGNAL("sigNextSlide"), self.part, 
SLOT("slotNextSlide()"))
		self.emit(PYSIGNAL("sigNextSlide"), ())



def main():
	app = KApplication(sys.argv, "TestApp")
	win = pyPartsMW (None, "partBeamer")
	win.show()
	app.exec_loop()
	

if __name__ == '__main__':
	main()

######################################


So embedding the kpdf kpart works and I can load a pdf file.
But the code fails on the self.emit statement with the following message:

[...]
  File "min.py", line 20, in __init__
    self.emit(PYSIGNAL("sigNextSlide"), ())
NameError: Invalid slot slotNextSlide

I'm note sure what I'm doing wrong here. I tried with and without "()" after 
slotNextPage but without success. From the part.h file referenced above one 
can see that the slotNextPage method is protected. Might this be the problem?
On the other hand, the openURL() method is also declared protected and I have 
no problems calling that one.

One more note: I managed to call the slotNextSlide() method using KDCOP. Would 
using dcop from withtin pykde be an option?

I'd be happy if someone could help me with this one. What I basically want to 
do is to embed kpdf-part in a pykde application and all methods (slots) 
provided by kpdf-part (especailyl controlling slides, switching to 
presentation mode etc). I'd prefer using direct method calls or signals. A 
DCOP based solution would also be OK.

Thank you very much,
-- 
Thomas Winkler
tc at tomwinkler.net


More information about the PyQt mailing list