From 89ff52c8ee9f782a73b86acbbb16ff3c16013c0a Mon Sep 17 00:00:00 2001 From: Tomas Zigo Date: Wed, 20 Dec 2023 21:05:32 +0100 Subject: [PATCH] wxGUI/history: add SearchCtrl widget --- gui/wxpython/history/browser.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/gui/wxpython/history/browser.py b/gui/wxpython/history/browser.py index c782767feb6..b76ebfe1b51 100644 --- a/gui/wxpython/history/browser.py +++ b/gui/wxpython/history/browser.py @@ -22,6 +22,7 @@ from core.gcmd import GError, GException 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 @@ -57,11 +58,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 ) @@ -90,6 +103,19 @@ 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) + self._tree.ExpandAll() + else: + self._tree.SetModel(model) + def UpdateHistoryModelFromScratch(self): """Update the model from scratch and refresh the tree""" self._model.CreateModel()