diff --git a/libs/pytwmn.py b/libs/pytwmn.py new file mode 100644 index 0000000..be0ac26 --- /dev/null +++ b/libs/pytwmn.py @@ -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("" + self.title + "" + self.msg + "") + +if __name__ == "__main__": + init() + n = Notification("PyTwmn", "This is a notification!") + n.show()