pyqt - Python: How can I refresh QLCDNumbers + emiting again after stopping -


i want ask how possible refresh qlcdnumbers after have started measures. created gui thread connect signals qlcdnumbers that:

class btdialog(qtgui.qdialog, dlg):   def __init__(self):     qtgui.qdialog.__init__(self)     self.setupui(self)     self.thread = workerthread()      #configure slots     self.connect(self.startbutton, qtcore.signal("clicked()"), self.onstart)     self.connect(self.stopbutton, qtcore.signal("clicked()"), self.onstop)      #qlcdnumber slot     self.connect(self.thread, self.thread.voltage, self.lcdvoltage.display)   def onstart(self):     self.thread.start()   def onstop(self):      self.emit(self.thread.voltage, 0) #trying refresh      abort() 

here connect 2 buttons, 1 starting worker thread , other stop process. when stop process want refresh qlcdnumber displaying '0' doesn't work. in worker thread initialize signal that:

def __init__(self, parent = none):     qtcore.qthread.__init__(self, parent)     self.voltage = qtcore.signal("voltage") 

and when process runs emit signal with

self.emit(self.voltage, volt_act) 

after measuring. works far. after stopping when want start worker process again signal doesn't emit qlcdnumber again. have restart gui. how can fix 2 problems of mine want refresh qlcdnumber , on after stopping , refreshing emitting signal again?

can't tell issue code posted, should modify it, checkout docs new-style signal/slot connections , further reference (modal dialogs, timers, etc):

#!/usr/bin/env python #-*- coding:utf-8 -*- import time  pyqt4 import qtgui, qtcore  class mythread(qtcore.qthread):     countchange = qtcore.pyqtsignal(int)     countreset  = qtcore.pyqtsignal(int)      def __init__(self, parent=none):         super(mythread, self).__init__(parent)         self.stopped = qtcore.qevent(qtcore.qevent.user)      def start(self):         self.stopped.setaccepted(false)         self.count = 0          super(mythread, self).start()      def run(self):         while not self.stopped.isaccepted():             self.count += 1             self.countchange.emit(self.count)             time.sleep(1)          self.countreset.emit(0)      def stop(self):         self.stopped.setaccepted(true)  class mywindow(qtgui.qdialog):     def __init__(self, parent=none):         super(mywindow, self).__init__(parent)          self.lcdnumber = qtgui.qlcdnumber(self)          self.pushbuttonstart = qtgui.qpushbutton(self)         self.pushbuttonstart.settext("start")         self.pushbuttonstart.clicked.connect(self.on_pushbuttonstart_clicked)          self.pushbuttonstop = qtgui.qpushbutton(self)         self.pushbuttonstop.settext("stop")         self.pushbuttonstop.clicked.connect(self.on_pushbuttonstop_clicked)          self.pushbuttondone = qtgui.qpushbutton(self)         self.pushbuttondone.settext("done")         self.pushbuttondone.clicked.connect(self.on_pushbuttondone_clicked)          self.layouthorizontal = qtgui.qhboxlayout(self)         self.layouthorizontal.addwidget(self.lcdnumber)         self.layouthorizontal.addwidget(self.pushbuttonstart)         self.layouthorizontal.addwidget(self.pushbuttonstop)         self.layouthorizontal.addwidget(self.pushbuttondone)          self.thread = mythread(self)         self.thread.countchange.connect(self.lcdnumber.display)         self.thread.countreset.connect(self.lcdnumber.display)      @qtcore.pyqtslot()     def on_pushbuttonstart_clicked(self):         self.thread.start()      @qtcore.pyqtslot()     def on_pushbuttonstop_clicked(self):         self.thread.stop()      @qtcore.pyqtslot()     def on_pushbuttondone_clicked(self):         sys.exit()  if __name__ == "__main__":     import sys      app = qtgui.qapplication(sys.argv)     app.setapplicationname('mywindow')      main = mywindow()     main.exec_()      sys.exit(app.exec_()) 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -