I have a application with gtk window and socket connection as server. Client is sending data to this server with image and I am trying to show updated images sent via socket in gtk window. But this gtk window is constantly seems to be freezed. Any hint how to make it "not freezed" when program is running? Probably place somewhere in code something like threading... not sure.
import socket
import sys
import gtk, PIL.Image, time
from PIL import Image
# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Bind the socket to the port
server_address = ('localhost', 8888)
print >>sys.stderr, 'starting up on %s port %s' % server_address
sock.bind(server_address)
# Listen for incoming connections
sock.listen(1)
img_width = 180
img_height = 144
test = gtk.gdk.Pixbuf(
gtk.gdk.COLORSPACE_RGB,
False,
8,
img_width,
img_height
)
rowstride = test.get_rowstride() #zistim si rowstride
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.show_all()
while True:
# Wait for a connection
print >>sys.stderr, 'waiting for a connection'
connection, client_address = sock.accept()
try:
print >>sys.stderr, 'connection from', client_address
# Receive the data in small chunks and retransmit it
while True:
data = connection.recv(100000) #100000
print >>sys.stderr, 'received "%s"' % data
if data:
print >>sys.stderr, 'sending data back to the client'
connection.sendall("OK") #data
pixbuf = gtk.gdk.pixbuf_new_from_data(data, gtk.gdk.COLORSPACE_RGB, False, 8, img_width, img_height, rowstride) #540 rowstride
pixmap, mask = pixbuf.render_pixmap_and_mask()
image = gtk.Image()
image.set_from_pixmap(pixmap, mask)
#window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.add(image) #image data
window.show_all()
else:
print >>sys.stderr, 'no more data from', client_address
break
finally:
# Clean up the connection
connection.close()