# 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
        self.show_configuration()
        self.win.show_all()

    def _add_led_speaker_checkbox(self):
        self.cpu_monitor_checkbox = Gtk.CheckButton()
        is_led_speaker_plugged = False
        is_pi_hat_plugged = False

        try:

            speaker_led_api = get_speakerleds_interface(retry_count=0)
            if speaker_led_api:  # can be None
                is_led_speaker_plugged = speaker_led_api.detect()

            pi_hat_api = get_pihat_interface(retry_count=0)
            if pi_hat_api:  # can be None
                is_pi_hat_plugged = pi_hat_api.detect()

        except Exception as e:
            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):

# 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

        self.show_configuration()
        self.win.show_all()

    def _add_led_speaker_checkbox(self):
        self.cpu_monitor_checkbox = Gtk.CheckButton()
        is_led_speaker_plugged = False
        is_pi_hat_plugged = False

        try:

            speaker_led_api = get_speakerleds_interface(retry_count=0)
            if speaker_led_api:  # can be None
                is_led_speaker_plugged = speaker_led_api.detect()

            pi_hat_api = get_pihat_interface(retry_count=0)
            if pi_hat_api:  # can be None
                is_pi_hat_plugged = pi_hat_api.detect()

        except Exception as e:
            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():