docstr: Reorder settings so that:
      - all items related to section always go together
      - all sections belonging to a category go together
      - sections inside a category are ordered alphabetically
      - categories are ordered by creation order
  
  Category is a superset of sections: for category "postprocessing" there could be multiple sections: "face restoration", "upscaling".
  
  This function also changes items' category_id so that all items belonging to a section have the same category_id.
docstr_tok: ["Reorder","settings","so","that",":","-","all","items","related","to","section","always","go","together","-","all","sections","belonging","to","a","category","go","together","-","sections","inside","a","category","are","ordered","alphabetically","-","categories","are","ordered","by","creation","order","Category","is","a","superset","of","sections",":","for","category","``","postprocessing","''","there","could","be","multiple","sections",":","``","face","restoration","''",",","``","upscaling","''",".","This","function","also","changes","items","'","category_id","so","that","all","items","belonging","to","a","section","have","the","same","category_id","."]
code: def reorder(self):
      """Reorder settings so that:
          - all items related to section always go together
          - all sections belonging to a category go together
          - sections inside a category are ordered alphabetically
          - categories are ordered by creation order
  
      Category is a superset of sections: for category "postprocessing" there could be multiple sections: "face restoration", "upscaling".
  
      This function also changes items' category_id so that all items belonging to a section have the same category_id.
      """
  
      category_ids = {}
      section_categories = {}
  
      settings_items = self.data_labels.items()
      for _, item in settings_items:
          if item.section not in section_categories:
              section_categories[item.section] = item.category_id
  
      for _, item in settings_items:
          item.category_id = section_categories.get(item.section)
  
      for category_id in categories.mapping:
          if category_id not in category_ids:
              category_ids[category_id] = len(category_ids)
  
      def sort_key(x):
          item: OptionInfo = x[1]
          category_order = category_ids.get(
              item.category_id, len(category_ids)
          )
          section_order = item.section[1]
  
          return category_order, section_order
  
      self.data_labels = dict(sorted(settings_items, key=sort_key))
  
imports: import json
  import sys
  from dataclasses import dataclass
  import gradio
  from modules import errors
  from modules.shared_cmd_options import cmd_opts
label_desc: Use image node_id 12 for calling the Options obj's underlying member method code with example usage: obj.reorder() and returns: category_order,  section_order