I am using Glade ,python and pygtk to develop a very basic GUI which will update itself depending on Realtime data received over a UDP socket.The data packets received come every 256ms. As I understand,I will need to receive this data using a thread to keep my GUI responsive while receiving the data.I have tried to do so.As a result The GUI opens but I dont get any OP from my UDP (dpmserver thread). I have tried the dpmserver module seperately,it works fine. I am new to threading.Actually this id my first program with threads in python. How can I keep my GUI responsive and at the same time receive the data? The code is as follows:
TMSTART=41
PACKETSIZE=133
FIELD=9
TMEND=(PACKETSIZE-1)-FIELD
import socket
import sys
import string
import os.path
import urllib2
import string
import linecache
from pprint import pprint,pformat
import threading
try:
import pygtk
pygtk.require("2.0")
except:
print "You need to install pyGTK or GTKv2 or set your PYTHONPATH correctly"
sys.exit(1)
import gtk
import gtk.glade
def procpack(data):
TMlist=[]
for i in range(TMSTART,TMEND,FIELD):
field=data[i+1:i+FIELD+1]
try:
if field=='\x00\x00\x00\x00\x00\x00\x00\x00\x00':
return TMlist
except:
pass
TMlist.append([field[0:8],field[8]])
def dpmserver():
server_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server_socket.bind(("", 5123))
print"UDPServer Waiting for client on port 5123"
bytestack=[];
while 1:
data, address = server_socket.recvfrom(512)
print "( " ,address[0], " " , address[1] , " ) said : ", data," length:",len(data)
print procpack(data)
class AppParafin:
def __init__(self):
self.gladefile = 'dpm.glade'
windowname = 'Deployment Monitor'# This must match the window name in glade
self.wTree = gtk.glade.XML(self.gladefile, windowname)# object for acessing widgets
t=threading.Thread(target=dpmserver)
t.start()
self.op=self.wTree.get_widget('Deployment Monitor')
self.op.show()
app = AppParafin()
gtk.main()