PyKDE Programming/KDE Extras

DCOP

edit

KParts

edit

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()
w.resize(500,300)
w.show()
sys.exit(app.exec_())

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.