title: How to make Python wait while QGIS renders a shapefile
body: <p>I have written code for my <code>QGIS 2.8.1</code> which can successfully take screenshot of one shape file, but unfortunately it doesn't work when I try with multiple shapefiles.</p>
  
  <p>So basically if I replace <code>allFiles = ["C:/Shapefiles/Map_00721.shp"]</code> in the code below with <code>allFiles = ["C:/Shapefiles/Map_00721.shp", "C:/Shapefiles/Map_00711.shp", "C:/Shapefiles/Map_00731.shp", "C:/Shapefiles/Map_00791.shp", "C:/Shapefiles/Map_00221.shp"]</code>, the loop iterates over the array without waiting for the rendering and snapshot process to happen.</p>
  
  <p>I have tried using <code>time.sleep</code> in the code below, but it stops the rendering of shapefiles too and the result doesn't came as expected.</p>
  
  <p>
  
  <pre><code>import ogr,os
  from PyQt4.QtGui import *
  from PyQt4.QtCore import *
  from qgis.core import *
  import qgis.utils
  import glob
  from time import sleep
  import math
  import processing
  from processing.core.Processing import Processing
  from PyQt4.QtCore import QTimer
  
  Processing.initialize()
  Processing.updateAlgsList()
  
  OutputFileName = "ABC"    # Temprory global placeholder for filename
  canvas = iface.mapCanvas()
  
  
  def startstuffs():
      qgis.utils.iface.zoomToActiveLayer()    # Zoom to Layer
      scale=canvas.scale()    # Get current Scale
      scale =  scale * 1.5
      canvas.zoomScale(scale)   # Zoomout a bit
      QTimer.singleShot(2000,saveImg)   # Jump to save img
  
  def saveImg():
      qgis.utils.iface.mapCanvas().saveAsImage(OutputFileName)
      QgsMapLayerRegistry.instance().removeAllMapLayers()
  
  
  # Add array of address below
  allFiles = ["C:/Shapefiles/Map_00721.shp"]
  filesLen = len(allFiles)
  
  TexLayer = "C:/US_County_NAD27.shp"
  
  for lop in range(filesLen):
  
      currentShpFile = allFiles[lop]
      currentShpFileName = currentShpFile.strip("C:/Shapefiles/")
      OutputFileName = "C:/ImageOut/" + currentShpFileName + ".png"
      wb = QgsVectorLayer(currentShpFile, currentShpFileName, 'ogr')
      wbTex = QgsVectorLayer(TexLayer, 'CountyGrid', 'ogr')
      QgsMapLayerRegistry.instance().addMapLayer(wb)    # Add the shapefile
      QgsMapLayerRegistry.instance().addMapLayer(wbTex)    # Add the county shapefile
      qgis.utils.iface.setActiveLayer(wb)   # Makes wb as active shapefile
  
      QTimer.singleShot(3000, startstuffs)    # This start stuffs
  
  print "Done!"
  </code></pre>