# Path: kano_login/swag_screen.py
# class SwagScreen(Template):
#     def __init__(self, win):
# 
#         # Set window
#         self.win = win
#         self.win.set_decorated(False)
#         self.win.set_resizable(True)
# 
#         # Set text depending on login
#         login = is_registered()
#         if login:
#             header = _("Profile activated!")
#             subheader = _(
#                 u"Now you can share stuff, build your character, " \
#                 u"and connect with friends! You've earned some " \
#                 u"rewards\N{HORIZONTAL ELLIPSIS}"
#             )
#             image_name = 'profile-created'
#             button_label = _("LET'S GO")
#         else:
#             header = _("No online profile - for now.")
#             subheader = _(
#                 "Your profile stores all your rewards, projects, and " \
#                 "challenges. But fear not - we'll save everything for " \
#                 "when you have internet."
#             )
#             image_name = 'no-profile-new'
#             button_label = _("LET'S GO")
# 
#         # Set image
#         img_width = 590
#         img_height = 270
#         image_filename = get_image(
#             'login', '', image_name, str(img_width) + 'x' + str(img_height)
#         )
# 
#         # Create template
#         Template.__init__(self, image_filename, header, subheader,
#                           button_label, "")
# 
#         self.win.set_main_widget(self)
#         self.kano_button.connect('button_release_event', self.next_screen)
#         self.kano_button.connect('key_release_event', self.next_screen)
#         self.kano_button.grab_focus()
#         self.win.show_all()
# 
#         # Force the cross button to hide
#         self.win.headerbar.close_button.hide()
# 
#     def next_screen(self, widget, event):
#         # If enter key is pressed or mouse button is clicked
#         if not hasattr(event, 'keyval') or event.keyval == 65293:
#             # Exit
#             sys.exit(0)
# 
# Path: kano_login/templates/template.py
# class Template(Gtk.Box):
# 
#     def __init__(self, img_filename, title, description, kano_button_text, orange_button_text):
#         Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL)
# 
#         if img_filename:
#             self.image = Gtk.Image.new_from_file(img_filename)
#             self.pack_start(self.image, False, False, 0)
# 
#         self.heading = Heading(title, description)
#         self.kano_button = KanoButton(kano_button_text)
# 
#         self.pack_start(self.heading.container, False, False, 0)
# 
#         self.button_box = Gtk.ButtonBox(spacing=10)
#         self.button_box.set_layout(Gtk.ButtonBoxStyle.SPREAD)
#         self.button_box.set_margin_bottom(30)
#         self.pack_start(self.button_box, False, False, 0)
# 
#         if not orange_button_text == "":
#             self.orange_button = OrangeButton(orange_button_text)
#             self.button_box.pack_start(self.orange_button, False, False, 0)
#             self.button_box.pack_start(self.kano_button, False, False, 0)
#             # The empty label is to centre the kano_button
#             label = Gtk.Label("    ")
#             self.button_box.pack_start(label, False, False, 0)
#         else:
#             self.button_box.pack_start(self.kano_button, False, False, 0)
# 
# Path: kano_profile_gui/images.py
# def get_image(category, subcategory, name, subfolder_str):
#     # The online badge image files are stored in the home directory.
#     # The function bellow gets the corrects path.
#     if category == 'badges' and subcategory == 'online':
#         return get_online_badge_path(name)
# 
#     folder = os.path.join(image_dir, category, subfolder_str, subcategory)
#     filename = '{name}.png'.format(name=name)
#     fullpath = os.path.join(folder, filename)
#     if not os.path.exists(fullpath):
#         logger.error("missing image: {}".format(fullpath))
#         return os.path.join(image_dir, 'icons/50/_missing.png')
#         #ensure_dir(folder)
#         #open(fullpath, 'w').close()
#         #print '{} created'.format(fullpath)
#         # try:
#         #     from randomavatar.randomavatar import Avatar
#         #     ensure_dir(folder)
#         #     avatar = Avatar(rows=10, columns=10)
#         #     image_byte_array = avatar.get_image(string=filename, width=width, height=width, pad=10)
#         #     avatar.save(image_byte_array=image_byte_array, save_location=fullpath)
#         #     print '{} created'.format(fullpath)
#         # except Exception:
#         #     return os.path.join(image_dir, 'icons/50/_missing.png')
#     return fullpath
# 
# Path: kano_world/config.py
# AUTH_URL = CONF['auth_url']


import os
import sys
from gi.repository import Gtk
from kano.gtk3.buttons import KanoButton, OrangeButton
from kano.gtk3.heading import Heading
from kano.network import is_internet
from kano_login.swag_screen import SwagScreen
from kano_login.templates.template import Template
from kano_profile_gui.images import get_image
from kano_world.config import AUTH_URL

    def __init__(self, win, dummy=None):

        FirstScreenTemplate.__init__(self)

        self.win = win
        self.win.set_decorated(False)
        self.win.set_main_widget(self)

        self.kano_button.connect('button_release_event', self.register_screen)
        self.login_button.connect(
            'button_release_event', self.login_screen
        )
        self.skip_button.connect(
            'button_release_event', self.exit_registration
        )

        self.kano_button.connect(
            'key_release_event', self.register_screen
        )
        self.button_box.set_margin_bottom(30)
        self.kano_button.grab_focus()
        self.win.show_all()

    def login_screen(self, widget, event):
        self.win.remove_main_widget()

        if is_internet():
            # Hand-off from the Gtk to the web view
            Gtk.main_quit()

# Path: kano_login/swag_screen.py
# class SwagScreen(Template):
#     def __init__(self, win):
# 
#         # Set window
#         self.win = win
#         self.win.set_decorated(False)
#         self.win.set_resizable(True)
# 
#         # Set text depending on login
#         login = is_registered()
#         if login:
#             header = _("Profile activated!")
#             subheader = _(
#                 u"Now you can share stuff, build your character, " \
#                 u"and connect with friends! You've earned some " \
#                 u"rewards\N{HORIZONTAL ELLIPSIS}"
#             )
#             image_name = 'profile-created'
#             button_label = _("LET'S GO")
#         else:
#             header = _("No online profile - for now.")
#             subheader = _(
#                 "Your profile stores all your rewards, projects, and " \
#                 "challenges. But fear not - we'll save everything for " \
#                 "when you have internet."
#             )
#             image_name = 'no-profile-new'
#             button_label = _("LET'S GO")
# 
#         # Set image
#         img_width = 590
#         img_height = 270
#         image_filename = get_image(
#             'login', '', image_name, str(img_width) + 'x' + str(img_height)
#         )
# 
#         # Create template
#         Template.__init__(self, image_filename, header, subheader,
#                           button_label, "")
# 
#         self.win.set_main_widget(self)
#         self.kano_button.connect('button_release_event', self.next_screen)
#         self.kano_button.connect('key_release_event', self.next_screen)
#         self.kano_button.grab_focus()
#         self.win.show_all()
# 
#         # Force the cross button to hide
#         self.win.headerbar.close_button.hide()
# 
#     def next_screen(self, widget, event):
#         # If enter key is pressed or mouse button is clicked
#         if not hasattr(event, 'keyval') or event.keyval == 65293:
#             # Exit
#             sys.exit(0)
# 
# Path: kano_login/templates/template.py
# class Template(Gtk.Box):
# 
#     def __init__(self, img_filename, title, description, kano_button_text, orange_button_text):
#         Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL)
# 
#         if img_filename:
#             self.image = Gtk.Image.new_from_file(img_filename)
#             self.pack_start(self.image, False, False, 0)
# 
#         self.heading = Heading(title, description)
#         self.kano_button = KanoButton(kano_button_text)
# 
#         self.pack_start(self.heading.container, False, False, 0)
# 
#         self.button_box = Gtk.ButtonBox(spacing=10)
#         self.button_box.set_layout(Gtk.ButtonBoxStyle.SPREAD)
#         self.button_box.set_margin_bottom(30)
#         self.pack_start(self.button_box, False, False, 0)
# 
#         if not orange_button_text == "":
#             self.orange_button = OrangeButton(orange_button_text)
#             self.button_box.pack_start(self.orange_button, False, False, 0)
#             self.button_box.pack_start(self.kano_button, False, False, 0)
#             # The empty label is to centre the kano_button
#             label = Gtk.Label("    ")
#             self.button_box.pack_start(label, False, False, 0)
#         else:
#             self.button_box.pack_start(self.kano_button, False, False, 0)
# 
# Path: kano_profile_gui/images.py
# def get_image(category, subcategory, name, subfolder_str):
#     # The online badge image files are stored in the home directory.
#     # The function bellow gets the corrects path.
#     if category == 'badges' and subcategory == 'online':
#         return get_online_badge_path(name)
# 
#     folder = os.path.join(image_dir, category, subfolder_str, subcategory)
#     filename = '{name}.png'.format(name=name)
#     fullpath = os.path.join(folder, filename)
#     if not os.path.exists(fullpath):
#         logger.error("missing image: {}".format(fullpath))
#         return os.path.join(image_dir, 'icons/50/_missing.png')
#         #ensure_dir(folder)
#         #open(fullpath, 'w').close()
#         #print '{} created'.format(fullpath)
#         # try:
#         #     from randomavatar.randomavatar import Avatar
#         #     ensure_dir(folder)
#         #     avatar = Avatar(rows=10, columns=10)
#         #     image_byte_array = avatar.get_image(string=filename, width=width, height=width, pad=10)
#         #     avatar.save(image_byte_array=image_byte_array, save_location=fullpath)
#         #     print '{} created'.format(fullpath)
#         # except Exception:
#         #     return os.path.join(image_dir, 'icons/50/_missing.png')
#     return fullpath
# 
# Path: kano_world/config.py
# AUTH_URL = CONF['auth_url']


# Path: kano_login/first_screen.py
import os
import sys
from gi.repository import Gtk
from kano.gtk3.buttons import KanoButton, OrangeButton
from kano.gtk3.heading import Heading
from kano.network import is_internet
from kano_login.swag_screen import SwagScreen
from kano_login.templates.template import Template
from kano_profile_gui.images import get_image
from kano_world.config import AUTH_URL


    def __init__(self, win, dummy=None):

        FirstScreenTemplate.__init__(self)

        self.win = win
        self.win.set_decorated(False)
        self.win.set_main_widget(self)

        self.kano_button.connect('button_release_event', self.register_screen)
        self.login_button.connect(
            'button_release_event', self.login_screen
        )
        self.skip_button.connect(
            'button_release_event', self.exit_registration
        )

        self.kano_button.connect(
            'key_release_event', self.register_screen
        )
        self.button_box.set_margin_bottom(30)
        self.kano_button.grab_focus()
        self.win.show_all()

    def login_screen(self, widget, event):
        self.win.remove_main_widget()

        if is_internet():
            # Hand-off from the Gtk to the web view
            Gtk.main_quit()

            os.system('{} {} {}'.format(FirstScreen.webengine, AUTH_URL, FirstScreen.win_size))