Skip to content

Commit

Permalink
wxGUI/history: add SearchCtrl widget
Browse files Browse the repository at this point in the history
  • Loading branch information
tmszi committed Dec 20, 2023
1 parent ea8f3ea commit 89ff52c
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions gui/wxpython/history/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 89ff52c

Please sign in to comment.