Thin Python wrapper around twmn: https://github.com/sboli/Twmn
This commit is contained in:
parent
3475d464f8
commit
4d65c4f45a
1 changed files with 32 additions and 0 deletions
32
libs/pytwmn.py
Normal file
32
libs/pytwmn.py
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
import os, socket
|
||||||
|
|
||||||
|
def init():
|
||||||
|
port = 9797
|
||||||
|
try:
|
||||||
|
with open(os.path.expanduser("~/.config/twmn/twmn.conf")) as f:
|
||||||
|
for line in f.readlines():
|
||||||
|
if line.startswith("port=") and \
|
||||||
|
line[5:-1].isdigit():
|
||||||
|
port = int(line[5:-1])
|
||||||
|
break
|
||||||
|
except IOError:
|
||||||
|
pass
|
||||||
|
global s
|
||||||
|
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
|
s.connect(("127.0.0.1", port))
|
||||||
|
|
||||||
|
class Notification(object):
|
||||||
|
def __init__(self, title="", msg="", icon=""):
|
||||||
|
self.title = unicode(title)
|
||||||
|
self.msg = unicode(msg)
|
||||||
|
if icon.startswith("file://"):
|
||||||
|
icon = icon[7:]
|
||||||
|
self.icon = icon
|
||||||
|
|
||||||
|
def show(self):
|
||||||
|
s.send("<root><title>" + self.title + "</title><content>" + self.msg + "</content></root>")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
init()
|
||||||
|
n = Notification("PyTwmn", "This is a notification!")
|
||||||
|
n.show()
|
Loading…
Reference in a new issue