Python QT GUI and interrupt - Raspberry Pi Forums


hi,

trying display value interrupt event when gpio input change state.
here python code :

code: select all

#!/usr/bin/env python import rpi.gpio gpio import time import os import random import datetime import sys threading import thread  pyqt4 import qtcore, qtgui, uic   qtcreatorfile = "form.ui" # enter file here. global ui_mainwindow, qtbaseclass  ui_mainwindow, qtbaseclass = uic.loaduitype(qtcreatorfile) gpio.setmode(gpio.bcm)  gpio.setup(18, gpio.in, pull_up_down=gpio.pud_up) gpio.setup(24, gpio.in, pull_up_down=gpio.pud_down) print "ici" global start  tmp = datetime.datetime(2000,12,14)  #on est oblige de donner une date dans les arguments, mais ca n'a aucune incidence pour la suite start = tmp.today()   #jour.today() renvoie la date au moment ou on l'appelle au format annee mois jour,heure,minute,seconde,microseconde print str(start)  def my_start(channel): #interrupt 18 	 	tmp = datetime.datetime(2000,12,14)  #on est oblige de donner une date dans les arguments, mais ca n'a aucune incidence pour la suite 	start = tmp.today()   #jour.today() renvoie la date au moment ou on l'appelle au format annee mois jour,heure,minute,seconde,microseconde    def my_stop(channel): #interrupt 24     tmp = datetime.datetime(2000,12,14)     stop = tmp.today()        print str(stop-start)     self.label.settext(str(stop-start))     print "houla" gpio.add_event_detect(18, gpio.falling, callback=my_start,bouncetime=2000) gpio.add_event_detect(24, gpio.rising, callback=my_stop,bouncetime=2000) class myapp(qtgui.qmainwindow, ui_mainwindow):     def __init__(self):         qtgui.qmainwindow.__init__(self)         ui_mainwindow.__init__(self)         self.setupui(self)         self.lcdnumber.display(10.1)         self.label.settext("essai de texte")                       def closeevent(self, event):         print("event")         reply = qtgui.qmessagebox.question(self, 'message',             "etes vous sur de vouloir quitter?", qtgui.qmessagebox.yes, qtgui.qmessagebox.no)          if reply == qtgui.qmessagebox.yes:             gpio.cleanup()       # clean gpio on ctrl+c exit             gpio.cleanup()           # clean gpio on normal exit             event.accept()         else:             event.ignore()    if __name__ == "__main__":     app = qtgui.qapplication(sys.argv)     window = myapp()     window.show()     sys.exit(app.exec_())     print "houla2"                 



problem , self isn't recognize in my_stop callback.
question :
how can update gui callback.

thanks

have tried putting them in class, this?

code: select all

tmp = datetime.datetime(2000,12,14)  start = tmp.today() print str(start) print "houla"  class myapp(qtgui.qmainwindow, ui_mainwindow):     def __init__(self):         qtgui.qmainwindow.__init__(self)         ui_mainwindow.__init__(self)         self.setupui(self)         self.lcdnumber.display(10.1)         self.label.settext("essai de texte")                       def closeevent(self, event):         print("event")         reply = qtgui.qmessagebox.question(self, 'message',             "etes vous sur de vouloir quitter?", qtgui.qmessagebox.yes, qtgui.qmessagebox.no)          if reply == qtgui.qmessagebox.yes:             gpio.cleanup()       # clean gpio on ctrl+c exit             gpio.cleanup()           # clean gpio on normal exit             event.accept()         else:             event.ignore()      def my_start(self, channel): #interrupt 18                tmp = datetime.datetime(2000,12,14)         start = tmp.today()       def my_stop(self, channel): #interrupt 24         tmp = datetime.datetime(2000,12,14)         stop = tmp.today()            print str(stop-start)         self.label.settext(str(stop-start))    if __name__ == "__main__":     app = qtgui.qapplication(sys.argv)     window = myapp()     gpio.add_event_detect(18, gpio.falling, callback=window.my_start, bouncetime=2000)     gpio.add_event_detect(24, gpio.rising, callback=window.my_stop, bouncetime=2000)     window.show()     sys.exit(app.exec_())     print "houla2"


raspberrypi



Comments