Skip to content

Commit

Permalink
wxGUI/history: add SearchCtrl widget with the ability to search the h…
Browse files Browse the repository at this point in the history
…istory tree (#3309)
  • Loading branch information
tmszi committed Jan 5, 2024
1 parent bd0e406 commit a6fe522
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions gui/wxpython/history/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
)
from gui_core.forms import GUI
from gui_core.treeview import CTreeView
from gui_core.wrap import SearchCtrl
from history.tree import HistoryBrowserTree

from grass.pydispatch.signal import Signal
Expand Down Expand Up @@ -62,11 +63,23 @@ def __init__(
lambda cmd: self.UpdateHistoryModelByCommand(cmd)
)

self.search = SearchCtrl(self)
self.search.SetDescriptiveText(_("Search"))
self.search.ShowCancelButton(True)
self.search.Bind(wx.EVT_TEXT, lambda evt: self.Filter(evt.GetString()))
self.search.Bind(wx.EVT_SEARCHCTRL_CANCEL_BTN, lambda evt: self.Filter(""))

self._layout()

def _layout(self):
"""Dialog layout"""
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(
self.search,
proportion=0,
flag=wx.ALL | wx.EXPAND,
border=5,
)
sizer.Add(
self._tree, proportion=1, flag=wx.EXPAND | wx.LEFT | wx.RIGHT, border=5
)
Expand Down Expand Up @@ -95,6 +108,18 @@ def _getSelectedNode(self):
def _refreshTree(self):
self._tree.SetModel(self._model.GetModel())

def Filter(self, text):
"""Filter history
:param str text: text string
"""
model = self._model.GetModel()
if text:
model = self._model.model.Filtered(key=["command"], value=text)
self._tree.SetModel(model)
else:
self._tree.SetModel(model)

def UpdateHistoryModelFromScratch(self):
"""Update the model from scratch and refresh the tree"""
self._model.CreateModel()
Expand Down

0 comments on commit a6fe522

Please sign in to comment.