-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpynotify-server.py
More file actions
executable file
·92 lines (80 loc) · 2.9 KB
/
pynotify-server.py
File metadata and controls
executable file
·92 lines (80 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/python
#Server program listens to port 8250, Send a text
# message to this port and it will display in the desktop
from socket import *
import pynotify
import gtk
import sys
import logging
import gobject
def log(msg):
LOG_FILENAME = '/tmp/pynotify.log'
logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG)
logging.debug(msg)
class PyNotifyServer:
# activate callback
def activate( self, widget, data=None):
dialog = gtk.MessageDialog(
parent = None,
flags = gtk.DIALOG_DESTROY_WITH_PARENT,
type = gtk.MESSAGE_INFO,
buttons = gtk.BUTTONS_OK,
message_format = "Listening to port 8250 for messages")
dialog.set_title('Pynotify-Server')
dialog.connect('response', self.show_hide)
dialog.show()
# Show_Hide callback
def show_hide(self, widget,response_id, data= None):
if response_id == gtk.RESPONSE_YES:
widget.hide()
else:
widget.hide()
# destroyer callback
def destroyer(self, widget,response_id, data= None):
if response_id == gtk.RESPONSE_OK:
self.UDPSock.close()
gtk.main_quit()
else:
widget.hide()
# popup callback
def popup(self, button, widget, data=None):
dialog = gtk.MessageDialog(
parent = None,
flags = gtk.DIALOG_DESTROY_WITH_PARENT,
type = gtk.MESSAGE_INFO,
buttons = gtk.BUTTONS_OK_CANCEL,
message_format = "Do you want to close this application?")
dialog.set_title('Quit?')
dialog.connect('response', self.destroyer)
dialog.show()
def notify(self,UDPSock,condition):
data,addr = UDPSock.recvfrom(self.buf)
if not data:
return False
else:
m = pynotify.Notification(data,"Broadcasted from: "+addr[0])
#m.set_timeout(10)
m.show()
return True
def __init__(self):
# create a new Status Icon
self.staticon = gtk.StatusIcon()
self.staticon.set_from_stock(gtk.STOCK_ABOUT)
#self.staticon.set_blinking(True)
self.staticon.connect("activate", self.activate)
self.staticon.connect("popup_menu", self.popup)
self.staticon.set_visible(True)
# Set the socket parameters
self.host = ""
self.port = 8250
self.buf = 1024
self.addr = (self.host,self.port)
# Create socket and bind to address
self.UDPSock = socket(AF_INET,SOCK_DGRAM)
self.UDPSock.bind(self.addr)
pynotify.init("Pynotify Echo")
gobject.io_add_watch(self.UDPSock, gobject.IO_IN, self.notify)
# invoking the main()
gtk.main()
if __name__ == "__main__":
pynotify_server = PyNotifyServer()