Ejemplo n.º 1
0
def save_app_state_with_dialog(app_name, data):
    logger.debug('save_app_state_with_dialog {}'.format(app_name))

    old_level, _, old_xp = calculate_kano_level()
    old_badges = calculate_badges()

    save_app_state(app_name, data)

    new_level, _, new_xp = calculate_kano_level()
    new_badges = calculate_badges()

    # TODO: This function needs a bit of refactoring in the future
    # The notifications no longer need to be concatenated to a string

    # new level
    new_level_str = ''
    if old_level != new_level:
        new_level_str = 'level:{}'.format(new_level)

        # A new level has been reached, update the desktop profile icon
        if os.path.exists('/usr/bin/kdesk') and not is_running('kano-sync'):
            logger.info('refreshing kdesk due to new experience level')
            run_bg('kdesk -a profile')

    # new items
    new_items_str = ''
    badge_changes = compare_badges_dict(old_badges, new_badges)
    if badge_changes:
        for category, subcats in badge_changes.iteritems():
            for subcat, items in subcats.iteritems():
                for item, rules in items.iteritems():
                    new_items_str += ' {}:{}:{}'.format(category, subcat, item)

    # Check if XP has changed, if so play sound in the backgrond
    if old_xp != new_xp:
        sound_cmd = 'aplay /usr/share/kano-media/sounds/kano_xp.wav > /dev/null 2>&1 &'
        run_bg(sound_cmd)

    if not new_level_str and not new_items_str:
        return

    if is_gui():
        fifo = open(
            os.path.join(os.path.expanduser('~'), '.kano-notifications.fifo'),
            'w'
        )
        with fifo:
            for notification in (new_level_str + ' ' + new_items_str).split(' '):
                if len(notification) > 0:
                    logger.debug(
                        "Showing the {} notification".format(notification)
                    )
                    fifo.write('{}\n'.format(notification))

    cmd = '{bin_dir}/kano-sync --sync -s'.format(bin_dir=bin_dir)
    run_bg(cmd)
Ejemplo n.º 2
0
def save_app_state_with_dialog(app_name, data):
    logger.debug("save_app_state_with_dialog {}".format(app_name))

    old_level, _, old_xp = calculate_kano_level()
    old_badges = calculate_badges()

    save_app_state(app_name, data)

    new_level, _, new_xp = calculate_kano_level()
    new_badges = calculate_badges()

    # TODO: This function needs a bit of refactoring in the future
    # The notifications no longer need to be concatenated to a string

    # new level
    new_level_str = ''
    if old_level != new_level:
        new_level_str = 'level:{}'.format(new_level)

    # new items
    new_items_str = ''
    badge_changes = compare_badges_dict(old_badges, new_badges)
    if badge_changes:
        for category, subcats in badge_changes.iteritems():
            for subcat, items in subcats.iteritems():
                for item, rules in items.iteritems():
                    new_items_str += ' {}:{}:{}'.format(category, subcat, item)

    # Check if XP has changed, if so play sound in the backgrond
    if old_xp != new_xp:
        sound_cmd = 'aplay /usr/share/kano-media/sounds/kano_xp.wav > /dev/null 2>&1 &'
        run_bg(sound_cmd)

    if not new_level_str and not new_items_str:
        return

    if is_gui():
        # Open the fifo in append mode, as if it is not
        # present, notifications are queued in a flat file
        notifications = (new_level_str + ' ' + new_items_str).split(' ')

        # Write  to both the dashboard and the desktop widget
        f1 = os.path.join(os.path.expanduser('~'), '.kano-notifications.fifo')
        f2 = os.path.join(os.path.expanduser('~'),
                          '.kano-notifications-desktop.fifo')
        write_notifications(f1, notifications)
        write_notifications(f2, notifications)

    cmd = '{bin_dir}/kano-sync --sync -s'.format(bin_dir=bin_dir)
    run_bg(cmd)
Ejemplo n.º 3
0
def save_app_state_with_dialog(app_name, data):
    logger.debug("save_app_state_with_dialog {}".format(app_name))

    old_level, _, old_xp = calculate_kano_level()
    old_badges = calculate_badges()

    save_app_state(app_name, data)

    new_level, _, new_xp = calculate_kano_level()
    new_badges = calculate_badges()

    # TODO: This function needs a bit of refactoring in the future
    # The notifications no longer need to be concatenated to a string

    # new level
    new_level_str = ''
    if old_level != new_level:
        new_level_str = 'level:{}'.format(new_level)

    # new items
    new_items_str = ''
    badge_changes = compare_badges_dict(old_badges, new_badges)
    if badge_changes:
        for category, subcats in badge_changes.iteritems():
            for subcat, items in subcats.iteritems():
                for item, rules in items.iteritems():
                    new_items_str += ' {}:{}:{}'.format(category, subcat, item)

    # Check if XP has changed, if so play sound in the backgrond
    if old_xp != new_xp:
        sound_cmd = 'aplay /usr/share/kano-media/sounds/kano_xp.wav > /dev/null 2>&1 &'
        run_bg(sound_cmd)

    if not new_level_str and not new_items_str:
        return

    if is_gui():
        # Open the fifo in append mode, as if it is not
        # present, notifications are queued in a flat file
        notifications = (new_level_str + ' ' + new_items_str).split(' ')
        
        # Write  to both the dashboard and the desktop widget
        f1 = os.path.join(os.path.expanduser('~'), '.kano-notifications.fifo')
        f2 = os.path.join(os.path.expanduser('~'), '.kano-notifications-desktop.fifo')
        write_notifications(f1, notifications)
        write_notifications(f2, notifications)

    cmd = '{bin_dir}/kano-sync --sync -s'.format(bin_dir=bin_dir)
    run_bg(cmd)
Ejemplo n.º 4
0
def root_check():
    from kano.gtk3 import kano_dialog

    user = os.environ['LOGNAME']
    if user != 'root':
        description = 'kano-updater must be executed with root privileges'
        logger.error(description)

        if is_gui():
            kdialog = kano_dialog.KanoDialog(
                _("Error!"),
                _("kano-updater must be executed with root privileges")
            )
            kdialog.run()
        sys.exit(description)
Ejemplo n.º 5
0
def root_check():
    from kano.gtk3 import kano_dialog

    user = os.environ['LOGNAME']
    if user != 'root':
        description = 'kano-updater must be executed with root privileges'
        logger.error(description)

        if is_gui():
            kdialog = kano_dialog.KanoDialog(
                _("Error!"),
                _("kano-updater must be executed with root privileges")
            )
            kdialog.run()
        sys.exit(description)
Ejemplo n.º 6
0
#

import graphics
import theme
import gameloop
import sys

from kano.utils import is_gui


def exit():
    graphics.exit()


def run():
    try:
        # Init the editor
        graphics.init()
        theme.init()

        # Start the editor
        gameloop.start()

    except KeyboardInterrupt:
        exit()

if not is_gui():
    sys.exit("make-snake requires an X session")

run()
Ejemplo n.º 7
0
        pass
    if save_state:
        gs.save_state()
    sys.exit()


def run():
    try:
        # Init the game
        parser.init()
        # Check for editor
        if (parser.args.editor):
            os.system("/usr/share/make-snake/snake-editor/__main__.py")
            sys.exit(0)
        graphics.init()
        theme.init()
        stage.init()
        game.reset()
        gs.load_state()

        # Start the game
        gameloop.start()

    except KeyboardInterrupt:
        exit()

if not is_gui():
    sys.exit("make-snake requires an X session")

run()