# 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/mouse.py
# def change_mouse_speed(configuration):
#     try:
#         speed = SPEEDS[configuration]
#     except IndexError:
#         return
# 
#     command = "xset m {}".format(speed)
# 
#     # Apply changes
#     os.system(command)
#     logger.debug("set_mouse / change_mouse_speed: selected_button:{}".format(configuration))


from gi import require_version
from gi.repository import Gdk
from kano_settings.templates import RadioButtonTemplate
from .config_file import get_setting, set_setting
from kano_settings.system.mouse import change_mouse_speed
        except ValueError:
            self.initial_button = 0

        self.selected_button = self.initial_button
        self.get_button(self.initial_button).set_active(True)

        self.win.top_bar.enable_prev()
        self.win.change_prev_callback(self.reset_and_go_home)

        self.kano_button.connect('clicked', self.set_mouse)
        self.win.show_all()

    def reset_and_go_home(self, widget=None, event=None):
        change_mouse_speed(self.initial_button)
        self.win.go_to_home()

    def set_mouse(self, button):
        try:
            config = MODES[self.selected_button]
        except IndexError:
            config = _("Normal")

        if not config == get_setting('Mouse'):
            set_setting('Mouse', config)
        self.win.go_to_home()

    def on_button_toggled(self, button, selected):
        if button.get_active():
            self.selected_button = selected
            # Apply changes so speed can be tested

# 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/mouse.py
# def change_mouse_speed(configuration):
#     try:
#         speed = SPEEDS[configuration]
#     except IndexError:
#         return
# 
#     command = "xset m {}".format(speed)
# 
#     # Apply changes
#     os.system(command)
#     logger.debug("set_mouse / change_mouse_speed: selected_button:{}".format(configuration))


# Path: kano_settings/set_mouse.py
from gi import require_version
from gi.repository import Gdk
from kano_settings.templates import RadioButtonTemplate
from .config_file import get_setting, set_setting
from kano_settings.system.mouse import change_mouse_speed

        except ValueError:
            self.initial_button = 0

        self.selected_button = self.initial_button
        self.get_button(self.initial_button).set_active(True)

        self.win.top_bar.enable_prev()
        self.win.change_prev_callback(self.reset_and_go_home)

        self.kano_button.connect('clicked', self.set_mouse)
        self.win.show_all()

    def reset_and_go_home(self, widget=None, event=None):
        change_mouse_speed(self.initial_button)
        self.win.go_to_home()

    def set_mouse(self, button):
        try:
            config = MODES[self.selected_button]
        except IndexError:
            config = _("Normal")

        if not config == get_setting('Mouse'):
            set_setting('Mouse', config)
        self.win.go_to_home()

    def on_button_toggled(self, button, selected):
        if button.get_active():
            self.selected_button = selected
            # Apply changes so speed can be tested

            change_mouse_speed(selected)