# Path: kano_settings/templates.py
# class Template(Gtk.Box):
# 
#     def __init__(
#         self,
#         title,
#         description,
#         button_text,
#         is_plug=False,
#         back_btn=False
#     ):
# 
#         Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL)
# 
#         self.title = Heading(title, description, is_plug, back_btn)
#         self.title.container.set_margin_bottom(0)
#         self.box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
#         self.align = Gtk.Alignment(xscale=0, yscale=0, xalign=0.5, yalign=0.3)
#         self.align.add(self.box)
#         self.kano_button = KanoButton(button_text)
#         self.kano_button.pack_and_align()
#         self.kano_button.align.set_padding(0, 30, 0, 0)
# 
#         self.pack_start(self.title.container, False, False, 0)
#         self.pack_start(self.align, True, True, 0)
#         self.pack_end(self.kano_button.align, False, False, 0)
# 
#     def set_prev_callback(self, cb):
#         self.title.set_prev_callback(cb)
# 
# Path: kano_settings/system/locale.py
# def set_locale(locale):
#     locale = ensure_utf_locale(locale)
# 
#     if not is_locale_installed(locale):
#         install_locale(locale)
# 
#     for param in LOCALE_PARAMS:
#         set_locale_param(param, locale, skip_check=True)
# 
# def get_locale():
#     return os.environ['LANG']
# 
# def strip_encoding_from_locale(locale):
#     return locale.split('.')[0]
# 
# Path: kano_settings/system/supported_locales.py
# class Locales(dict):
#     LANGUAGES = {
#         'en': _("English"),
#         'de': _("German")
#     }
# 
#     REGIONS = {
#         'US': _("United States"),
#         'GB': _("United Kingdom"),
#         'DE': _("Germany")
#     }
# 
#     def list_language_codes(self):
#         return self.keys()
# 
#     def list_languages(self):
#         return [self.LANGUAGES[lang] for lang in self.iterkeys()]
# 
#     def list_region_codes(self, lang=None, lang_code=None):
#         if lang:
#             lang_code = self.lang_to_lang_code(lang)
# 
#         return self[lang_code]
# 
#     def list_regions(self, lang=None, lang_code=None):
#         return [
#             self.REGIONS[region_code] for region_code
#             in self.list_region_codes(lang=lang, lang_code=lang_code)
#         ]
# 
#     @staticmethod
#     def lang_to_lang_code(lang):
#         for lang_code, _lang in Locales.LANGUAGES.iteritems():
#             if lang == _lang:
#                 return lang_code
# 
#     @staticmethod
#     def lang_code_to_lang(lang_code):
#         return Locales.LANGUAGES[lang_code]
# 
#     @staticmethod
#     def region_to_region_code(region):
#         for region_code, _region in Locales.REGIONS.iteritems():
#             if region == _region:
#                 return region_code
# 
#     @staticmethod
#     def region_code_to_region(region_code):
#         return Locales.REGIONS[region_code]
# 
#     @staticmethod
#     def get_codes_from_locale_code(locale_code):
#         return locale_code.split('_')
# 
#     @staticmethod
#     def get_locale_code_from_codes(lang_code, region_code):
#         return "{}_{}".format(lang_code, region_code)
# 
#     @staticmethod
#     def get_locale_code_from_langs(lang, region):
#         region_code = Locales.region_to_region_code(region)
#         lang_code = Locales.lang_to_lang_code(lang)
# 
#         return Locales.get_locale_code_from_codes(lang_code, region_code)
# 
# SUPPORTED_LOCALES = Locales({
#     'en': ['US', 'GB'],
#     'de': ['DE']
# })
# 
# Path: kano_settings/config_file.py
# def get_setting(variable):
# 
#     try:
#         value = read_json(settings_file)[variable]
#     except Exception:
#         if variable not in DEFAULTS:
#             logger.info("Defaults not found for variable: {}".format(variable))
#         value = DEFAULTS[variable]
#     return value
# 
# def set_setting(variable, value):
# 
#     if username == 'root':
#         return
# 
#     logger.debug(u"config_file / set_setting: {} {}".format(variable, value))
# 
#     data = read_json(settings_file)
#     if not data:
#         data = dict()
# 
#     data[variable] = value
#     write_json(settings_file, data)
#     chown_path(settings_file)


from gi import require_version
from gi.repository import Gtk
from kano.gtk3.kano_combobox import KanoComboBox
from kano_settings.templates import Template
from kano_settings.system.locale import set_locale, get_locale, \
    strip_encoding_from_locale
from kano_settings.system.supported_locales import Locales, SUPPORTED_LOCALES
from kano_settings.config_file import get_setting, set_setting
import kano_settings.common as common
#
# locale.py
#
# Copyright (C) 2015 - 2018 Kano Computing Ltd.
# License: http://www.gnu.org/licenses/gpl-2.0.txt GNU GPL v2
#

require_version('Gtk', '3.0')




class LocaleConfig(Template):

    def __init__(self, win):

# Path: kano_settings/templates.py
# class Template(Gtk.Box):
# 
#     def __init__(
#         self,
#         title,
#         description,
#         button_text,
#         is_plug=False,
#         back_btn=False
#     ):
# 
#         Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL)
# 
#         self.title = Heading(title, description, is_plug, back_btn)
#         self.title.container.set_margin_bottom(0)
#         self.box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
#         self.align = Gtk.Alignment(xscale=0, yscale=0, xalign=0.5, yalign=0.3)
#         self.align.add(self.box)
#         self.kano_button = KanoButton(button_text)
#         self.kano_button.pack_and_align()
#         self.kano_button.align.set_padding(0, 30, 0, 0)
# 
#         self.pack_start(self.title.container, False, False, 0)
#         self.pack_start(self.align, True, True, 0)
#         self.pack_end(self.kano_button.align, False, False, 0)
# 
#     def set_prev_callback(self, cb):
#         self.title.set_prev_callback(cb)
# 
# Path: kano_settings/system/locale.py
# def set_locale(locale):
#     locale = ensure_utf_locale(locale)
# 
#     if not is_locale_installed(locale):
#         install_locale(locale)
# 
#     for param in LOCALE_PARAMS:
#         set_locale_param(param, locale, skip_check=True)
# 
# def get_locale():
#     return os.environ['LANG']
# 
# def strip_encoding_from_locale(locale):
#     return locale.split('.')[0]
# 
# Path: kano_settings/system/supported_locales.py
# class Locales(dict):
#     LANGUAGES = {
#         'en': _("English"),
#         'de': _("German")
#     }
# 
#     REGIONS = {
#         'US': _("United States"),
#         'GB': _("United Kingdom"),
#         'DE': _("Germany")
#     }
# 
#     def list_language_codes(self):
#         return self.keys()
# 
#     def list_languages(self):
#         return [self.LANGUAGES[lang] for lang in self.iterkeys()]
# 
#     def list_region_codes(self, lang=None, lang_code=None):
#         if lang:
#             lang_code = self.lang_to_lang_code(lang)
# 
#         return self[lang_code]
# 
#     def list_regions(self, lang=None, lang_code=None):
#         return [
#             self.REGIONS[region_code] for region_code
#             in self.list_region_codes(lang=lang, lang_code=lang_code)
#         ]
# 
#     @staticmethod
#     def lang_to_lang_code(lang):
#         for lang_code, _lang in Locales.LANGUAGES.iteritems():
#             if lang == _lang:
#                 return lang_code
# 
#     @staticmethod
#     def lang_code_to_lang(lang_code):
#         return Locales.LANGUAGES[lang_code]
# 
#     @staticmethod
#     def region_to_region_code(region):
#         for region_code, _region in Locales.REGIONS.iteritems():
#             if region == _region:
#                 return region_code
# 
#     @staticmethod
#     def region_code_to_region(region_code):
#         return Locales.REGIONS[region_code]
# 
#     @staticmethod
#     def get_codes_from_locale_code(locale_code):
#         return locale_code.split('_')
# 
#     @staticmethod
#     def get_locale_code_from_codes(lang_code, region_code):
#         return "{}_{}".format(lang_code, region_code)
# 
#     @staticmethod
#     def get_locale_code_from_langs(lang, region):
#         region_code = Locales.region_to_region_code(region)
#         lang_code = Locales.lang_to_lang_code(lang)
# 
#         return Locales.get_locale_code_from_codes(lang_code, region_code)
# 
# SUPPORTED_LOCALES = Locales({
#     'en': ['US', 'GB'],
#     'de': ['DE']
# })
# 
# Path: kano_settings/config_file.py
# def get_setting(variable):
# 
#     try:
#         value = read_json(settings_file)[variable]
#     except Exception:
#         if variable not in DEFAULTS:
#             logger.info("Defaults not found for variable: {}".format(variable))
#         value = DEFAULTS[variable]
#     return value
# 
# def set_setting(variable, value):
# 
#     if username == 'root':
#         return
# 
#     logger.debug(u"config_file / set_setting: {} {}".format(variable, value))
# 
#     data = read_json(settings_file)
#     if not data:
#         data = dict()
# 
#     data[variable] = value
#     write_json(settings_file, data)
#     chown_path(settings_file)


# Path: kano_settings/locale.py
from gi import require_version
from gi.repository import Gtk
from kano.gtk3.kano_combobox import KanoComboBox
from kano_settings.templates import Template
from kano_settings.system.locale import set_locale, get_locale, \
    strip_encoding_from_locale
from kano_settings.system.supported_locales import Locales, SUPPORTED_LOCALES
from kano_settings.config_file import get_setting, set_setting
import kano_settings.common as common

#
# locale.py
#
# Copyright (C) 2015 - 2018 Kano Computing Ltd.
# License: http://www.gnu.org/licenses/gpl-2.0.txt GNU GPL v2
#

require_version('Gtk', '3.0')




class LocaleConfig(Template):

    def __init__(self, win):

        Template.__init__(