Commit 3d351ebd authored by Roman Alifanov's avatar Roman Alifanov

changes for easy Integration of a new type of sections

parent e2d5e8d4
from ..setting.setting import Setting
from .base_strategy import SectionStrategy
from .classic import ClassicSectionStrategy
class Section:
def __init__(self, section_data, strategy, module):
self.name = module.get_translation(section_data['name'])
self.weight = section_data.get('weight', 0)
self.page = section_data.get('page')
self.settings = [Setting(s, module) for s in section_data.get('settings', [])]
self.strategy = strategy
self.module = module
self.module.add_section(self)
def create_preferences_group(self):
return self.strategy.create_preferences_group(self)
from .classic import ClassicSection
class SectionFactory:
def __init__(self):
self.strategies = {
'classic': ClassicSectionStrategy(),
self.sections = {
'classic': ClassicSection,
}
def create_section(self, section_data, module):
section_type = section_data.get('type', 'classic')
strategy = self.strategies.get(section_type)
if not strategy:
raise ValueError(f"Неизвестный тип секции: {section_type}")
return Section(section_data, strategy, module)
section = self.sections.get(section_type)
if not section:
raise ValueError(f"Unknown type of section: {section_type}")
return section(section_data, module)
\ No newline at end of file
class BaseSection():
def __init__(self, section_data, module):
self.name = module.get_translation(section_data['name'])
self.weight = section_data.get('weight', 0)
self.page = section_data.get('page')
\ No newline at end of file
class SectionStrategy:
def create_preferences_group(self, section):
raise NotImplementedError("Метод create_preferences_group должен быть реализован")
from gi.repository import Adw
from ..setting.setting import Setting
from .base_strategy import SectionStrategy
from .base import BaseSection
class ClassicSection(BaseSection):
def __init__(self, section_data, module):
super().__init__(section_data, module)
self.settings = [Setting(s, module) for s in section_data.get('settings', [])]
self.module = module
class ClassicSectionStrategy(SectionStrategy):
def create_preferences_group(self, section):
group = Adw.PreferencesGroup(title=section.name, description=section.module.name)
self.module.add_section(self)
def create_preferences_group(self):
group = Adw.PreferencesGroup(title=self.name, description=self.module.name)
not_empty = False
for setting in section.settings:
for setting in self.settings:
row = setting.create_row()
if row:
print(f"Добавление строки для настройки: {setting.name}")
print(f"Adding a row for setting: {setting.name}")
group.add(row)
not_empty = True
else:
print(f"Не удалось создать строку для настройки: {setting.name}")
print(f"Failed to create a row for setting: {setting.name}")
if not_empty:
return group
else:
......
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