title: PyQt Widget connect() and disconnect()
body: <p>Depending on a conditions I would like to connect/re-connect a button to a different function.</p>
  
  <p>Let's say I have a button:</p>
  
  <pre><code>myButton = QtGui.QPushButton()
  </code></pre>
  
  <p>For this example let's say I check if there is an internet connection.</p>
  
  <pre><code>if connected == True:
      myButton.clicked.connect(function_A)
  
  elif connected == False:
      myButton.clicked.connect(function_B)
  </code></pre>
  
  <p>First of all I would like to disconnect a button from any function it was already connected before the button is being re-assigned/re-connected to another function (function_A or function_B).
  Secondly, I have already noticed that after the button is re-connected it takes an extra click for the button to pick up a new function. After the button is re-connected to another function it still attempts to run a previous function - a function to which a button was connected earlier (before a re-connection). Please advice. Thanks in advance!</p>
  
  <h1>EDITED LATER:</h1>
  
  <p>It appears a widget's <strong>.disconnect()</strong> method can be used to disconnect a button from a function it it is connected. </p>
  
  <pre><code>myButton.disconnect()
  </code></pre>
  
  <p>Unfortunately .disconnect() throws an error if a widget is not connected to any function. 
  To get around it I am using Try/Except. But I would rather use a more elegant solution...</p>
  
  <pre><code>try: myButton.clicked.disconnect() 
  except Exception: pass
  </code></pre>