Open Zren opened 7 years ago
Probably worth mentioning two other (not necessarily better) ways of approaching this:
Here's an example simple script I might use for the timer if I can:
#!/usr/bin/env python3
from plumbum.cmd import mpv, kdialog, kill, notify_send
from plumbum import BG
fut = mpv['--loop', '/usr/share/sounds/freedesktop/stereo/complete.oga'] & BG
try:
kdialog(
'--title', "Timer",
'--icon', 'kalarm',
'--msgbox', "Your time's run out!"
)
except (Exception, KeyboardInterrupt) as e:
notify_send(
'-a', "Timer",
'-i', 'kalarm',
'-t', 0,
"Timer Error",
str(e)
)
finally:
kill(fut.proc.pid)
I'm thinking of something similar, where it returns which "action" was clicked. I spin up canberra-gtk-play
which is part of libcanberra
which is a plasma-pa
dependency (the volume widget). With it printing which action was clicked, I could dynamically add buttons like "sleep 5min" or something along those lines.
$ dpkg -S `which canberra-gtk-play`
$ pacman -Qo `which canberra-gtk-play`
/usr/bin/canberra-gtk-play is owned by libcanberra 0.30+2+gc0620e4-2
#!/usr/bin/python3
import subprocess
import gi
gi.require_version('GLib', '2.0')
gi.require_version('Notify', '0.7')
from gi.repository import GLib, Notify
appName = "Event Calendar"
# https://notify2.readthedocs.io/en/latest/
loop = GLib.MainLoop()
Notify.init(appName)
# print(Notify.get_server_caps())
n = Notify.Notification.new(
appName,
"This is an example notification.",
icon="view-calendar"
)
def on_action(notification, action, *user_data):
print(action, *user_data)
sfxProc.terminate()
loop.quit()
def closed(notification):
on_action(notification, "closed")
n.connect("closed", closed)
n.add_action("default", "default", on_action)
n.add_action("dismiss", "Dismiss", on_action)
n.show()
sfxProc = subprocess.Popen([
"canberra-gtk-play",
# "--id", "phone-incoming-call",
"--file", "/usr/share/sounds/freedesktop/stereo/complete.oga",
"--description", appName,
"--loop", "3",
])
loop.run()
It seems Audio.loops will repeat infinitely when > 1, so I'll need to implement remainingLoops myself.