mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-06-10 14:51:54 +02:00
[utils] QmlInstantEngine: fix spurious consecutive reloads issue
Fix the problem with the application taking up all the CPU after a few reloads while using a Qt3D Scene. When a file changes, wait for a few milliseconds before adding it back to the watch list. This prevents the system to reload the engine twice for a same fileChanged event (happens with some text editors).
This commit is contained in:
parent
60f1f36ff8
commit
8823dba87f
1 changed files with 12 additions and 4 deletions
|
@ -1,7 +1,7 @@
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from PySide2.QtCore import QFileSystemWatcher, QUrl, Slot
|
from PySide2.QtCore import QFileSystemWatcher, QUrl, Slot, QTimer
|
||||||
from PySide2.QtQml import QQmlApplicationEngine
|
from PySide2.QtQml import QQmlApplicationEngine
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,6 +29,8 @@ class QmlInstantEngine(QQmlApplicationEngine):
|
||||||
self._rootItem = None
|
self._rootItem = None
|
||||||
|
|
||||||
def onObjectCreated(root, url):
|
def onObjectCreated(root, url):
|
||||||
|
if not root:
|
||||||
|
return
|
||||||
# Restore root item geometry
|
# Restore root item geometry
|
||||||
if self._rootItem:
|
if self._rootItem:
|
||||||
root.setGeometry(self._rootItem.geometry())
|
root.setGeometry(self._rootItem.geometry())
|
||||||
|
@ -160,6 +162,11 @@ class QmlInstantEngine(QQmlApplicationEngine):
|
||||||
@Slot(str)
|
@Slot(str)
|
||||||
def onFileChanged(self, filepath):
|
def onFileChanged(self, filepath):
|
||||||
""" Handle changes in a watched file. """
|
""" Handle changes in a watched file. """
|
||||||
|
if filepath not in self._watchedFiles:
|
||||||
|
# could happen if a file has just been reloaded
|
||||||
|
# and has not been re-added yet to the watched files
|
||||||
|
return
|
||||||
|
|
||||||
if self._verbose:
|
if self._verbose:
|
||||||
print("Source file changed : ", filepath)
|
print("Source file changed : ", filepath)
|
||||||
# Clear the QQuickEngine cache
|
# Clear the QQuickEngine cache
|
||||||
|
@ -177,9 +184,10 @@ class QmlInstantEngine(QQmlApplicationEngine):
|
||||||
|
|
||||||
self.reload()
|
self.reload()
|
||||||
|
|
||||||
# Finally, read the modified file to the watch system
|
# Finally, re-add the modified file to the watch system
|
||||||
self.addFile(filepath)
|
# after a short cooldown to avoid multiple consecutive reloads
|
||||||
|
QTimer.singleShot(200, lambda: self.addFile(filepath))
|
||||||
|
|
||||||
def reload(self):
|
def reload(self):
|
||||||
print("Reloading ", self._sourceFile)
|
print("Reloading {}".format(self._sourceFile))
|
||||||
self.load(self._sourceFile)
|
self.load(self._sourceFile)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue