mirror of
https://github.com/Findus23/acronomy-krunner.git
synced 2024-09-08 00:03:45 +02:00
first working version
This commit is contained in:
commit
4e264121d9
6 changed files with 110 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
.idea
|
11
Makefile
Normal file
11
Makefile
Normal file
|
@ -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/
|
15
README.md
Normal file
15
README.md
Normal file
|
@ -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`
|
10
astroacro.desktop
Normal file
10
astroacro.desktop
Normal file
|
@ -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
|
58
astroacro.py
Normal file
58
astroacro.py
Normal file
|
@ -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()
|
15
plasma-runner-astroacro.desktop
Normal file
15
plasma-runner-astroacro.desktop
Normal file
|
@ -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
|
Loading…
Reference in a new issue