[PyKDE] Some questions

Jim Bublitz jbublitz at nwinternet.com
Thu Oct 26 05:47:36 BST 2006

On Wednesday 25 October 2006 20:46, Reza Salari wrote:

> 3- Another thing that I want to embed is a konsole. It seems that it sould
> be simple to embed konsole from KParts but there is not an example (I know
> there is a KHTM example). There are so many questions about implementing a
> konsole in PyKDE in the net but all with no success in getting a reply.
> Does any one decide to write a sample code? I really need a starting
> point... .I know also C++ but at beginner level and can understand not
> heavy C++ sources. So a useful simple C++ code will be useful too; I found
> some,but finally confused with their cross-references. (better to be in
> python).

Thanks for the nice comments (although all of the PyQt credit goes to Phil).

KDE does provide a konsolepart, however there are some problems with it. For 
some distributions (and between different versions of the same distribution), 
none of the konsolepart library symbols are exported, except the part itself. 
It's supported in the current PyKDE release by default, which will prevent 
some of PyKDE from loading on some systems, so it will be optional in the 
next release.

No symbols exported means you can display and interact with a konsolepart in 
your application, but you can't control it from the program except to the 
extent that's possible from DCOP (which I think most people find isn't 
sufficient for what they'd like to do).

I don't have a simple KParts example, but the fundamental code you need is 
kparts.createReadOnlyPart or kparts.createReadWritePart (in the PyKDE docs in 
the KParts-globals section).

from kparts import KParts, createReadOnlyPart

class MainWindow (KParts.MainWindow):
	def __init__ (parent):
		KParts.MainWindow.__init__ (parent)

		self.part = createReadOnlyPart ("libsomepart", self)
		self.widget = self.part.widget ()

You can then make self.widget the central widget or use it like any other 
widget. If you want the part's menus, you need to build your application 
using KXMLGUI (see the xml menu demo in PyKDE/examples), create a .rc file 
for you portion of the menus and call setXMLfile, and call self.createGUI (in 
you MainWindow class) to merge in the part's menus.

Note that to control most parts (except KHTMLPart) from within your program, 
the only option is DCOP, because there is no Python interface to the API of 
most parts. So it really isn't much different than using QXEmbed most of the 
time. Also, some parts can be buggy - KWord context menus don't work 
correctly, for example, and KSpread will crash on exit unless you set the 
part to read-only before exiting.

I plan to do more work on this, including some examples, for PyKDE 4.


More information about the PyQt mailing list