title: pyqt: how to disable multiple clicks for QPushButton?
body: <p>When I push a button, some time consuming code runs. While it is running, I want to avoid that the button responds to any further click. When the code is done, then the button can be re-enabled and further clicks should be processed.</p>
  
  <p>I'm trying to do that using: </p>
  
  <pre><code>   self.btn.blockSignals(True)
     self.btn.setEnabled(False)
     ... code ...
     self.btn.blockSignals(True)
     self.btn.setEnabled(False)
  </code></pre>
  
  <p>But still, if I rapidly click this button 10 times, the code will be executed 10 times...</p>
  
  <p>In reality I'd move the time consuming code to another thread. (Edit: <s>but still the problem is the same - I think??.</s> In reality that solves it. See <a href="https://stackoverflow.com/a/46817275/5069105">accepted answer</a>.)</p>
  
  <p>How do I block or ignore clicks to a button while something is running?</p>
  
  <p>Here's a minimal version of my code:</p>
  
  <pre><code>import time
  import sys
  from PyQt4 import QtGui
  
  class Example(QtGui.QWidget):
  
      def __init__(self):
          super(Example, self).__init__()
          self.initUI()
  
      def initUI(self):
          grid = QtGui.QGridLayout()
          self.setLayout(grid)
          self.btn = QtGui.QPushButton('Count')
          grid.addWidget(self.btn, 1, 1)
          self.txt1 = QtGui.QTextEdit()
          grid.addWidget(self.txt1, 1, 2)
          self.btn.clicked.connect(self.click)
          self.count = 0
          self.show()
  
      def click(self):
          # Here I want to block any further click in the button, but it is
          # not working - clicking it 10 times quickly will run this 10 times...
          self.btn.blockSignals(True)
          self.btn.setEnabled(False)
          time.sleep(2)  # time consuming code...
          self.count += 1
          self.txt1.append(str(self.count))
          self.repaint()
          self.btn.setEnabled(True)
          self.btn.blockSignals(False)
  
  
  if __name__ == '__main__':
      app = QtGui.QApplication(sys.argv)
      ex = Example()
      sys.exit(app.exec_())
  </code></pre>