Skip to content

Commit

Permalink
Register category options in a custom position.
Browse files Browse the repository at this point in the history
  • Loading branch information
anapnoe authored Oct 3, 2024
1 parent 82a973c commit 89cba88
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions modules/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 89cba88

Please sign in to comment.