title: QtGui.QFileDialog.getExistingDirectory() window won't close after directory has been chosen (PyQt)
body: <p>I am trying to get a path with the <code>QtGui.QFileDialog.getExistingDirectory()</code> dialog window in a <code>python</code> program to ease things up for users while the rest of the program is in console output.
  I have this piece of code for this purpose:</p>
  
  <pre><code>import sys, os
  from PyQt4 import QtGui
  
  def getpath(filename,
              noPathFileMsg='',
              wrongFolderMsg='',
              selectFolderMsg=''):
  
      try:
          f = open('./'+filename,'r')
      except IOError:
          folder = get_new_path(filename,
                                       noPathFileMsg, 
                                       selectFolderMsg)
      else:
          folder = f.readline()
          f.close()
          currentDir = os.getcwd()
          try:
              os.chdir(folder)
          except:
              folder = get_new_path(filename,
                                           wrongFolderMsg,
                                           selectFolderMsg)
          else:
              os.chdir(currentDir)
      finally:
          return folder
  
  def get_new_path(filename,
                   infoMsg,
                   selectFolderMsg):
  
      app = QtGui.QApplication(sys.argv)
      QtGui.QMessageBox.about(None, 'No folder', infoMsg)
      folder = QtGui.QFileDialog.getExistingDirectory(None, selectFolderMsg)
      app.exit()
      if os.name == 'posix':
          folder += '/'
      elif os.name == 'nt':
          folder += '\\'
      g = open('./'+filename,'w')
      g.write(folder)
      g.close()
      return folder
  if __name__ == '__main__':
      folderPath = getpath('pathtofolder.txt',
                           noPathFileMsg='The path to the folder has not been set',
                           wrongFolderMsg='The path folder saved cannot be reached',
                           selectFolderMsg='Please select a folder')
      print folderPath
      var = input('The program stopped at the input instruction, the dialog window should now be closed!')
  </code></pre>
  
  <p>If I call the getpath function the dialog window stays open until the script that called the function ends instead of closing just after this instruction:</p>
  
  <pre><code>folder = QtGui.QFileDialog.getExistingDirectory(None, selectFolderMsg)
  </code></pre>
  
  <p>If you run this code it will create a file that saves the directory saved with the dialog window in the folder where the script is run.</p>
  
  <p>What did I do wrong?</p>
  
  <p>By the way, I am on Ubuntu 12.04.
  Thank you!
  Cheers</p>