class Message & color
This commit is contained in:
parent
50a2a97af0
commit
eb0011e901
1 changed files with 66 additions and 24 deletions
|
|
@ -1,12 +1,65 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
from enum import IntEnum
|
# import rich
|
||||||
|
from rich.console import Console
|
||||||
|
import humanize
|
||||||
import datetime
|
import datetime
|
||||||
|
from enum import IntEnum
|
||||||
|
|
||||||
import dbus
|
import dbus
|
||||||
import gi.repository.GLib
|
import gi.repository.GLib
|
||||||
from dbus.mainloop.glib import DBusGMainLoop
|
from dbus.mainloop.glib import DBusGMainLoop
|
||||||
|
|
||||||
|
class N:
|
||||||
|
def __init__(self):
|
||||||
|
self.member = "Notify"
|
||||||
|
self.interface = "org.freedesktop.Notifications"
|
||||||
|
self.args_list = [
|
||||||
|
"my app",
|
||||||
|
0,
|
||||||
|
"",
|
||||||
|
"my summary",
|
||||||
|
"my (potentially longer) body",
|
||||||
|
["s"],
|
||||||
|
{
|
||||||
|
"urgency": 1,
|
||||||
|
"sender-pid": 12345,
|
||||||
|
},
|
||||||
|
-1
|
||||||
|
]
|
||||||
|
def get_member(self):
|
||||||
|
return self.member
|
||||||
|
|
||||||
|
def get_interface(self):
|
||||||
|
return self.interface
|
||||||
|
|
||||||
|
def get_args_list(self):
|
||||||
|
return self.args_list
|
||||||
|
|
||||||
|
class Message:
|
||||||
|
def __init__(self, notification):
|
||||||
|
# print("Notification")
|
||||||
|
args = notification.get_args_list()
|
||||||
|
# print("Args list:", args, flush = True)
|
||||||
|
|
||||||
|
self.app = str(args[0])
|
||||||
|
self.replaces_id = int(args[1])
|
||||||
|
# self.icon = str(args[2])
|
||||||
|
self.summary = str(args[3])
|
||||||
|
self.body = str(args[4])
|
||||||
|
self.actions = args[5]
|
||||||
|
self.hints = dict(args[6])
|
||||||
|
self.expire_timeout = int(args[7])
|
||||||
|
|
||||||
|
self.date = datetime.datetime.now()
|
||||||
|
self.hdate = humanize.naturaltime(self.date)
|
||||||
|
self.urgency = {0: "low", 1: "normal", 2: "critical", None: "unknown"}
|
||||||
|
|
||||||
|
def print(self):
|
||||||
|
console = Console()
|
||||||
|
console.print(f"[color(33)][black on color(33)]{self.hdate}:[bold white on color(33)]{self.app}[color(33) on color(254)][not bold black on color(254)]{self.summary}[color(254) on color(239)][white on color(239)]{self.body}[reset][color(239)]")
|
||||||
|
|
||||||
|
|
||||||
def receive(bus, notification):
|
def receive(bus, notification):
|
||||||
# print(notification, flush = True)
|
# print(notification, flush = True)
|
||||||
# print("---------------------------------------------", flush = True)
|
# print("---------------------------------------------", flush = True)
|
||||||
|
|
@ -14,32 +67,21 @@ def receive(bus, notification):
|
||||||
# print("Interface:", notification.get_interface(), flush = True)
|
# print("Interface:", notification.get_interface(), flush = True)
|
||||||
|
|
||||||
if notification.get_member() == "Notify" and notification.get_interface() == 'org.freedesktop.Notifications':
|
if notification.get_member() == "Notify" and notification.get_interface() == 'org.freedesktop.Notifications':
|
||||||
# print("Notification")
|
msg = Message(notification)
|
||||||
args = notification.get_args_list()
|
msg.print()
|
||||||
# print("Args list:", args, flush = True)
|
|
||||||
|
|
||||||
app = str(args[0])
|
|
||||||
replaces_id = int(args[1])
|
|
||||||
# icon = str(args[2])
|
|
||||||
summary = str(args[3])
|
|
||||||
body = str(args[4])
|
|
||||||
actions = args[5]
|
|
||||||
hints = dict(args[6])
|
|
||||||
expire_timeout = int(args[7])
|
|
||||||
|
|
||||||
date = datetime.datetime.now()
|
|
||||||
urgency = {0: "low", 1: "normal", 2: "critical", None: "unknown"}
|
|
||||||
|
|
||||||
print(f"[{date}][{app}]:\n\t{summary}\n\t« {body} »", flush=True)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
DBusGMainLoop(set_as_default=True)
|
import sys
|
||||||
|
|
||||||
bus = dbus.SessionBus()
|
if len(sys.argv) > 1 and sys.argv[1] == "--test":
|
||||||
bus.add_match_string_non_blocking("eavesdrop=true, interface='org.freedesktop.Notifications', member='Notify'")
|
receive(None, N())
|
||||||
bus.add_message_filter(receive)
|
else:
|
||||||
|
DBusGMainLoop(set_as_default=True)
|
||||||
|
|
||||||
mainloop = gi.repository.GLib.MainLoop()
|
bus = dbus.SessionBus()
|
||||||
mainloop.run()
|
bus.add_match_string_non_blocking("eavesdrop=true, interface='org.freedesktop.Notifications', member='Notify'")
|
||||||
|
bus.add_message_filter(receive)
|
||||||
|
|
||||||
|
mainloop = gi.repository.GLib.MainLoop()
|
||||||
|
mainloop.run()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue