PyKDE Programming/KDE Extras

From Wikibooks, open books for an open world
Jump to navigation Jump to search

DCOP[edit | edit source]

KParts[edit | edit source]

A mimimal example of an application using the Kate KPart (Katepart):

import sys
from PyKDE4.kdecore import KLibLoader
from PyKDE4.kparts import KParts
from PyQt4.QtGui import QApplication

app = QApplication(sys.argv)
factory = KLibLoader.self().factory("katepart")
part = factory.create(None, "PartOfKate")
w = part.widget()

The script does the following:

  1. After importing everything needed, it creates a QApplication (Note that no KApplication is needed for using a KPart).
  2. A factory is created from the library “katepart”. A factory is a class which generates objects from a library.
  3. The factory is used to create an instance, a Katepart-object with no parent and the name “PartOfKate”. You can use any name here.
  4. The widget of the Katepart is resized (It looks better) and shown.
  5. The main loop of the Application is started.