# Path: kano_world/functions.py
# def get_mixed_username():
#     if is_registered():
#         import mercury  # Lazy import to avoid dynamically linking with global import
#         kw = mercury.KanoWorld(kw_url)
#         username = kw.get_username()
#     else:
#         username = get_user_unsudoed()
#     return username
# 
# Path: kano_profile/badges.py
# def calculate_kano_level():
#     '''
#     Calculates the current level of the user
#     Returns: level, percentage and current xp
#     '''
#     level_rules = read_json(levels_file)
#     if not level_rules:
#         return -1, 0, 0
# 
#     max_level = max([int(n) for n in level_rules.keys()])
#     xp_now = calculate_xp()
# 
#     for level in xrange(1, max_level + 1):
#         level_min = level_rules[str(level)]
# 
#         if level != max_level:
#             level_max = level_rules[str(level + 1)] - 1
#         else:
#             level_max = float('inf')
# 
#         if level_min <= xp_now <= level_max:
#             reached_level = level
#             reached_percentage = (xp_now - level_min) / (level_max + 1 - level_min)
# 
#             return int(reached_level), reached_percentage, xp_now
# 
# Path: kano_profile_gui/components/icons.py
# def get_ui_icon(name):
#     if name == 'green_arrow':
#         icon_number = 0
#     elif name == 'pale_right_arrow':
#         icon_number = 1
#     elif name == 'dark_left_arrow':
#         icon_number = 2
#     elif name == 'dark_right_arrow':
#         icon_number = 3
#     elif name == 'pale_left_arrow':
#         icon_number = 4
#     elif name == 'tick':
#         icon_number = 5
#     elif name == 'cross':
#         icon_number = 6
#     elif name == 'dropdown_arrow':
#         icon_number = 7
#     else:
#         raise Exception('Unknown icon name ' + name)
# 
#     src_loc = os.path.join(media_dir, 'images/icons/systemsetup-icons.png')
#     pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(src_loc, 192, 24)
# 
#     subpixbuf = pixbuf.new_subpixbuf(24 * icon_number, 0, 24, 24)
#     buf = subpixbuf.add_alpha(True, 255, 255, 255)
# 
#     icon = Gtk.Image()
#     icon.set_from_pixbuf(buf)
#     return icon


import os
from gi.repository import Gtk, GObject
from kano.gtk3.cursor import attach_cursor_events
from kano_world.functions import get_mixed_username
from kano_profile.badges import calculate_kano_level
from kano_profile_gui.components.icons import get_ui_icon

    def disable_buttons(self):
        """ Disable all the buttons except for the exit button.
        The latter's sensitivity is not altered
        """
        self._set_button_sensitivity(False)

    def enable_buttons(self):
        """ Enable all the menu buttons. The exit button's sensitivity is
        not altered
        """
        self._set_button_sensitivity(True)

    def _set_button_sensitivity(self, sensitivity_value):
        """ Keep all the buttons whose sensitivity we want to control here
        """
        self.home_button.set_sensitive(sensitivity_value)
        for button in self.buttons.itervalues():
            button['button'].set_sensitive(sensitivity_value)


class HomeButton(Gtk.Button):

    def __init__(self):
        Gtk.Button.__init__(self)
        attach_cursor_events(self)
        self.get_style_context().add_class('home_button')

        # Get the username or kano world name
        # Get username here

# Path: kano_world/functions.py
# def get_mixed_username():
#     if is_registered():
#         import mercury  # Lazy import to avoid dynamically linking with global import
#         kw = mercury.KanoWorld(kw_url)
#         username = kw.get_username()
#     else:
#         username = get_user_unsudoed()
#     return username
# 
# Path: kano_profile/badges.py
# def calculate_kano_level():
#     '''
#     Calculates the current level of the user
#     Returns: level, percentage and current xp
#     '''
#     level_rules = read_json(levels_file)
#     if not level_rules:
#         return -1, 0, 0
# 
#     max_level = max([int(n) for n in level_rules.keys()])
#     xp_now = calculate_xp()
# 
#     for level in xrange(1, max_level + 1):
#         level_min = level_rules[str(level)]
# 
#         if level != max_level:
#             level_max = level_rules[str(level + 1)] - 1
#         else:
#             level_max = float('inf')
# 
#         if level_min <= xp_now <= level_max:
#             reached_level = level
#             reached_percentage = (xp_now - level_min) / (level_max + 1 - level_min)
# 
#             return int(reached_level), reached_percentage, xp_now
# 
# Path: kano_profile_gui/components/icons.py
# def get_ui_icon(name):
#     if name == 'green_arrow':
#         icon_number = 0
#     elif name == 'pale_right_arrow':
#         icon_number = 1
#     elif name == 'dark_left_arrow':
#         icon_number = 2
#     elif name == 'dark_right_arrow':
#         icon_number = 3
#     elif name == 'pale_left_arrow':
#         icon_number = 4
#     elif name == 'tick':
#         icon_number = 5
#     elif name == 'cross':
#         icon_number = 6
#     elif name == 'dropdown_arrow':
#         icon_number = 7
#     else:
#         raise Exception('Unknown icon name ' + name)
# 
#     src_loc = os.path.join(media_dir, 'images/icons/systemsetup-icons.png')
#     pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(src_loc, 192, 24)
# 
#     subpixbuf = pixbuf.new_subpixbuf(24 * icon_number, 0, 24, 24)
#     buf = subpixbuf.add_alpha(True, 255, 255, 255)
# 
#     icon = Gtk.Image()
#     icon.set_from_pixbuf(buf)
#     return icon


# Path: kano_profile_gui/MenuBar.py
import os
from gi.repository import Gtk, GObject
from kano.gtk3.cursor import attach_cursor_events
from kano_world.functions import get_mixed_username
from kano_profile.badges import calculate_kano_level
from kano_profile_gui.components.icons import get_ui_icon


    def disable_buttons(self):
        """ Disable all the buttons except for the exit button.
        The latter's sensitivity is not altered
        """
        self._set_button_sensitivity(False)

    def enable_buttons(self):
        """ Enable all the menu buttons. The exit button's sensitivity is
        not altered
        """
        self._set_button_sensitivity(True)

    def _set_button_sensitivity(self, sensitivity_value):
        """ Keep all the buttons whose sensitivity we want to control here
        """
        self.home_button.set_sensitive(sensitivity_value)
        for button in self.buttons.itervalues():
            button['button'].set_sensitive(sensitivity_value)


class HomeButton(Gtk.Button):

    def __init__(self):
        Gtk.Button.__init__(self)
        attach_cursor_events(self)
        self.get_style_context().add_class('home_button')

        # Get the username or kano world name
        # Get username here

        username = get_mixed_username()