2

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

4
  • 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...) 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
    Apr 15, 2016 at 9:57
  • thank you!, but qgis crash, check my response
    – fherdom
    Apr 15, 2016 at 10:26

1 Answer 1

2

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()
0

Your Answer

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

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