Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 27 additions & 8 deletions gui/wxpython/datacatalog/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ def __init__(
self.UpdateCurrentDbLocationMapsetNode()
self._lastWatchdogUpdate = gs.clock()
self._updateMapsetWhenIdle = None
self._watchingMapsetEnabled = False

# mapset watchdog
self._mapset_watchdog = MapsetWatchdog(
Expand Down Expand Up @@ -301,13 +302,7 @@ def __init__(
)
self.startEdit.connect(self.OnStartEditLabel)
self.endEdit.connect(self.OnEditLabel)
self.Bind(
EVT_UPDATE_MAPSET, lambda evt: self._onWatchdogMapsetReload(evt.src_path)
)
self.Bind(wx.EVT_IDLE, self._onUpdateMapsetWhenIdle)
self.Bind(
EVT_CURRENT_MAPSET_CHANGED, lambda evt: self._updateAfterMapsetChanged()
)
self.EnableWatchingMapset()

def _resetSelectVariables(self):
"""Reset variables related to item selection."""
Expand Down Expand Up @@ -623,6 +618,7 @@ def _onWatchdogMapsetReload(self, event_path):
self._lastWatchdogUpdate = time
if (time_diff) < 0.5:
self._updateMapsetWhenIdle = event_path
self.DisableWatchingMapset()
return
mapset_path = os.path.dirname(os.path.dirname(os.path.abspath(event_path)))
location_path = os.path.dirname(os.path.abspath(mapset_path))
Expand All @@ -642,9 +638,31 @@ def UpdateAfterMapsetChanged(self):
If watchdog is active, updating is skipped here
to avoid double updating.
"""
if not watchdog_used:
if not (watchdog_used or self._watchingMapsetEnabled):
self._updateAfterMapsetChanged()

def DisableWatchingMapset(self):
"""Disable watching of current mapset folder for changes with watchdog."""
if not self._watchingMapsetEnabled:
return
self._watchingMapsetEnabled = False
self.Unbind(EVT_UPDATE_MAPSET)
self.Unbind(wx.EVT_IDLE)
self.Unbind(EVT_CURRENT_MAPSET_CHANGED)

def EnableWatchingMapset(self):
"""Enable watching of current mapset folder for changes with watchdog."""
if self._watchingMapsetEnabled:
return
self._watchingMapsetEnabled = True
self.Bind(
EVT_UPDATE_MAPSET, lambda evt: self._onWatchdogMapsetReload(evt.src_path)
)
self.Bind(wx.EVT_IDLE, self._onUpdateMapsetWhenIdle)
self.Bind(
EVT_CURRENT_MAPSET_CHANGED, lambda evt: self._updateAfterMapsetChanged()
)

def GetDbNode(self, grassdb, location=None, mapset=None, map=None, map_type=None):
"""Returns node representing db/location/mapset/map or None if not found."""
grassdb_nodes = self._model.SearchNodes(name=grassdb, type="grassdb")
Expand Down Expand Up @@ -1819,6 +1837,7 @@ def _updateAfterGrassdbChanged(
# instead the watchdog handler takes care of refreshing tree
if (
watchdog_used
and self._watchingMapsetEnabled
and grassdb == self.current_grassdb_node.data["name"]
and location == self.current_location_node.data["name"]
and mapset == self.current_mapset_node.data["name"]
Expand Down
Loading