Hey all,

i am having an issue with my thread being called and then locking out the gui. i have been advised to follow a tutorial at the pygtk faq, and i think i am close.
but still hanging.

first, i tried to use thread, then threading.

here is what i have.


import os
import time
from time import strftime
import sys
import gtk
import pygtk
import serial
import threading
from threading import Thread
import gtk.glade

gtk.gdk.threads_init()

def on_StartEnginesButton_clicked(self, widget, *args):
print "on_StartEnginesButton_clicked called with self.%s" % widget.get_name()
       Input1Iter = self.Input1Buffer.get_end_iter()
       Input2Iter = self.Input2Buffer.get_end_iter()
       Input1Data = 'Reading Serial device ttyS14 \n'
       Input2Data = 'Reading Serial device ttys15 \n'
       self.Input1Buffer.insert(Input1Iter, Input1Data)
self.Input2Buffer.insert(Input2Iter, Input2Data) time.sleep(1) def Serial1(): print 'running serial 1'
           gtk.gdk.threads_init()
           ser = serial.Serial('/dev/ttyS1', 2400, timeout=None)
           loopy = 1
           i = 1
while loopy < 5: for x in range(5): i = i + 1 a = ser.read(1)#read one byte a = ord(a) # change byte to integer
                   if (a < 64 )or (a > 127):
break b = ser.read(1)
                   b = ord(b)
                   if (b < 64 )or (b > 127):
                       break
                   c = ser.read(1)
                   c = ord(c)
                   if c < 92:
                       break
                   d = ser.read(1)
                   d = ord(d)
                   if d < 128:
                       break
                   Sensor_ID = (a & 63) + (b & 63) * 64 + (c & 1) * 4096
                   Status = (c & 62) / 2 + (d & 63) * 32
                   c = int(c)
                   d = int(d)
x_Now = strftime('%Y-%m-%d %H:%M:%S') gtk.threads_enter() Input1Data = str(Sensor_ID)+'\t'+str(Status)+'\t--------->\t'+x_Now+'\n'
                   Input1Iter = self.Input1Buffer.get_end_iter()
                   self.Input1Buffer.insert(Input1Iter, Input1Data)
                   gtk.threads_leave()
                   f = open('/home/piv/PivData/tmp/Serial/'+str(i), 'w')
f.write(str(Sensor_ID)+'\n'+str(c)+'\n'+str(d)+'\n'+str(Status)+'\n'+x_Now)
                   f.close()
Thread.start(Serial1())
def main(self):
       #gtk.gdk.threads_enter()
       gtk.main()
#gtk.gdk.threads_leave()
def main():
   main = Main()
main.run()
if __name__ == "__main__":

gtk.threads_enter() main() gtk.threads_leave()
thanks all , some (a lot) is not included here, as its rather long.
i have tried where the comments are , that didn't work either.

any ideas?


_______________________________________________
pygtk mailing list   [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to