commit 4e264121d992054a05d04afb397ee0ee3d3199df Author: Lukas Winkler Date: Sun May 31 12:53:55 2020 +0200 first working version diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..485dee6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..12129c4 --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ +install-config: + mkdir -p ~/.local/share/kservices5/ + rm ~/.local/share/kservices5/plasma-runner-astroacro.desktop + kquitapp5 krunner; kstart5 krunner + cp plasma-runner-astroacro.desktop ~/.local/share/kservices5/ + kquitapp5 krunner; kstart5 krunner + +create-autostart: + # Configure the path in the .desktop file first + mkdir -p ~/.config/autostart/ + cp astroacro_autostart.desktop ~/.config/autostart/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..4bde45e --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +### Simple Krunner dbus template + +This plugin provides a simple template for a Krunner plugin using dbus. + +To run this plugin you have to execute the `make install-config` command. +This installs the .desktop file so that your runner gets recognized. +Secondly you have to run your script. Because Krunner queries the dbus +interface and does not load a plugin you can use for example a debugger. + +More information can be found here: +https://cgit.kde.org/krunner.git/plain/src/data/org.kde.krunner1.xml +https://techbase.kde.org/Development/Tutorials/D-Bus/Introduction + +On Debian/Ubuntu you need: +`sudo apt install python3 python3-hglib` \ No newline at end of file diff --git a/astroacro.desktop b/astroacro.desktop new file mode 100644 index 0000000..0840196 --- /dev/null +++ b/astroacro.desktop @@ -0,0 +1,10 @@ +[Desktop Entry] +Version=1.0 +Type=Application +Name=Runner +Comment=Autostart entry for a Krunner plugin +Keywords=Runner;Krunner +Categories=Utilities +Exec=python3 "%{Folder_LOCATION}/astroacro.py" +Icon=python +StartupNotify=true diff --git a/astroacro.py b/astroacro.py new file mode 100644 index 0000000..235a866 --- /dev/null +++ b/astroacro.py @@ -0,0 +1,58 @@ +#!/bin/env python3 +import webbrowser + +import dbus.service +import requests +from dbus.mainloop.glib import DBusGMainLoop +from gi.repository import GLib + +DBusGMainLoop(set_as_default=True) + +objpath = "/astroacro" + +iface = "org.kde.krunner1" + +s = requests.Session() + + +class Runner(dbus.service.Object): + def __init__(self): + dbus.service.Object.__init__(self, dbus.service.BusName("net.astroacro", dbus.SessionBus()), objpath) + + @dbus.service.method(iface, in_signature='s', out_signature='a(sssida{sv})') + def Match(self, query: str): + """This method is used to get the matches and it returns a list of lists/tupels""" + if " " in query: + return [] + + runners = [] + r = s.get("http://127.0.0.1:8000/api/acronym/", params={"search": query}) + icon = "internet-web-browser" + type = 100 # (Plasma::QueryType) + relevance = 1.0 # 0-1 + + for result in r.json(): + data = result["slug"] + display_text = result["name"] + ": " + result["full_name"] + properties = { + "subtext": ", ".join(result["tags"]), + # "category": "", + # "urls": "" + } + runners.append((data, display_text, icon, type, relevance, properties)) + return runners + + # @dbus.service.method(iface, out_signature='a(sss)') + # def Actions(self): + # # id, text, icon + # return [("id", "Tooltip", "planetkde")] + + @dbus.service.method(iface, in_signature='ss') + def Run(self, data: str, action_id: str): + print(data, action_id) + webbrowser.open("http://127.0.0.1:8000/acro/" + data) + + +runner = Runner() +loop = GLib.MainLoop() +loop.run() diff --git a/plasma-runner-astroacro.desktop b/plasma-runner-astroacro.desktop new file mode 100644 index 0000000..f166576 --- /dev/null +++ b/plasma-runner-astroacro.desktop @@ -0,0 +1,15 @@ +[Desktop Entry] +Name=astroacro +Comment=Look up astronomical Acronyms +X-KDE-ServiceTypes=Plasma/Runner +Type=Service +Icon=accessories-dictionary +X-KDE-PluginInfo-Author=Lukas Winkler +X-KDE-PluginInfo-Email=kde@lw1.at +X-KDE-PluginInfo-Name=astroacro +X-KDE-PluginInfo-Version=1.0 +X-KDE-PluginInfo-License=LGPL +X-KDE-PluginInfo-EnabledByDefault=true +X-Plasma-API=DBus +X-Plasma-DBusRunner-Service=net.astroacro +X-Plasma-DBusRunner-Path=/astroacro