# Path: kano_profile/apps.py
# def get_app_list():
#     if not os.path.exists(apps_dir):
#         return []
#     else:
#         return [p for p in os.listdir(apps_dir)
#                 if os.path.isdir(os.path.join(apps_dir, p))]
# 
# def get_app_data_dir(app_name):
#     data_str = 'data'
#     app_data_dir = os.path.join(get_app_dir(app_name), data_str)
#     return app_data_dir
# 
# def launch_project(app, filename, data_dir, background=False):
#     # This is necessary to support the new official names
#     # TODO: once the apps have been renamed this will not be necessary
#     name_translation = {
#         'make-art': 'kano-draw',
#         'terminal-quest': 'linux-story'
#     }
# 
#     app_tr = name_translation.get(app, app)
# 
#     logger.info("launch_project: {} {} {}".format(app_tr, filename, data_dir))
# 
#     app_profiles = read_json(app_profiles_file)
# 
#     # XML file with complete pathname
#     fullpath = os.path.join(data_dir, filename)
# 
#     # Prepare the command line to open the app with the new project
#     try:
#         cmd = (app_profiles[app_tr]['cmd']
#                .format(fullpath=fullpath, filename=filename))
#     except KeyError as exc:
#         logger.warn(
#             "Can't find app '{}' in the app profiles - [{}]"
#             .format(app_tr, exc)
#         )
#         raise ValueError(_("App '{}' not available").format(app_tr))
# 
#     # Try to load the project if the app is already running, via a signal.
#     _, _, rc = run_cmd('/usr/bin/kano-signal launch-share {}'.format(fullpath))
#     if rc:
#         # Likely the app is not running and the signal could not be sent, so start it now
#         logger.warn("Error sending launch signal, starting the app now, rc={}".format(rc))
#         if background:
#             # TODO: After migrating to launching apps via systemd, shares for make-snake
#             # stopped launching from KW. Created a special case here to avoid
#             # fixing the make-snake cmd through systemd temporarily. FIX THIS.
#             if app == 'make-snake':
#                 run_bg(cmd)
#             else:
#                 run_cmd('systemd-run --user {cmd}'.format(cmd=cmd))
#         else:
#             _, _, rc = run_print_output_error(cmd)
#             return rc
#     else:
#         logger.info("Sent signal to app: {} to open : {}".format(app_tr, fullpath))
# 
#     return 0
# 
# Path: kano_profile/paths.py
# TRACKER_UUIDS_PATH = os.path.join(kanoprofile_dir, 'tracker', 'uuids')
# PAUSED_SESSIONS_FILE = os.path.join(kanoprofile_dir, '.paused_sessions')
# 
# Path: kano_profile_gui/paths.py



import os
import kano.gtk3.cursor as cursor
import kano_profile_gui.components.icons as icons
from gi.repository import Gtk
from kano.utils import get_home, read_json
from kano_profile.apps import get_app_list, get_app_data_dir, launch_project
from kano_profile.paths import app_profiles_file
from kano.logging import logger
from kano.gtk3.scrolled_window import ScrolledWindow
from .paths import image_dir
from kdesk.hourglass import hourglass_start, hourglass_end
#!/usr/bin/env python

# projects.py
#
# Copyright (C) 2014, 2015 Kano Computing Ltd.
# License: http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
#


app_profiles = read_json(app_profiles_file)


# The list of the displayed items
class ProjectList():
    def __init__(self):
        self.width = 646
        self.height = 88

        apps = get_app_list()

        self.projects_list = []

        for app in apps:
            if app in app_profiles:
                if 'ext' in app_profiles[app]:
                    if app_profiles[app]['dir'] == 'kanoprofile':
                        data_dir = get_app_data_dir(app)
                    else:
                        data_dir = os.path.join(get_home(), app_profiles[app]['dir'])


# Path: kano_profile/apps.py
# def get_app_list():
#     if not os.path.exists(apps_dir):
#         return []
#     else:
#         return [p for p in os.listdir(apps_dir)
#                 if os.path.isdir(os.path.join(apps_dir, p))]
# 
# def get_app_data_dir(app_name):
#     data_str = 'data'
#     app_data_dir = os.path.join(get_app_dir(app_name), data_str)
#     return app_data_dir
# 
# def launch_project(app, filename, data_dir, background=False):
#     # This is necessary to support the new official names
#     # TODO: once the apps have been renamed this will not be necessary
#     name_translation = {
#         'make-art': 'kano-draw',
#         'terminal-quest': 'linux-story'
#     }
# 
#     app_tr = name_translation.get(app, app)
# 
#     logger.info("launch_project: {} {} {}".format(app_tr, filename, data_dir))
# 
#     app_profiles = read_json(app_profiles_file)
# 
#     # XML file with complete pathname
#     fullpath = os.path.join(data_dir, filename)
# 
#     # Prepare the command line to open the app with the new project
#     try:
#         cmd = (app_profiles[app_tr]['cmd']
#                .format(fullpath=fullpath, filename=filename))
#     except KeyError as exc:
#         logger.warn(
#             "Can't find app '{}' in the app profiles - [{}]"
#             .format(app_tr, exc)
#         )
#         raise ValueError(_("App '{}' not available").format(app_tr))
# 
#     # Try to load the project if the app is already running, via a signal.
#     _, _, rc = run_cmd('/usr/bin/kano-signal launch-share {}'.format(fullpath))
#     if rc:
#         # Likely the app is not running and the signal could not be sent, so start it now
#         logger.warn("Error sending launch signal, starting the app now, rc={}".format(rc))
#         if background:
#             # TODO: After migrating to launching apps via systemd, shares for make-snake
#             # stopped launching from KW. Created a special case here to avoid
#             # fixing the make-snake cmd through systemd temporarily. FIX THIS.
#             if app == 'make-snake':
#                 run_bg(cmd)
#             else:
#                 run_cmd('systemd-run --user {cmd}'.format(cmd=cmd))
#         else:
#             _, _, rc = run_print_output_error(cmd)
#             return rc
#     else:
#         logger.info("Sent signal to app: {} to open : {}".format(app_tr, fullpath))
# 
#     return 0
# 
# Path: kano_profile/paths.py
# TRACKER_UUIDS_PATH = os.path.join(kanoprofile_dir, 'tracker', 'uuids')
# PAUSED_SESSIONS_FILE = os.path.join(kanoprofile_dir, '.paused_sessions')
# 
# Path: kano_profile_gui/paths.py



# Path: kano_profile_gui/projects.py
import os
import kano.gtk3.cursor as cursor
import kano_profile_gui.components.icons as icons
from gi.repository import Gtk
from kano.utils import get_home, read_json
from kano_profile.apps import get_app_list, get_app_data_dir, launch_project
from kano_profile.paths import app_profiles_file
from kano.logging import logger
from kano.gtk3.scrolled_window import ScrolledWindow
from .paths import image_dir
from kdesk.hourglass import hourglass_start, hourglass_end

#!/usr/bin/env python

# projects.py
#
# Copyright (C) 2014, 2015 Kano Computing Ltd.
# License: http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
#


app_profiles = read_json(app_profiles_file)


# The list of the displayed items
class ProjectList():
    def __init__(self):
        self.width = 646
        self.height = 88

        apps = get_app_list()

        self.projects_list = []

        for app in apps:
            if app in app_profiles:
                if 'ext' in app_profiles[app]:
                    if app_profiles[app]['dir'] == 'kanoprofile':
                        data_dir = get_app_data_dir(app)
                    else:
                        data_dir = os.path.join(get_home(), app_profiles[app]['dir'])


                    icon_path = os.path.join(image_dir, 'icons', app_profiles[app]['icon'])