Eclectic Media Git pynotify / 485367e
Initial commit, initial GObject Notify wrapper Creates a wrapper object around GNU Notify (V7) objects for easy use in python scripting. Also adds a convienience command line function. Ariana Giroux 1 year, 23 days ago
1 changed file(s) with 51 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 """ Python3 sanity interface for GTK Notify object spawning.
1
2 MIT License circa October 2019 by Ariana Giroux <ariana.giroux@gmail.com>
3 Author PGP Key: FEED 41C6 F26B 4E0E B52B DFA1 510E F70B 4B42 770D
4
5 From original StackExchange post: https://askubuntu.com/questions/108764/how-do-i-send-text-messages-to-the-notification-bubbles
6 For further documentation of the objects, see: https://lazka.github.io/pgi-docs/#Notify-0.7
7 """
8 import click
9 from gi import require_version
10 require_version('Notify', '0.7')
11 from gi.repository import GObject
12 from gi.repository import Notify
13
14
15 class Notifier(GObject.Object):
16 """ A wrapper class for GTK Notify Objects.
17 Example Usage:
18 >>> notifier = Notifier("test app", timeout=1500) # app title not required
19 >>> notifier("the body of the message")
20 """
21 def __init__(self, title: str, icon_path=None, timeout=None):
22 """ Set `title` to show title for notification
23 Set `app_title` to "" if None. App title for logs?
24 Set `icon_path` to "" if None.
25 Timeout is in milleseconds, leave none for default timing. """
26 super(Notifier, self).__init__()
27 self.icon_path = icon_path
28 self.title = title
29 self.timeout = Notify.EXPIRES_DEFAULT if not timeout else timeout
30
31 def __call__(self, text: str):
32 """ Spawn a new GTK Notification. """
33 Notify.init(self.title)
34 n = Notify.Notification.new(self.title, text,
35 "" if not self.icon_path else self.icon_path)
36 n.set_timeout(self.timeout)
37 n.show()
38
39
40 @click.command()
41 @click.argument('message', type=str)
42 def notify_once(message: str):
43 notifier = Notifier("Eclectic Media Scripts")
44 notifier(message)
45
46
47 if __name__ == '__main__':
48 notify_once()
49
50 # vim: nospell nowrap colorcolumn=80 sw=4 ts=4 syntax=python: