View Single Post
Posts: 56 | Thanked: 31 times | Joined on Jul 2008 @ Austria
#18
Just use gobject.io_add_watch to be notified when there is data to read and spare yourself the ordeal of using threads.

http://faq.pygtk.org/index.py?req=sh...=faq20.016.htp

def handle_data(source, condition):
__data = source.recv(1024)
__if len(data) > 0:
____self.entrybox.set_text(self.entrybox.get_text( ) + data)
____# or maybe just self.entrybox.props.text += data
____#print data
____return True # call me again if something happens
__else: # end of file
____return False # stop calling me

sock=BluetoothSocket(RFCOMM)
#sock.settimeout(15) # ?
sock.connect(('00:1F:00:B5:3A:45',5))
gobject.io_add_watch(sock, gobject.IO_IN, handle_data)

What happens is that your GUI program ALSO watches your socket and should something arrive, it will call "handle_data" which then reads the chunk that arrived (that is fast).
After that, your GUI program resumes. Note that threads didn't enter the picture anywhere (not in the GTK library either).

Last edited by dannym; 2010-04-08 at 09:10.