Skip to main content

KRunner in Python (II)

Digging into the way that kde handles services, I've found that this code emulates its behaviour:

from PyQt4 import QtGui
from PyKDE4.kdecore import KServiceTypeTrader

QtGui.QApplication([])

constraint = "[X-Plasma-API] == '%s' and '%s' in [X-Plasma-ComponentTypes]"
KServiceTypeTrader.self().query("Plasma/ScriptEngine", constraint % ("python", "Runner"))
# -> []

KServiceTypeTrader.self().query("Plasma/ScriptEngine", constraint % ("python", "Applet"))
# -> [<PyKDE4.kdecore.KService object at 0xb75bee6c>]

KServiceTypeTrader.self().query("Plasma/ScriptEngine", constraint % ("python", "DataEngine"))
# -> [<pykde4.kdecore.kservice 0xb75befac="" at="" object="">]

Conclusion: There is no Python script engine for runners but there is for applets and data engines.

:(

To be continued (again)...

Comments

Popular posts from this blog

KRunner in Python (I)

This is my first post, so I don't really know how to start... [DONE]. My goal is to improve the usability of the time tracking software included in KDE: KTimeTracker , just because I don't want to spend time to track it. I'll try to expose the whole (good! It'll mean that I found a solution!) of the process I am following to get a working KDE Runner written in Python . KDE4 (actually Plasma) brings a very useful tool called KRunner . It's a launcher that can be customized with our own actions. The plugins that implements this functionality are Runners. So, after looking for a tutorial or example, I found the tutorials page for Plasma and, starting from the generic plasmoid tutorial , I developed a first version that looks like: # -*- coding: utf-8 -*- from PyKDE4.plasma import Plasma import sys sys.path.append('/usr/share/kde4/apps/plasma_scriptengine_python') import plasma_importer class PythonRunner(Plasma.RunnerScript): importer = None ...

KRunner in Python (and IV)

To make this very simple example working, I've had to modify the pyrunner.py file that I checked out in the last post . I don't know if this changes will be necessary in newer KDE versions (mine is 4.3.4), but by now this patch can be used. And here is a final working example: from PyKDE4 import plasmascript from PyKDE4.plasma import Plasma class EchoRunner(plasmascript.Runner): def match(self, search): if not search.isValid(): return term = search.query() if term.length I think it is self explainable, but you can leave any question in the comments. You can also download the full example structure ready to install from here .