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...) Commented Apr 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
    – fherdom
    Commented Apr 15, 2016 at 9:57
  • stackoverflow.com/questions/3393612/… Commented Apr 15, 2016 at 10:06
  • thank you!, but qgis crash, check my response
    – fherdom
    Commented Apr 15, 2016 at 10:26

1 Answer 1



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

    def _run(self):
        self.is_running = False
        self.function(*self.args, **self.kwargs)

    def start(self):
        if not self.is_running:
            self._timer = Timer(self.interval, self._run)
            self.is_running = True

    def stop(self):
        self.is_running = False

def repainit(_iface):
    layer = _iface.activeLayer()
    if layer:
        print "repaint {}".format(layer)

rt = RepeatedTimer(5, repainit, iface)

# rt.stop()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.