Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wxGUI/history: Add time period branching to history browser tree #3622

Merged
Show file tree
Hide file tree
Changes from 6 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
46 changes: 46 additions & 0 deletions gui/wxpython/core/treemodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,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 @@ -37,7 +37,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 @@ -170,7 +170,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 @@ -196,36 +196,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
Loading