I have written a script that runs with a glade gui. When a button in glade is pushed I need it to run a piece of code, pause for 3 seconds and run it again in an on going loop until the button is pushed again. So the button is just an on/off control.
I can get it to run the code with out any problems but i cannot get it to stop when the button is pushed again.
I have simplified the code for here,
from pylab import *
import sys
import datetime
import os
import time
import pygtk
pygtk.require("2.0")
import gtk
import gtk.glade
###############################################################################
# End of Imports
record = 0
view = 0
class gui:
def __init__(self):
global record
global view
#Set the Glade file
self.gladefile = "graph4a.glade"
self.wTree = gtk.glade.XML(self.gladefile)
#Create our dictionay and connect it
dic = { "on_record_toggled" : self.record_toggle,
"on_window1_destroy" : gtk.main_quit }
self.wTree.signal_autoconnect(dic)
def record_toggle(self, widget):
global record
if (record == 1):
print "Record is turned off"
record = 0
else:
print "Record is turned on"
record = 1
os.system("perl modbus3c.pl") #These 2 lines need to be continually looped
time.sleep(3) #whenever the record button is toggled on
#until it is toggled off again
if __name__ == "__main__":
hwg = gui()
gtk.main()