Skip to content

Commit

Permalink
wxGUI/history: Add time period branching to history browser tree (#3622)
Browse files Browse the repository at this point in the history
  • Loading branch information
lindakarlovska authored May 2, 2024
1 parent 9dc6fc6 commit a351e5e
Show file tree
Hide file tree
Showing 4 changed files with 428 additions and 139 deletions.
46 changes: 46 additions & 0 deletions gui/wxpython/core/treemodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,52 @@ def match(self, key, value):
return False


class DictFilterNode(DictNode):
"""Node which has data in a form of dictionary and can be filtered."""

def __init__(self, data=None):
super().__init__(data=data)

def match(self, method="exact", **kwargs):
"""Method used for searching according to given parameters.
:param str method: 'exact' for exact match or
'filtering' for filtering by type/name
:param kwargs key-value to be matched, filtering method uses 'type' and 'name'
:return bool: True if an entry matching given parameters was found
"""
if not kwargs:
return False

if method == "exact":
return self._match_exact(**kwargs)
elif method == "filtering":
return self._match_filtering(**kwargs)

def _match_exact(self, **kwargs):
"""Match method for exact matching."""
for key, value in kwargs.items():
if not (key in self.data and self.data[key] == value):
return False
return True

def _match_filtering(self, **kwargs):
"""Match method for filtering."""
if (
"type" in kwargs
and "type" in self.data
and kwargs["type"] != self.data["type"]
):
return False
if (
"name" in kwargs
and "name" in self.data
and not kwargs["name"].search(self.data["name"])
):
return False
return True


class ModuleNode(DictNode):
"""Node representing module."""

Expand Down
34 changes: 2 additions & 32 deletions gui/wxpython/datacatalog/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
)
from gui_core.dialogs import TextEntryDialog
from core.giface import StandaloneGrassInterface
from core.treemodel import TreeModel, DictNode
from core.treemodel import TreeModel, DictFilterNode
from gui_core.treeview import TreeView
from gui_core.wrap import Menu
from datacatalog.dialogs import CatalogReprojectionDialog
Expand Down Expand Up @@ -171,7 +171,7 @@ def OnOK(self, event):
self.EndModal(wx.ID_OK)


class DataCatalogNode(DictNode):
class DataCatalogNode(DictFilterNode):
"""Node representing item in datacatalog."""

def __init__(self, data=None):
Expand All @@ -197,36 +197,6 @@ def label(self):

return _("{name}").format(**data)

def match(self, method="exact", **kwargs):
"""Method used for searching according to given parameters.
:param method: 'exact' for exact match or 'filtering' for filtering by type/name
:param kwargs key-value to be matched, filtering method uses 'type' and 'name'
where 'name' is compiled regex
"""
if not kwargs:
return False

if method == "exact":
for key, value in kwargs.items():
if not (key in self.data and self.data[key] == value):
return False
return True
# for filtering
if (
"type" in kwargs
and "type" in self.data
and kwargs["type"] != self.data["type"]
):
return False
if (
"name" in kwargs
and "name" in self.data
and not kwargs["name"].search(self.data["name"])
):
return False
return True


class DataCatalogTree(TreeView):
"""Tree structure visualizing and managing grass database.
Expand Down
Loading

0 comments on commit a351e5e

Please sign in to comment.