I need to 'triggerRepaint()' a rasterLayer every 30 seconds, it's possible do it in QGIS? perhaps, a background process ui in python? create a watcher in python like QFileSystemWatcher
-
Can you clarify if you want to retrigger every 30 seconds or on every file change or a mixed approach (e.g. on file changed but not more frequent than every 30 seconds...)– Matthias KuhnApr 15, 2016 at 9:36
-
every 30 seconds, the RasterLayer can be a WMS Layer. QFileSystemWatcher is a skeleton than can be used to develop an QgsRasterLayerWatcher, by example– fherdomApr 15, 2016 at 9:57
-
stackoverflow.com/questions/3393612/…– Matthias KuhnApr 15, 2016 at 10:06
-
thank you!, but qgis crash, check my response– fherdomApr 15, 2016 at 10:26
1 Answer
Works!
from threading import Timer
class RepeatedTimer(object):
def __init__(self, interval, function, *args, **kwargs):
self._timer = None
self.interval = interval
self.function = function
self.args = args
self.kwargs = kwargs
self.is_running = False
self.start()
def _run(self):
self.is_running = False
self.start()
self.function(*self.args, **self.kwargs)
def start(self):
if not self.is_running:
self._timer = Timer(self.interval, self._run)
self._timer.start()
self.is_running = True
def stop(self):
self._timer.cancel()
self.is_running = False
def repainit(_iface):
layer = _iface.activeLayer()
if layer:
layer.triggerRepaint()
print "repaint {}".format(layer)
rt = RepeatedTimer(5, repainit, iface)
# rt.stop()