I am working on a gesture recognition project. There is a C program that captures the gestures from video input and write them to the file. Now, I have an image viewer written in Python – GTK. It switches to the next or previous window according to gestures. This continuous file read and application update is defined as follows:
def ai(self):
if self.mtime!=os.stat("input.txt").st_mtime:
self.mtime=os.stat("input.txt").st_mtime
inp=open("input.txt", "r");
line=inp.read()
if len(line)!=0:
line=line[0:len(line)-1]
for x in line.split(' '):
y=x.split('-')
if(y[1]=="R"):
self.next()
print "Move Right"
elif(y[1]=="L"):
self.prev()
print "Move Left"
time.sleep(1)
print "WakeUp"
self.ai()
Now if I comment out the recursive call here, then application works after reading present file and updating images. Of course, then it doesn’t update afterwards.
But if I uncomment the recursive call, then the console keeps on working but image-viewer application stops responding.
Is there any way to perform this function? Any event where i could bind this ai() function that could check for file updates every time that event is fired…
Any help would be appreciated.
Not sure if I understand you correctly, but I would expect what you want to do is to schedule a call to
ai()in your main GTK loop, so that your program checks if there is input on a regular base.If this is what you want you have two choices: scheduling the call periodically or schedule the call for when the program is idle (it is not doing anything else).
Your code should look something like:
The documentation should be here but presently there is a server error. Here are the relevant passages:
A catch: you have your callbacks to return
Trueif you want to keep them in the scheduler, failing to do so will make them execute only once.HTH!