Commit ca2b7a56 authored by Roman Alifanov's avatar Roman Alifanov

new module structure

parent 34825230
- name: "Gnome" - name: "Gnome"
icon: preferences-desktop-display-symbolic
weight: 30 weight: 30
pages:
- name: "Appearance"
icon: preferences-desktop-display-symbolic
- name: "Date & Time"
icon: preferences-system-time-symbolic
- name: "Power"
icon: battery-symbolic
- name: "System"
icon: preferences-system-symbolic
sections: sections:
- name: Themes - name: "Themes"
type: classic
weight: 0 weight: 0
page: "Appearance"
settings: settings:
- name: IconTheme - name: IconTheme
type: entry type: entry
...@@ -27,8 +35,9 @@ ...@@ -27,8 +35,9 @@
gtype: string gtype: string
backend: gsettings backend: gsettings
key: org.gnome.desktop.background.picture-options key: org.gnome.desktop.background.picture-options
- name: Clock - name: "Clock"
weight: 10 weight: 10
page: "Date & Time"
settings: settings:
- name: Weekday - name: Weekday
type: boolean type: boolean
...@@ -45,16 +54,18 @@ ...@@ -45,16 +54,18 @@
gtype: boolean gtype: boolean
backend: gsettings backend: gsettings
key: org.gnome.desktop.interface.clock-show-seconds key: org.gnome.desktop.interface.clock-show-seconds
- name: Battery - name: "Battery"
weight: 10 weight: 10
page: "Power"
settings: settings:
- name: Show percentage - name: Show percentage
type: boolean type: boolean
gtype: boolean gtype: boolean
backend: gsettings backend: gsettings
key: org.gnome.desktop.interface.show-battery-percentage key: org.gnome.desktop.interface.show-battery-percentage
- name: Performance - name: "Performance"
weight: 20 weight: 20
page: "System"
settings: settings:
- name: Animations - name: Animations
help: Animations can be disabled for performance help: Animations can be disabled for performance
...@@ -63,12 +74,14 @@ ...@@ -63,12 +74,14 @@
backend: gsettings backend: gsettings
key: org.gnome.desktop.interface.enable-animations key: org.gnome.desktop.interface.enable-animations
- name: "Fonts" - name: "Fonts"
icon: font-x-generic-symbolic
weight: 1 weight: 1
pages:
- name: "Appearance"
icon: preferences-desktop-display-symbolic
sections: sections:
- name: Main - name: "Main"
type: classic
weight: 0 weight: 0
page: "Appearance"
settings: settings:
- name: Antialiasing - name: Antialiasing
type: choice type: choice
...@@ -104,12 +117,14 @@ ...@@ -104,12 +117,14 @@
step: 0.01 step: 0.01
digits: 2 digits: 2
- name: "GRUB" - name: "GRUB"
icon: system-reboot-symbolic
weight: 25 weight: 25
pages:
- name: "Boot"
icon: system-reboot-symbolic
sections: sections:
- name: Main - name: "Main"
type: classic
weight: 0 weight: 0
page: "Boot"
settings: settings:
- name: Timeout - name: Timeout
root: true root: true
......
...@@ -125,12 +125,33 @@ class Setting: ...@@ -125,12 +125,33 @@ class Setting:
return backend return backend
class Module:
def __init__(self, module_data):
self.name = module_data['name']
self.weight = module_data.get('weight', 0)
self.pages = {
page['name']: page for page in module_data.get('pages', [])
}
self.sections = []
def add_section(self, section):
self.sections.append(section)
def get_sorted_sections(self):
# Сортируем секции по весу
return sorted(self.sections, key=lambda s: s.weight)
class Section: class Section:
def __init__(self, section_data, strategy): def __init__(self, section_data, strategy, module):
self.name = section_data['name'] self.name = section_data['name']
self.weight = section_data.get('weight', 0) self.weight = section_data.get('weight', 0)
self.page = section_data.get('page')
self.settings = [Setting(s) for s in section_data.get('settings', [])] self.settings = [Setting(s) for s in section_data.get('settings', [])]
self.strategy = strategy self.strategy = strategy
self.module = module
self.module.add_section(self)
def create_preferences_group(self): def create_preferences_group(self):
return self.strategy.create_preferences_group(self) return self.strategy.create_preferences_group(self)
...@@ -176,21 +197,26 @@ class SectionFactory: ...@@ -176,21 +197,26 @@ class SectionFactory:
'classic': ClassicSectionStrategy(), 'classic': ClassicSectionStrategy(),
} }
def create_section(self, section_data): def create_section(self, section_data, module):
section_type = section_data.get('type', 'classic') section_type = section_data.get('type', 'classic')
strategy = self.strategies.get(section_type) strategy = self.strategies.get(section_type)
if not strategy: if not strategy:
raise ValueError(f"Неизвестный тип секции: {section_type}") raise ValueError(f"Неизвестный тип секции: {section_type}")
return Section(section_data, strategy) return Section(section_data, strategy, module)
class Page:
def __init__(self, name, icon=None):
self.name = name
self.icon = icon or "preferences-system" # Значение по умолчанию
self.sections = []
class Category: def add_section(self, section):
def __init__(self, category_data, section_factory: SectionFactory): self.sections.append(section)
self.name = category_data['name']
self.icon_name = category_data.get('icon', 'preferences-system') def sort_sections(self):
self.weight = category_data.get('weight', 0) self.sections = sorted(self.sections, key=lambda s: s.weight)
self.sections = [section_factory.create_section(s) for s in category_data.get('sections', [])]
def create_stack_page(self, stack, listbox): def create_stack_page(self, stack, listbox):
box = Gtk.ScrolledWindow() box = Gtk.ScrolledWindow()
...@@ -217,16 +243,16 @@ class Category: ...@@ -217,16 +243,16 @@ class Category:
row = TuneItPanelRow() row = TuneItPanelRow()
row.set_name(self.name) row.set_name(self.name)
row.set_title(self.name) row.set_title(self.name)
row.icon_name = self.icon_name row.icon_name = self.icon
listbox.append(row) listbox.append(row)
else: else:
print(f"the category {self.name} is empty, ignored") print(f"the page {self.name} is empty, ignored")
def init_settings_stack(stack, listbox, split_view): def init_settings_stack(stack, listbox, split_view):
yaml_data = load_modules() yaml_data = load_modules()
merged_data = merge_categories_by_name(yaml_data)
section_factory = SectionFactory() section_factory = SectionFactory()
modules_dict = {}
pages_dict = {}
if stack.get_pages(): if stack.get_pages():
print("Clear pages...") print("Clear pages...")
...@@ -236,10 +262,32 @@ def init_settings_stack(stack, listbox, split_view): ...@@ -236,10 +262,32 @@ def init_settings_stack(stack, listbox, split_view):
else: else:
print("First init...") print("First init...")
categories = [Category(c, section_factory) for c in merged_data] for module_data in yaml_data:
module = Module(module_data)
modules_dict[module.name] = module
for section_data in module_data.get('sections', []):
page_name = section_data.get('page', 'Default')
if page_name not in pages_dict:
page_info = module.pages.get(page_name, {})
page = Page(
name=page_name,
icon=page_info.get('icon')
)
pages_dict[page_name] = page
section = section_factory.create_section(section_data, module)
pages_dict[page_name].add_section(section)
pages = list(pages_dict.values())
for page in pages:
page.sort_sections()
pages = sorted(pages, key=lambda p: p.name)
for category in categories: for page in pages:
category.create_stack_page(stack, listbox) page.create_stack_page(stack, listbox)
if not stack: if not stack:
print("Ошибка: settings_pagestack не найден.") print("Ошибка: settings_pagestack не найден.")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment