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


from gi import require_version
from gi.repository import Gdk, Gtk
from kano.utils import run_bg, has_min_performance, RPI_2_B_SCORE
from kano.logging import logger
from kano_settings.templates import RadioButtonTemplate
from kano_settings.config_file import get_setting, set_setting
            from kano_peripherals.speaker_leds.driver.high_level import \
                get_speakerleds_interface
            from kano_peripherals.pi_hat.driver.high_level import \
                get_pihat_interface
import kano.notifications as notifications
            logger.error("Something unexpected occured in _add_led_speaker_checkbox"
                         " - [{}]".format(e))

        if has_min_performance(RPI_2_B_SCORE) and (is_led_speaker_plugged or is_pi_hat_plugged):
            self.buttons.append(self.cpu_monitor_checkbox)
            self.label_button_and_pack(
                self.cpu_monitor_checkbox,
                _("Enable LED ring CPU Animation"), ''
            )

    def configure_all_notifications(self):
        if self.disable_all_radiobutton.get_active():
            notifications.disable()
        else:
            notifications.enable()

    def configure_world_notifications(self):
        if self.disable_world_radiobutton.get_active():
            notifications.disallow_world_notifications()
        else:
            notifications.allow_world_notifications()

    def configure_cpu_monitor_animation(self, checkbox=None):
        is_ticked = self.cpu_monitor_checkbox.get_active()
        was_enabled = get_setting('LED-Speaker-anim')

        if is_ticked and not was_enabled:
            set_setting('LED-Speaker-anim', is_ticked)
            run_bg('kano-speakerleds cpu-monitor start', unsudo=True)
        elif was_enabled and not is_ticked:

# 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/set_notifications.py
from gi import require_version
from gi.repository import Gdk, Gtk
from kano.utils import run_bg, has_min_performance, RPI_2_B_SCORE
from kano.logging import logger
from kano_settings.templates import RadioButtonTemplate
from kano_settings.config_file import get_setting, set_setting
            from kano_peripherals.speaker_leds.driver.high_level import \
                get_speakerleds_interface
            from kano_peripherals.pi_hat.driver.high_level import \
                get_pihat_interface
import kano.notifications as notifications

            logger.error("Something unexpected occured in _add_led_speaker_checkbox"
                         " - [{}]".format(e))

        if has_min_performance(RPI_2_B_SCORE) and (is_led_speaker_plugged or is_pi_hat_plugged):
            self.buttons.append(self.cpu_monitor_checkbox)
            self.label_button_and_pack(
                self.cpu_monitor_checkbox,
                _("Enable LED ring CPU Animation"), ''
            )

    def configure_all_notifications(self):
        if self.disable_all_radiobutton.get_active():
            notifications.disable()
        else:
            notifications.enable()

    def configure_world_notifications(self):
        if self.disable_world_radiobutton.get_active():
            notifications.disallow_world_notifications()
        else:
            notifications.allow_world_notifications()

    def configure_cpu_monitor_animation(self, checkbox=None):
        is_ticked = self.cpu_monitor_checkbox.get_active()
        was_enabled = get_setting('LED-Speaker-anim')

        if is_ticked and not was_enabled:
            set_setting('LED-Speaker-anim', is_ticked)
            run_bg('kano-speakerleds cpu-monitor start', unsudo=True)
        elif was_enabled and not is_ticked:

            set_setting('LED-Speaker-anim', is_ticked)