Friday, 31 July 2015

qgis - How to automatically reload a layer every 30 seconds?


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



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

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...