title: PySide Application with asynchronous function execution
body: <p>I have a sample pyside demo which I created to see the webkit browser communication with python...
  I have two buttons in webkit</p>
  
  <ul>
  <li><p>button 1 - when clicked it sleeps for 10 seconds and then prints a message</p></li>
  <li><p>button2 - when clicked it prints a message immediately.</p></li>
  </ul>
  
  <p>When I clicked on button 1, the whole apps freezes and waits for python to finish sleeping, this means I cannot click on button 2 to do some other stuff. How can I implement an asynchronous method between function calls? </p>
  
  <p>My python codes are below</p>
  
  <pre><code>import sys,json
  from time import sleep
  from PySide.QtCore import *
  from PySide.QtGui import *
  from PySide.QtWebKit import QWebView, QWebSettings
  from PySide.QtNetwork import QNetworkRequest
  from PySide.QtCore import QObject, Slot, Signal
  
      html_str="""&lt;!doctype&gt;
          &lt;html&gt;
  
          &lt;body&gt;hello world
          &lt;button id="button" &gt;button1&lt;/button&gt;
          &lt;button id="button2" &gt;button2&lt;/button&gt;
          &lt;/body&gt;
      &lt;/html&gt;
      &lt;script type="text/javascript"&gt;
      document.getElementById("button").onclick=function(){
      object.reply(" hello ");
      }
      document.getElementById("button2").onclick=function(){
      object.reply2(" hello ");
      }
      function data_from_js(msg){
          var tag=document.createElement('div');
          tag.innerHTML="message from python";
          document.body.appendChild(tag);
          alert(msg['name']);
      }
      &lt;/script&gt;
      &lt;style&gt;
      body{
      border:solid black 1px;
      }
      &lt;/style&gt;
      &lt;/doctype&gt;"""
  class Qbutton(QObject):
      from time import sleep
      def __init__(self):
          super(Qbutton,self).__init__()
      @Slot(str)
      def reply(self,recd):
          #r=QMessageBox.information(self,"Info",msg)
          msgBox = QMessageBox()
          sleep(10)
          msgBox.setText("python just said"+recd)
          msgBox.exec_()
          return "I am recieving pythonic data"
          #r=QMessageBox.question(self,title,recd,QMessageBox.Yes | QMessageBox.No)
      @Slot(str)
      def reply2(self,recd):
          msgBox = QMessageBox()
          msgBox.setText("python just said"+recd+ " another time")
          msgBox.exec_()
          return "I am recieving pythonic data"        
      @Slot(str)
      def send_tojs(self):
          pass
  
  
  class adstar_gui(QWidget):
      def __init__(self):        
          super(adstar_gui,self).__init__()
          self.setWindowTitle("Adstar Wordlist Generator")
          self.setMaximumWidth(5000)
          self.setMaximumHeight(5000)
          self.setMinimumWidth(500)
          self.setMinimumHeight(500)
          self.show()
          print "Sample window"
  
      def closeEvent(self,event):
          self.closeEvent()
  if __name__=="__main__":
      Qapp=QApplication(sys.argv)
      t=QWebView()
      t.setHtml(html_str)
      button=Qbutton()
      t.page().mainFrame().addToJavaScriptWindowObject("object",button)
      t.show()
      #t.page().mainFrame().evaluateJavaScript("data_from_js(%s);" % (json.dumps({'name':"My name is Junior"}) ))
      QCoreApplication.processEvents()
      #sys.exit(Qapp.exec_())
      Qapp.exec_()
  </code></pre>
  
  <p>QUESTION</p>
  
  <p>How can I click on <code>button 1</code> in webkit and let python do something in the background when button 1 is clicked? (so that <code>button 2</code> function does not need to wait for button 1 function to finish)</p>
  
  <p>Kindly use this demo and improve on it...much appreciated</p>