# 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/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


import threading
import kano_settings.system.keyboard_layouts as keyboard_layouts
import kano_settings.system.keyboard_config as keyboard_config
import kano_settings.common as common
from gi import require_version
from gi.repository import Gtk, GObject
from kano_settings.templates import Template
from kano_settings.config_file import get_setting
from kano.gtk3.buttons import OrangeButton
from kano.gtk3.kano_combobox import KanoComboBox
from kano.utils import detect_kano_keyboard
from kano.logging import logger
                    keyboard_config.set_keyboard(self.selected_country, self.selected_variant)

                    # A reboot is needed to apply the new keyboard to QT5 apps
                    common.need_reboot = True
                    
                # The callback runs a GUI task, so wrap it!
                GObject.idle_add(self.work_finished_cb)

            # Save the changes in the config file
            self.update_config()

            # An then apply the new saved changes
            thread = threading.Thread(target=lengthy_process)
            thread.start()

            kano_keyboard = detect_kano_keyboard()

            # Go back a screen
            if kano_keyboard:
                self.go_to_kano_screen()
            else:
                self.win.go_to_home()

            self.win.show_all()

    def read_config(self):
        self.selected_continent_index = get_setting('Keyboard-continent-index')
        self.selected_country_index = get_setting('Keyboard-country-index')
        self.selected_variant_index = get_setting('Keyboard-variant-index')
        self.selected_continent_hr = get_setting('Keyboard-continent-human')

# 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/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


# Path: kano_settings/set_keyboard.py
import threading
import kano_settings.system.keyboard_layouts as keyboard_layouts
import kano_settings.system.keyboard_config as keyboard_config
import kano_settings.common as common
from gi import require_version
from gi.repository import Gtk, GObject
from kano_settings.templates import Template
from kano_settings.config_file import get_setting
from kano.gtk3.buttons import OrangeButton
from kano.gtk3.kano_combobox import KanoComboBox
from kano.utils import detect_kano_keyboard
from kano.logging import logger

                    keyboard_config.set_keyboard(self.selected_country, self.selected_variant)

                    # A reboot is needed to apply the new keyboard to QT5 apps
                    common.need_reboot = True
                    
                # The callback runs a GUI task, so wrap it!
                GObject.idle_add(self.work_finished_cb)

            # Save the changes in the config file
            self.update_config()

            # An then apply the new saved changes
            thread = threading.Thread(target=lengthy_process)
            thread.start()

            kano_keyboard = detect_kano_keyboard()

            # Go back a screen
            if kano_keyboard:
                self.go_to_kano_screen()
            else:
                self.win.go_to_home()

            self.win.show_all()

    def read_config(self):
        self.selected_continent_index = get_setting('Keyboard-continent-index')
        self.selected_country_index = get_setting('Keyboard-country-index')
        self.selected_variant_index = get_setting('Keyboard-variant-index')
        self.selected_continent_hr = get_setting('Keyboard-continent-human')

        self.selected_country_hr = get_setting('Keyboard-country-human')