4 This script processes events generated by the extaction plugin and displays
5 notifications of these events on the screen.
14 gi
.require_version('GdkPixbuf', '2.0')
15 gi
.require_version('Notify', '0.7')
16 from gi
.repository
import GdkPixbuf
, Notify
19 # The module requires html.escape() and os.environb which first appeared in
21 if sys
.hexversion
< 0x03020000:
22 print("This program requires at least Python 3.2.", file=sys
.stderr
)
28 if bkey
not in os
.environb
:
29 print("Environment variable '{}' is not set.".format(key
))
31 return os
.environb
[bkey
].decode()
35 # Make the parameters saved in environment variables easier accessible.
37 event_type
= get_env('EVENT_TYPE')
38 # This script can handle only the msg type.
39 if event_type
!= 'msg':
40 print("EVENT_TYPE='{}' is not recognized.".format(event_type
))
43 # event_network = get_env('EVENT_NETWORK')
44 # event_local_user = get_env('EVENT_LOCAL_USER')
45 event_remote_user
= get_env('EVENT_REMOTE_USER')
46 event_message
= get_env('EVENT_MESSAGE')
47 # event_message_html = get_env('EVENT_MESSAGE_HTML')
49 # Some necessary parameter is missing.
52 if not Notify
.init("Extaction-plugin handler"):
53 print("Initialization of libnotify failed.")
56 title
= "Message from {}:".format(event_remote_user
)
57 # Select first 256 characters from the message.
58 body
= event_message
[:256]
59 # Escape the '&', '<', '>' characters.
60 body
= html
.escape(body
)
62 notification
= Notify
.Notification
.new(title
, body
)
63 if b
'EVENT_REMOTE_USER_ICON' in os
.environb
:
64 # The icon is encoded in base64, decode it first.
65 icon_encoded
= os
.environb
[b
'EVENT_REMOTE_USER_ICON']
66 icon_decoded
= base64
.b64decode(icon_encoded
)
68 # Create a pixbuf loader.
69 loader
= GdkPixbuf
.PixbufLoader
.new()
70 loader
.set_size(48, 48)
71 loader
.write(icon_decoded
)
74 # Set icon from the pixbuf.
75 pixbuf
= loader
.get_pixbuf()
76 notification
.set_icon_from_pixbuf(pixbuf
)
78 # Get the notification on the screen.
83 if __name__
== '__main__':
86 # vim: set tabstop=4 shiftwidth=4 textwidth=79 expandtab :