summaryrefslogtreecommitdiffstats
path: root/config/chroot_local-includes/usr/lib/python3/dist-packages/tailsgreeter/ui/settings_collection.py
blob: 03bb4638acd2b7a51d313dc65cba2c43423f7242 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import gi

from tailsgreeter.ui.setting import GreeterSetting
from tailsgreeter.ui.region_settings import LocalizationSettingUI
from tailsgreeter.ui.additional_settings import AdditionalSetting

gi.require_version('Gtk', '3.0')
from gi.repository import Gtk


class GreeterSettingsCollection(object):
    def __init__(self, *settings: GreeterSetting, no_subclassification=False):
        self.settings = {setting.id: setting for setting in settings}

        if no_subclassification:
            return

        self.region_settings = GreeterSettingsCollection(
            *(s for s in self.settings.values() if isinstance(s, LocalizationSettingUI)),
            no_subclassification = True,
        )
        self.additional_settings = GreeterSettingsCollection(
            *(s for s in self.settings.values() if isinstance(s, AdditionalSetting)),
            no_subclassification = True,
        )

    def __getitem__(self, key) -> GreeterSetting:
        return self.settings[key]

    def __iter__(self):
        return iter(self.settings.values())

    def id_from_row(self, row: Gtk.ListBoxRow):
        for setting in self.settings.values():
            if setting.listboxrow == row:
                return setting.id