From 89cba88aea7e1677bcd66f545eae62b42ed91054 Mon Sep 17 00:00:00 2001 From: anapnoe <124302297+anapnoe@users.noreply.github.com> Date: Thu, 3 Oct 2024 13:13:40 +0300 Subject: [PATCH] Register category options in a custom position. --- modules/options.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/modules/options.py b/modules/options.py index 2a78a825ee2..8fb8c86e821 100644 --- a/modules/options.py +++ b/modules/options.py @@ -326,11 +326,20 @@ class OptionsCategories: def __init__(self): self.mapping = {} - def register_category(self, category_id, label): + def register_category(self, category_id, label, position=None): if category_id in self.mapping: return category_id - self.mapping[category_id] = OptionsCategory(category_id, label) + # Use a dictionary to hold the categories temporarily + temp_mapping = self.mapping.copy() + # Insert the new category at the specified position + if position is not None and position == 0: + temp_mapping = {category_id: OptionsCategory(category_id, label), **temp_mapping} + else: + temp_mapping[category_id] = OptionsCategory(category_id, label) + + # Update the mapping + self.mapping = temp_mapping categories = OptionsCategories()