]> git.proxmox.com Git - mirror_edk2.git/commitdiff
IntelFsp2Pkg: Add search function for Config Editor
authorLoo, Tung Lun <tung.lun.loo@intel.com>
Tue, 13 Jul 2021 00:12:08 +0000 (08:12 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Thu, 15 Jul 2021 14:21:14 +0000 (14:21 +0000)
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3482

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. It also includes a README for this
function.

Cc: Maurice Ma <maurice.ma@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Chasel Chiu <chasel.chiu@intel.com>
Signed-off-by: Loo Tung Lun <tung.lun.loo@intel.com>
Reviewed-by: Chasel Chiu <chasel.chiu@intel.com>
IntelFsp2Pkg/Tools/ConfigEditor/ConfigEditor.py
IntelFsp2Pkg/Tools/ConfigEditor/GenYamlCfg.py
IntelFsp2Pkg/Tools/UserManuals/ConfigEditorUserManual.md

index a7f79bbc961587ebfd8f4ddb8e0cfe335b72326d..008c7d7a160ad863037dde4955959a0b7b8c8009 100644 (file)
@@ -811,6 +811,8 @@ class application(tkinter.Frame):
         self.org_cfg_data_bin = None\r
         self.in_left = state()\r
         self.in_right = state()\r
+        self.search_text = ''\r
+        self.binseg_dict = {}\r
 \r
         # Check if current directory contains a file with a .yaml extension\r
         # if not default self.last_dir to a Platform directory where it is\r
@@ -835,6 +837,23 @@ class application(tkinter.Frame):
 \r
         root.geometry("1200x800")\r
 \r
+        # Search string\r
+        fram = tkinter.Frame(root)\r
+        # adding label to search box\r
+        tkinter.Label(fram, text='Text to find:').pack(side=tkinter.LEFT)\r
+        # adding of single line text box\r
+        self.edit = tkinter.Entry(fram, width=30)\r
+        # positioning of text box\r
+        self.edit.pack(\r
+            side=tkinter.LEFT, fill=tkinter.BOTH, expand=1, padx=(4, 4))\r
+        # setting focus\r
+        self.edit.focus_set()\r
+        # adding of search button\r
+        butt = tkinter.Button(fram, text='Search', relief=tkinter.GROOVE,\r
+                              command=self.search_bar)\r
+        butt.pack(side=tkinter.RIGHT, padx=(4, 4))\r
+        fram.pack(side=tkinter.TOP, anchor=tkinter.SE)\r
+\r
         paned = ttk.Panedwindow(root, orient=tkinter.HORIZONTAL)\r
         paned.pack(fill=tkinter.BOTH, expand=True, padx=(4, 4))\r
 \r
@@ -943,6 +962,12 @@ class application(tkinter.Frame):
                                      "Unsupported file '%s' !" % path)\r
                 return\r
 \r
+    def search_bar(self):\r
+        # get data from text box\r
+        self.search_text = self.edit.get()\r
+        # Clear the page and update it according to search value\r
+        self.refresh_config_data_page()\r
+\r
     def set_object_name(self, widget, name):\r
         self.conf_list[id(widget)] = name\r
 \r
@@ -976,14 +1001,18 @@ class application(tkinter.Frame):
                                               'units')\r
 \r
     def update_visibility_for_widget(self, widget, args):\r
-\r
         visible = True\r
         item = self.get_config_data_item_from_widget(widget, True)\r
         if item is None:\r
             return visible\r
         elif not item:\r
             return visible\r
-\r
+        if self.cfg_data_obj.binseg_dict:\r
+            str_split = item['path'].split('.')\r
+            if self.cfg_data_obj.binseg_dict[str_split[-2]] == -1:\r
+                visible = False\r
+                widget.grid_remove()\r
+                return visible\r
         result = 1\r
         if item['condition']:\r
             result = self.evaluate_condition(item)\r
@@ -999,6 +1028,12 @@ class application(tkinter.Frame):
                 widget.grid()\r
                 widget.configure(state='normal')\r
 \r
+        if visible and self.search_text != '':\r
+            name = item['name']\r
+            if name.lower().find(self.search_text.lower()) == -1:\r
+                visible = False\r
+                widget.grid_remove()\r
+\r
         return visible\r
 \r
     def update_widgets_visibility_on_page(self):\r
@@ -1134,6 +1169,7 @@ class application(tkinter.Frame):
             self.fsp_version = '2.X'\r
         else:\r
             self.fsp_version = '1.X'\r
+\r
         return gen_cfg_data\r
 \r
     def about(self):\r
@@ -1377,6 +1413,7 @@ class application(tkinter.Frame):
                 return None\r
         else:\r
             path = name\r
+\r
         item = self.cfg_data_obj.get_item_by_path(path)\r
         return item\r
 \r
index 25fd9c547efaffe6d22a7e4275daa3e19df775b5..611a9a9c726602fd0f338d919ea4407101953f55 100644 (file)
@@ -583,6 +583,8 @@ class CGenYamlCfg:
         self._mode = ''\r
         self._debug = False\r
         self._macro_dict = {}\r
+        self.bin_offset = []\r
+        self.binseg_dict = {}\r
         self.initialize()\r
 \r
     def initialize(self):\r
@@ -1301,10 +1303,15 @@ option format '%s' !" % option)
             if 'indx' not in cfgs:\r
                 return\r
             act_cfg = self.get_item_by_index(cfgs['indx'])\r
-            if force or act_cfg['value'] == '':\r
+            actual_offset = act_cfg['offset'] - struct_info['offset']\r
+            set_value = True\r
+            for each in self.bin_offset:\r
+                if actual_offset in range(each[0], (each[0] + each[2]) * 8):\r
+                    if each[1] < 0:\r
+                        set_value = False\r
+            if set_value and force or act_cfg['value'] == '':\r
                 value = get_bits_from_bytes(full_bytes,\r
-                                            act_cfg['offset'] -\r
-                                            struct_info['offset'],\r
+                                            actual_offset,\r
                                             act_cfg['length'])\r
                 act_val = act_cfg['value']\r
                 if act_val == '':\r
@@ -1423,9 +1430,11 @@ for '%s' !" % (act_cfg['value'], act_cfg['path']))
                               "in binary, the 1st instance will be used !"\r
                               % seg[0])\r
                 bin_segs.append([seg[0], pos, seg[2]])\r
+                self.binseg_dict[seg[0]] = pos\r
             else:\r
-                raise Exception("Could not find '%s' in binary !"\r
-                                % seg[0])\r
+                bin_segs.append([seg[0], -1, seg[2]])\r
+                self.binseg_dict[seg[0]] = -1\r
+                continue\r
 \r
         return bin_segs\r
 \r
@@ -1433,8 +1442,17 @@ for '%s' !" % (act_cfg['value'], act_cfg['path']))
         # get cfg bin length\r
         cfg_bins = bytearray()\r
         bin_segs = self.get_bin_segment(bin_data)\r
+        Dummy_offset = 0\r
         for each in bin_segs:\r
-            cfg_bins.extend(bin_data[each[1]:each[1] + each[2]])\r
+            if each[1] != -1:\r
+                self.bin_offset.append([Dummy_offset, each[1], each[2]])\r
+                cfg_bins.extend(bin_data[each[1]:each[1] + each[2]])\r
+            else:\r
+                string = each[0] + ' is not availabe.'\r
+                messagebox.showinfo('', string)\r
+                self.bin_offset.append([Dummy_offset, each[1], each[2]])\r
+                cfg_bins.extend(bytearray(each[2]))\r
+            Dummy_offset += each[2]\r
         return cfg_bins\r
 \r
     def save_current_to_bin(self):\r
@@ -1447,12 +1465,15 @@ for '%s' !" % (act_cfg['value'], act_cfg['path']))
         cfg_off = 0\r
         for each in bin_segs:\r
             length = each[2]\r
-            bin_data[each[1]:each[1] + length] = cfg_bins[cfg_off:\r
-                                                          cfg_off\r
-                                                          + length]\r
-            cfg_off += length\r
-        print('Patched the loaded binary successfully !')\r
+            if each[1] != -1:\r
+                bin_data[each[1]:each[1] + length] = cfg_bins[cfg_off:\r
+                                                              cfg_off\r
+                                                              + length]\r
+                cfg_off += length\r
+            else:\r
+                cfg_off += length\r
 \r
+        print('Patched the loaded binary successfully !')\r
         return bin_data\r
 \r
     def load_default_from_bin(self, bin_data):\r
@@ -1469,6 +1490,7 @@ for '%s' !" % (act_cfg['value'], act_cfg['path']))
             if not top:\r
                 raise Exception("Invalid configuration path '%s' !"\r
                                 % path)\r
+\r
         return self.get_field_value(top)\r
 \r
     def generate_binary(self, bin_file_name, path=''):\r
index 08a815133c3f8449fc7260f167a87455c460085c..da21df2432420e6bfbdf219b655838dce92b3f00 100644 (file)
@@ -40,6 +40,10 @@ This option generates a new configuration delta file for the newly changed value
 ## 8. Save Full Config Data to Delta File\r
 This option saves all the changed configuration values into a Delta file.\r
 \r
+## 9. Search feature\r
+This feature helps the user to easily find any configuration item they are looking for in ConfigEditor.\r
+A text search box is available on the Top Right Corner of ConfigEditor. To use this feature the user should type the name or a key word of the item they want to search in the text box and then click on the "Search" button. This will display all the items which contains that particular word searched by the user.\r
+\r
 ## Running Configuration Editor:\r
 \r
    **python ConfigEditor.py**\r