diff options
author | Candice Bentéjac <candice.bentejac@gmail.com> | 2022-10-31 14:08:51 +0300 |
---|---|---|
committer | Candice Bentéjac <candice.bentejac@gmail.com> | 2022-10-31 14:08:51 +0300 |
commit | 72e1567a9fe647f576826c416ec7f65636edd5de (patch) | |
tree | c7c85ab9abe2a3261392cf4fdaf543b6f6247827 | |
parent | 7593254ec096385e6f4132bce3cf834f0a59d523 (diff) |
[ui] Add a button to disable/enable the file watcher
By default, the file watcher polls every single node's file every 5
seconds, independently from their status. This commit adds a button
in the GraphEditor to disable or enable the file watcher at will.
-rw-r--r-- | meshroom/ui/graph.py | 24 | ||||
-rwxr-xr-x | meshroom/ui/qml/main.qml | 47 |
2 files changed, 71 insertions, 0 deletions
diff --git a/meshroom/ui/graph.py b/meshroom/ui/graph.py index 0abf173b..2aa28f19 100644 --- a/meshroom/ui/graph.py +++ b/meshroom/ui/graph.py @@ -23,6 +23,11 @@ from meshroom.ui import commands from meshroom.ui.utils import makeProperty +class PollerRefreshStatus(Enum): + AUTO_ENABLED = 0 + DISABLED = 1 + + class FilesModTimePollerThread(QObject): """ Thread responsible for non-blocking polling of last modification times of a list of files. @@ -38,6 +43,7 @@ class FilesModTimePollerThread(QObject): self._stopFlag = Event() self._refreshInterval = 5 # refresh interval in seconds self._files = [] + self._filePollerRefresh = PollerRefreshStatus.AUTO_ENABLED def start(self, files=None): """ Start polling thread. @@ -45,6 +51,8 @@ class FilesModTimePollerThread(QObject): Args: files: the list of files to monitor """ + if self._filePollerRefresh is not PollerRefreshStatus.AUTO_ENABLED: + return if self._thread: # thread already running, return return @@ -88,6 +96,15 @@ class FilesModTimePollerThread(QObject): if files == self._files: self.timesAvailable.emit(times) + def onFilePollerRefreshChanged(self, value): + self._filePollerRefresh = PollerRefreshStatus(value) + if self._filePollerRefresh is PollerRefreshStatus.AUTO_ENABLED: + self.start() + else: + self.stop() + + filePollerRefresh = Property(int, lambda self: self._filePollerRefresh.value, constant=True) + class ChunksMonitor(QObject): """ @@ -107,6 +124,8 @@ class ChunksMonitor(QObject): self._filesTimePoller.start() self.setChunks(chunks) + self.filePollerRefreshChanged.connect(self._filesTimePoller.onFilePollerRefreshChanged) + def setChunks(self, chunks): """ Set the list of chunks to monitor. """ self.chunks = chunks @@ -135,6 +154,8 @@ class ChunksMonitor(QObject): if fileModTime != chunk.statusFileLastModTime: chunk.updateStatusFromCache() + filePollerRefreshChanged = Signal(int) + filePollerRefresh = Property(int, lambda self: self._filesTimePoller.filePollerRefresh, notify=filePollerRefreshChanged) class GraphLayout(QObject): """ @@ -278,6 +299,7 @@ class UIGraph(QObject): self._hoveredNode = None self.computeStatusChanged.connect(self.updateLockedUndoStack) + self.filePollerRefreshChanged.connect(self._chunksMonitor.filePollerRefreshChanged) def setGraph(self, g): """ Set the internal graph. """ @@ -934,3 +956,5 @@ class UIGraph(QObject): hoveredNodeChanged = Signal() # Currently hovered node hoveredNode = makeProperty(QObject, "_hoveredNode", hoveredNodeChanged, resetOnDestroy=True) + filePollerRefreshChanged = Signal(int) + filePollerRefresh = Property(int, lambda self: self._chunksMonitor.filePollerRefresh, notify=filePollerRefreshChanged) diff --git a/meshroom/ui/qml/main.qml b/meshroom/ui/qml/main.qml index 22550f80..84f5779d 100755 --- a/meshroom/ui/qml/main.qml +++ b/meshroom/ui/qml/main.qml @@ -903,6 +903,53 @@ ApplicationWindow { enabled: !updatingStatus && !_reconstruction.computingLocally } MaterialToolButton { + id: filePollerRefreshStatus + text: _reconstruction.filePollerRefresh == 0 ? MaterialIcons.sync : MaterialIcons.sync_disabled + ToolTip.text: "Set File Refresh Status" + ToolTip.visible: hovered + font.pointSize: 11 + padding: 2 + onClicked: { + refreshFilesMenu.open() + } + enabled: true + Menu { + id: refreshFilesMenu + y: parent.height + x: -width + parent.width + MenuItem { + id: enableAutoRefresh + text: "Enable Auto-Refresh" + checkable: true + checked: _reconstruction.filePollerRefresh == 0 + onToggled: { + if (checked) { + disableAutoRefresh.checked = false + _reconstruction.filePollerRefreshChanged(0) + } + // Prevents cases where the user unchecks the currently checked option + enableAutoRefresh.checked = true + filePollerRefreshStatus.text = MaterialIcons.sync + } + } + MenuItem { + id: disableAutoRefresh + text: "Disable Auto-Refresh" + checkable: true + checked: _reconstruction.filePollerRefresh == 1 + onToggled: { + if (checked) { + enableAutoRefresh.checked = false + _reconstruction.filePollerRefreshChanged(1) + } + // Prevents cases where the user unchecks the currently checked option + disableAutoRefresh.checked = true + filePollerRefreshStatus.text = MaterialIcons.sync_disabled + } + } + } + } + MaterialToolButton { text: MaterialIcons.more_vert font.pointSize: 11 padding: 2 |