Skip to content

Commit 89ff52c

Browse files
committed
wxGUI/history: add SearchCtrl widget
1 parent ea8f3ea commit 89ff52c

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

gui/wxpython/history/browser.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from core.gcmd import GError, GException
2323
from gui_core.forms import GUI
2424
from gui_core.treeview import CTreeView
25+
from gui_core.wrap import SearchCtrl
2526
from history.tree import HistoryBrowserTree
2627

2728
from grass.pydispatch.signal import Signal
@@ -57,11 +58,23 @@ def __init__(
5758
lambda cmd: self.UpdateHistoryModelByCommand(cmd)
5859
)
5960

61+
self.search = SearchCtrl(self)
62+
self.search.SetDescriptiveText(_("Search"))
63+
self.search.ShowCancelButton(True)
64+
self.search.Bind(wx.EVT_TEXT, lambda evt: self.Filter(evt.GetString()))
65+
self.search.Bind(wx.EVT_SEARCHCTRL_CANCEL_BTN, lambda evt: self.Filter(""))
66+
6067
self._layout()
6168

6269
def _layout(self):
6370
"""Dialog layout"""
6471
sizer = wx.BoxSizer(wx.VERTICAL)
72+
sizer.Add(
73+
self.search,
74+
proportion=0,
75+
flag=wx.ALL | wx.EXPAND,
76+
border=5,
77+
)
6578
sizer.Add(
6679
self._tree, proportion=1, flag=wx.EXPAND | wx.LEFT | wx.RIGHT, border=5
6780
)
@@ -90,6 +103,19 @@ def _getSelectedNode(self):
90103
def _refreshTree(self):
91104
self._tree.SetModel(self._model.GetModel())
92105

106+
def Filter(self, text):
107+
"""Filter history
108+
109+
:param str text: text string
110+
"""
111+
model = self._model.GetModel()
112+
if text:
113+
model = self._model.model.Filtered(key=["command"], value=text)
114+
self._tree.SetModel(model)
115+
self._tree.ExpandAll()
116+
else:
117+
self._tree.SetModel(model)
118+
93119
def UpdateHistoryModelFromScratch(self):
94120
"""Update the model from scratch and refresh the tree"""
95121
self._model.CreateModel()

0 commit comments

Comments
 (0)