# Path: kano_settings/templates.py
# class RadioButtonTemplate(LabelledListTemplate):
# 
#     def __init__(self, title, description, button_text, text_array):
#         LabelledListTemplate.__init__(self, title, description, button_text, text_array)
# 
#         for i in range(len(text_array)):
#             if i == 0:
#                 button = Gtk.RadioButton.new_with_label_from_widget(None, text_array[0][0])
#             else:
#                 button = Gtk.RadioButton.new_from_widget(self.buttons[0])
#             self.buttons.append(button)
#             self.label_button_and_pack(button, text_array[i][0], text_array[i][1])
#             button.connect('toggled', self.on_button_toggled, i)
# 
#     def on_button_toggled(self, widget=None, selected=0):
#         pass
# 
# 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/system/font.py
# def change_font_size(configuration):
#     try:
#         size = SIZES[configuration]
#     except IndexError:
#         return
# 
#     font = "sGtk/FontName=Bariol {}"
#     pattern = font.format("[0-9]+")
#     replace = font.format(size)
# 
#     # Apply changes: For jessie, this is automatically reloaded by lxsession 
#     file_replace(config_file, pattern, replace)
# 
#     logger.debug("set_font / change_font_size: selected_button:{}".format(configuration))


from gi import require_version
from gi.repository import Gdk
from kano.utils import get_user_unsudoed
from kano_settings.templates import RadioButtonTemplate
from .config_file import get_setting, set_setting
from kano_settings.system.font import change_font_size
import os
#
# set_font.py
#
# Copyright (C) 2014-2018 Kano Computing Ltd.
# License: http://www.gnu.org/licenses/gpl-2.0.txt GNU GPLv2
#

require_version('Gtk', '3.0')


selected_button = 0
initial_button = 0

username = get_user_unsudoed()
config_file = os.path.join('/home', username, '.config/lxsession/LXDE/desktop.conf')


MODES = [_("Small"), _("Normal"), _("Big")]


class SetFont(RadioButtonTemplate):
    selected_button = 0
    initial_button = 0

    def __init__(self, win):
        RadioButtonTemplate.__init__(
            self,
            _("Font"),

# Path: kano_settings/templates.py
# class RadioButtonTemplate(LabelledListTemplate):
# 
#     def __init__(self, title, description, button_text, text_array):
#         LabelledListTemplate.__init__(self, title, description, button_text, text_array)
# 
#         for i in range(len(text_array)):
#             if i == 0:
#                 button = Gtk.RadioButton.new_with_label_from_widget(None, text_array[0][0])
#             else:
#                 button = Gtk.RadioButton.new_from_widget(self.buttons[0])
#             self.buttons.append(button)
#             self.label_button_and_pack(button, text_array[i][0], text_array[i][1])
#             button.connect('toggled', self.on_button_toggled, i)
# 
#     def on_button_toggled(self, widget=None, selected=0):
#         pass
# 
# 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/system/font.py
# def change_font_size(configuration):
#     try:
#         size = SIZES[configuration]
#     except IndexError:
#         return
# 
#     font = "sGtk/FontName=Bariol {}"
#     pattern = font.format("[0-9]+")
#     replace = font.format(size)
# 
#     # Apply changes: For jessie, this is automatically reloaded by lxsession 
#     file_replace(config_file, pattern, replace)
# 
#     logger.debug("set_font / change_font_size: selected_button:{}".format(configuration))


# Path: kano_settings/set_font.py
from gi import require_version
from gi.repository import Gdk
from kano.utils import get_user_unsudoed
from kano_settings.templates import RadioButtonTemplate
from .config_file import get_setting, set_setting
from kano_settings.system.font import change_font_size
import os

#
# set_font.py
#
# Copyright (C) 2014-2018 Kano Computing Ltd.
# License: http://www.gnu.org/licenses/gpl-2.0.txt GNU GPLv2
#

require_version('Gtk', '3.0')


selected_button = 0
initial_button = 0

username = get_user_unsudoed()
config_file = os.path.join('/home', username, '.config/lxsession/LXDE/desktop.conf')


MODES = [_("Small"), _("Normal"), _("Big")]


class SetFont(RadioButtonTemplate):
    selected_button = 0
    initial_button = 0

    def __init__(self, win):
        RadioButtonTemplate.__init__(
            self,
            _("Font"),

            _("Choose a comfortable text size"),