Python plugin user guide

KDE 4.9 has branched, and so the Pâté plugin ”host” for Python plugins has moved from Kate’s playground to be a mainstream plugin. Since a plugin-for-plugins might be a bit confusing, here is a quick tour of how it is managed and works, and especially a few rough edges it still has.

NOTE If you’ve installed this from a package, hopefully your distro will have added kate.so under PyKDE4 as needed, but if you are building from source, see the notes at the end of this post.

Start by enabling the enabling the Pâté plugin:

That should cause the Pâté plugin’s configuration page to pop into existence, but you may need to press the Reload button to see the right hand pane filled in like this:

Enable specific Python plugins of interest, and press the Reload button. The comment will be set to “Loaded”, then close and reopen the dialog (rough edge #1) to see any new configuration pages that the plugin provides:

Go back to the Pâté plugin’s configuration page, and now look at the second tab:

Use the combo box to select one of the built-in support modules (kate and kate.gui) or any of the loaded plugins. The first tab shows HTML documentation for the Python code and you can see any actions it has added into the Kate UI on the second tab (this will be empty for the built-in modules, but not for console):

It looks as though the Python console has added one entry to the View menu, alog with a shortcut. And so it has:

Yaay! See if you can guess what to do next :-)

 

IF YOU HAVE BUILT FROM SOURCE

And then installed the results in say /usr/local, attempting to enable the plugin may result in a crash with something this on the terminal:

>  File "/home/.../kate/plugins/pate/kate/__init__.py", line 38, in <module> from PyKDE4.kate import Kate
> No module named kate
> Could not import kate"

This is because the Pate build should install kate.so as part of the PyKDE4 bindings, but typically, a developer build will install this locally, and not to where the remaining system-supplied PyKDE4 files are installed:

Install the project...
 -- Install configuration: "RelWithDebInfo"
 -- Up-to-date: /usr/local/lib/python2.7/dist-packages/PyKDE4/kate.so
 ...

The system-supplied PyKDE4 binding modules should be in Python’s sys.path:

srhaque> python
 Python 2.7.3 (default, Apr 20 2012, 22:39:59)
 [GCC 4.6.3] on linux2
 Type "help", "copyright", "credits" or "license" for more information.
 >>> import sys
 >>> print sys.path
 ['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-linux2', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PIL', '/usr/lib/python2.7/dist-packages/gst-0.10', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/pymodules/python2.7']

For me, Ubuntu puts PyKDE4 at /usr/lib/python2.7/dist-packages/PyKDE4, so we need a link from there to the actual location:

srhaque> ls -l /usr/lib/python2.7/dist-packages/PyKDE4/kate.so
lrwxrwxrwx 1 root root 53 May 20 09:51 /usr/lib/python2.7/dist-packages/PyKDE4/kate.so -> /usr/local/lib/python2.7/dist-packages/PyKDE4/kate.so

Note that just having this location in PYTHONPATH and/or in sys.path does not work because the PyKDE4 needs an __init__.py to be seen (see the one in the system directory to understand why).

I’ve not thought of a good way to simplify this for developers, and I assume end-users won’t see it because we’ll install in the default path. Suggestions/fixes welcome.

 

10 thoughts on “Python plugin user guide”

    1. Good question.

      I’m not sure how best to handle this…I certainly was not planning to do a “bulk” import without knowing good/useful from bad/useless. Also, there is the question of ownership/forking. OTOH, maybe pypi is a good place to keep such stuff anyway? At least they seem to have some notion of packaging (not to mention Python expertise).

  1. Thanks for the plugin :-) But anyway, look at the other plugin names in your screenshot. To name some: Build Plugin, Backtrace Browser, Mail files… Quite descriptive, aren’t they? And how should I find Python Plugin (sorry, Pâté plugin) in this list without reading the descriptions (or your blog)? I thought that the time of mis-naming applications in KDE has gone and it apparently hasn’t. Also the name of this blog entry is (correctly) “Python plugin user guide”… I’m not saying this is an ugly name (it might be perfect for a local brand, possibly), but completely undiscoverable, so it is a bad name.

    1. Thanks for the feedback, but I’m not clear on what you are saying. The short name is “Python Plugins”, and the long name is “Pate host for Python plugins” – that seems clear to me. What do you suggest would work better?

      1. I’m saying that the screenshot showing the “Plugin Manager” screenshot shows “Pâté” in the Name column and “Python Plugins” in the Comment column. This is what I meant that is wrong – it should say “Python Plugins” in the Name column and “Pâté host for Python plugins” in the Comment.

  2. I try to install the pluging but i have this error when i start kate :
    RuntimeError: the sip module has already registered a module called PyKDE4.kate
    Could not import the kate module. Dieing.
    Traceback (most recent call last):
    File “/home/openerp/.kde/share/apps/kate/pate/kate_core_plugins.py”, line 17, in
    import kate
    RuntimeError: the sip module has already registered a module called PyKDE4.kate
    Could not load plugin kate_core_plugins
    Traceback (most recent call last):
    File “/home/openerp/.kde/share/apps/kate/pate/kate_plugins/kate_plugins.py”, line 17, in
    from jste_plugins.autocomplete import *
    File “/home/openerp/.kde/share/apps/kate/pate/kate_plugins/jste_plugins/autocomplete.py”, line 17, in
    import kate
    RuntimeError: the sip module has already registered a module called PyKDE4.kate
    Could not load plugin kate_plugins
    Traceback (most recent call last):
    File “/home/openerp/.kde/share/apps/kate/pate/kate_plugins/kate_plugins.py”, line 17, in
    from jste_plugins.autocomplete import *
    File “/home/openerp/.kde/share/apps/kate/pate/kate_plugins/jste_plugins/autocomplete.py”, line 17, in
    import kate
    RuntimeError: the sip module has already registered a module called PyKDE4.kate
    Could not load plugin kate_plugins
    Traceback (most recent call last):
    File “/home/openerp/.kde/share/apps/kate/pate/kate_plugins/kate_settings_plugins.py”, line 17, in
    from kate_core_plugins import create_mainmenu, create_submenu, separated_menu
    File “/home/openerp/.kde/share/apps/kate/pate/kate_plugins/kate_core_plugins.py”, line 17, in
    import kate
    RuntimeError: the sip module has already registered a module called PyKDE4.kate
    Could not load plugin kate_settings_plugins

    Can you help me ?

  3. I am confused by the output you have pasted above. What version of Kate are you using? Would I be right in thinking that you have built the old, unmaintained version of Pate from github, and then tried to run the plugins also on github?

  4. The plugins are great, but why when I open (KDE 4.10.5) in “Settings” -> “Configure Kate…” the window that appears is so small? And it cannot remember its size after closing. Although that window is not opened frequently, it is frustrating.

  5. Some good work on that dialog was done recently. Since you apparently don’t see the benefit of that in your version, I guess it is coming in 4.11.

Leave a Reply