Creating KDE4 apps with Python

Creating the Python KDE4 application id3encodingconverter makes me dive into PyKDE programming again after the first version of EncodingConverter EncodingConverter a KDE Amarok plugin with PyKDE 3. But it's the first time getting that deep into the world of Qt, KDE, PyKDE and it takes some time to solve all the issued that come up.

I'll just list a few of them and hope this might help others having the same problems.

  • PyKDE4 seems to still have some issues, like menus not showing up or the ui compiler doing wrong translations of imports. Overall it does work, but it's worthwile scanning the mailing list for issues brought up by people, as the whole project was just released a few weeks ago.
  • from the Python distutils module will install your application. It's important though to tell the script where to place files. Here's a short excerpt of my script, it took me a few minutes to get all the settings needed for the different files

    We have to get the target directories for KDE4 data files. This uses kde4-config to query the local system's default directories. Not too nice, as we generate absolute directories here. For Debian packaging I still need to adapt this.

    # get target directories for kde4 files
    kde4DataTarget = os.popen("kde4-config --expandvars --install data")\
    kde4DesktopTarget = os.popen("kde4-config --expandvars --install apps")\

    To distribute the different files I added this to the setup method:

        # UI files generated by pykdeuic4 and other private libraries
        py_modules=['encoding', 'ngram', 'ID3EncodingConverterUI',
        # main application
        # ui.rc, .desktop and documentation files
        data_files=[(os.path.join(kde4DataTarget, 'id3encodingconverter'),
            (os.path.join(kde4DesktopTarget, 'id3encodingconverter'),
            ('share/doc/id3encodingconverter/', ['TODO'])],)

  • .desktop file: If you want to have a menu entry in KDE or other window managers you need to create a .desktop file. Some information can be found under and desktop-file-validate can scan your file and check if everything is ok.
  • Packaging your application seems worthwhile as many users won't take the time to go solve all problems that arise by installing from a source package without dependency handling. For me it took quite some time as I described in Debian package for id3encodingconverter but every major distribution should provide help how to process KDE and Python apps.

Still waiting for more issued to learn. Stay tuned.