I have to schedule a job in qgis every n seconds. In the meantime i will be able to do other stuff (for example visualize the attributes of an object). I have implemented a code like this in Python:
import time,threading...
interval=60
def job():
....
....
....
threading.Timer(interval,job).start()
threading.Timer(interval,job).start()
When I launch the script it remains suspended and does not do anything
I put here the entire code for completeness:
import time,threading
import re,glob,os
from PyQt4.QtGui import QColor
interval=5
def job():
lay=qgis.utils.iface.activeLayer()
iterator=range(50)
counter=0
for i in iterator:
if lay<>None and not(re.search("com",lay.name())):
QgsMapLayerRegistry.instance().removeMapLayer(lay.id())
lay=qgis.utils.iface.activeLayer()
dir="/home_local/titan/projDir/data/titan/shapefiles/shapefile/"
lista=os.listdir(dir)
exp="shp"
for file in lista:
if re.search(exp,file):
counter=counter+1
lay=qgis.utils.iface.addVectorLayer(dir+file,file+str(counter),"ogr")
symbols = lay.rendererV2().symbols()
symbol = symbols[0]
if re.search("F30",file):
symbol.setColor(QColor.fromRgb(50,50,250))
else :
symbol.setColor(QColor.fromRgb(150,200,200))
qgis.utils.iface.mapCanvas().refresh()
qgis.utils.iface.legendInterface().refreshLayerSymbology(lay)
lay.setLayerTransparency(30)
threading.Timer(interval,job).start()
threading.Timer(interval,job).start()
NB. without the threading the job works.