[PATCH] IntelFsp2Pkg: Add search function for Config Editor


 

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3482

This patch adds a search function in the Config Editor GUI at
the top right corner. Once users key in the words to search,
it will look for the option containing the string in the
same page and display it.

Cc: Maurice Ma <maurice.ma@...>
Cc: Nate DeSimone <nathaniel.l.desimone@...>
Cc: Star Zeng <star.zeng@...>
Cc: Chasel Chiu <chasel.chiu@...>
Signed-off-by: Loo Tung Lun <tung.lun.loo@...>
---
IntelFsp2Pkg/Tools/ConfigEditor/ConfigEditor.py | 31 +++++++++++++++++++++=
++++++++++
IntelFsp2Pkg/Tools/ConfigEditor/GenYamlCfg.py | 25 +++++++++++++++++++--=
----
2 files changed, 50 insertions(+), 6 deletions(-)

diff --git a/IntelFsp2Pkg/Tools/ConfigEditor/ConfigEditor.py b/IntelFsp2Pkg=
/Tools/ConfigEditor/ConfigEditor.py
index a7f79bbc96..d58df385b1 100644
--- a/IntelFsp2Pkg/Tools/ConfigEditor/ConfigEditor.py
+++ b/IntelFsp2Pkg/Tools/ConfigEditor/ConfigEditor.py
@@ -811,6 +811,7 @@ class application(tkinter.Frame):
self.org_cfg_data_bin =3D None=0D
self.in_left =3D state()=0D
self.in_right =3D state()=0D
+ self.search_text =3D ''=0D
=0D
# Check if current directory contains a file with a .yaml extensio=
n=0D
# if not default self.last_dir to a Platform directory where it is=
=0D
@@ -835,6 +836,23 @@ class application(tkinter.Frame):
=0D
root.geometry("1200x800")=0D
=0D
+ # Search string=0D
+ fram =3D tkinter.Frame(root)=0D
+ # adding label to search box=0D
+ tkinter.Label(fram, text=3D'Text to find:').pack(side=3Dtkinter.LE=
FT)=0D
+ # adding of single line text box=0D
+ self.edit =3D tkinter.Entry(fram, width=3D30)=0D
+ # positioning of text box=0D
+ self.edit.pack(=0D
+ side=3Dtkinter.LEFT, fill=3Dtkinter.BOTH, expand=3D1, padx=3D(=
4, 4))=0D
+ # setting focus=0D
+ self.edit.focus_set()=0D
+ # adding of search button=0D
+ butt =3D tkinter.Button(fram, text=3D'Search', relief=3Dtkinter.GR=
OOVE,=0D
+ command=3Dself.search_bar)=0D
+ butt.pack(side=3Dtkinter.RIGHT, padx=3D(4, 4))=0D
+ fram.pack(side=3Dtkinter.TOP, anchor=3Dtkinter.SE)=0D
+=0D
paned =3D ttk.Panedwindow(root, orient=3Dtkinter.HORIZONTAL)=0D
paned.pack(fill=3Dtkinter.BOTH, expand=3DTrue, padx=3D(4, 4))=0D
=0D
@@ -943,6 +961,12 @@ class application(tkinter.Frame):
"Unsupported file '%s' !" % path)=0D
return=0D
=0D
+ def search_bar(self):=0D
+ # get data from text box=0D
+ self.search_text =3D self.edit.get()=0D
+ # Clear the page and update it according to search value=0D
+ self.refresh_config_data_page()=0D
+=0D
def set_object_name(self, widget, name):=0D
self.conf_list[id(widget)] =3D name=0D
=0D
@@ -999,6 +1023,12 @@ class application(tkinter.Frame):
widget.grid()=0D
widget.configure(state=3D'normal')=0D
=0D
+ if visible and self.search_text !=3D '':=0D
+ name =3D item['name']=0D
+ if name.lower().find(self.search_text.lower()) =3D=3D -1:=0D
+ visible =3D False=0D
+ widget.grid_remove()=0D
+=0D
return visible=0D
=0D
def update_widgets_visibility_on_page(self):=0D
@@ -1377,6 +1407,7 @@ class application(tkinter.Frame):
return None=0D
else:=0D
path =3D name=0D
+=0D
item =3D self.cfg_data_obj.get_item_by_path(path)=0D
return item=0D
=0D
diff --git a/IntelFsp2Pkg/Tools/ConfigEditor/GenYamlCfg.py b/IntelFsp2Pkg/T=
ools/ConfigEditor/GenYamlCfg.py
index 25fd9c547e..0d9505b97f 100644
--- a/IntelFsp2Pkg/Tools/ConfigEditor/GenYamlCfg.py
+++ b/IntelFsp2Pkg/Tools/ConfigEditor/GenYamlCfg.py
@@ -583,6 +583,7 @@ class CGenYamlCfg:
self._mode =3D ''=0D
self._debug =3D False=0D
self._macro_dict =3D {}=0D
+ self.bin_offset =3D []=0D
self.initialize()=0D
=0D
def initialize(self):=0D
@@ -1301,10 +1302,15 @@ option format '%s' !" % option)
if 'indx' not in cfgs:=0D
return=0D
act_cfg =3D self.get_item_by_index(cfgs['indx'])=0D
- if force or act_cfg['value'] =3D=3D '':=0D
+ actual_offset =3D act_cfg['offset'] - struct_info['offset']=0D
+ set_value =3D True=0D
+ for each in self.bin_offset:=0D
+ if actual_offset in range(each[0], (each[0] + each[2]) * 8=
):=0D
+ if each[1] < 0:=0D
+ set_value =3D False=0D
+ if set_value and force or act_cfg['value'] =3D=3D '':=0D
value =3D get_bits_from_bytes(full_bytes,=0D
- act_cfg['offset'] -=0D
- struct_info['offset'],=0D
+ actual_offset,=0D
act_cfg['length'])=0D
act_val =3D act_cfg['value']=0D
if act_val =3D=3D '':=0D
@@ -1424,8 +1430,8 @@ for '%s' !" % (act_cfg['value'], act_cfg['path']))
% seg[0])=0D
bin_segs.append([seg[0], pos, seg[2]])=0D
else:=0D
- raise Exception("Could not find '%s' in binary !"=0D
- % seg[0])=0D
+ bin_segs.append([seg[0], -1, seg[2]])=0D
+ continue=0D
=0D
return bin_segs=0D
=0D
@@ -1433,8 +1439,15 @@ for '%s' !" % (act_cfg['value'], act_cfg['path']))
# get cfg bin length=0D
cfg_bins =3D bytearray()=0D
bin_segs =3D self.get_bin_segment(bin_data)=0D
+ Dummy_offset =3D 0=0D
for each in bin_segs:=0D
- cfg_bins.extend(bin_data[each[1]:each[1] + each[2]])=0D
+ if each[1] !=3D -1:=0D
+ self.bin_offset.append([Dummy_offset, each[1], each[2]])=0D
+ cfg_bins.extend(bin_data[each[1]:each[1] + each[2]])=0D
+ else:=0D
+ self.bin_offset.append([Dummy_offset, each[1], each[2]])=0D
+ cfg_bins.extend(bytearray(each[2]))=0D
+ Dummy_offset +=3D each[2]=0D
return cfg_bins=0D
=0D
def save_current_to_bin(self):=0D
--=20
2.28.0.windows.1

Join devel@edk2.groups.io to automatically receive all group messages.