Example #1
0
def save(path):
    if features.get('civsync.allow_sharing') == 'none':
        return ask_if_sharing_allowed(lambda: save(path))
    if not check_auth(): return
    name = make_name(path)
    print 'uploading', path, 'as', name
    DropboxHelper.uploadFile(path, name)
    ui.async(lambda: sync.request_with_sid('/sync/uploading', name=name,
                                           sharing=features.get('civsync.allow_sharing')))
Example #2
0
def init():
    print 'DropboxHelper init'
    global DropboxHelper
    if not DropboxHelper:
        DropboxHelper = jnius_reflect.autoclass('com.zielm.freeciv.DropboxHelper')
        print 'initializing DropboxHelper tokens'
        tokenKey = features.get('civsync.key')
        tokenSecret = features.get('civsync.secret')
        DropboxHelper.setTokens(tokenKey, tokenSecret)
        DropboxHelper.init()
        ui.execute_later(_message_checker)
Example #3
0
def _callback(funname, *args):
    if debug:
        start_time = time.time()
        if features.get('debug.freeciv.print_callbacks'):
            global callback_num
            callback_num += 1
            if not funname.startswith(('canvas_', 'update_mouse_cursor')):
                print '[callback % 7d]' % callback_num, funname
    try:
        args = tuple(args)
        name = funname
        if hasattr(callback, name):
            ret = getattr(callback, name)(*args)
            if not isinstance(ret, (list, tuple)):
                ret = (ret, )
            return ret
        else:
            print 'no function named %s %s' % (name, args)
    except Exception as ex:
        if not isinstance(ex, (KeyboardInterrupt, SystemExit)):
            traceback.print_exc(limit=200)
        else:
            print type(ex).__name__
        print 'Abort.'
        _end_callbacks()
        if hard_exit:
            os._exit(1)
        else:
            sys.exit(1)
    finally:
        if debug:
            tpl = _profiling_callback[funname]
            tpl[0] += 1
            tpl[1] += time.time() - start_time
Example #4
0
def check_auth():
    if not features.get('civsync.key'):
        login()
        return False
    else:
        init()
        return True
def _callback(funname, *args):
    if debug:
        start_time = time.time()
        if features.get('debug.freeciv.print_callbacks'):
            global callback_num
            callback_num += 1
            if not funname.startswith(('canvas_', 'update_mouse_cursor')):
                print '[callback % 7d]' % callback_num, funname
    try:
        args = tuple(args)
        name = funname
        if hasattr(callback, name):
            ret = getattr(callback, name)(*args)
            if not isinstance(ret, (list, tuple)):
                ret = (ret, )
            return ret
        else:
            print 'no function named %s %s' % (name, args)
    except Exception as ex:
        if not isinstance(ex, (KeyboardInterrupt, SystemExit)):
            traceback.print_exc(limit=200)
        else:
            print type(ex).__name__
        print 'Abort.'
        _end_callbacks()
        if hard_exit:
            os._exit(1)
        else:
            sys.exit(1)
    finally:
        if debug:
            tpl = _profiling_callback[funname]
            tpl[0] += 1
            tpl[1] += time.time() - start_time
Example #6
0
 def _callback(self):
     try:
         val = features.get(self.feature_key)
         features.set_perm(self.feature_key, not val)
     except ValueError as e:
         ui.message(str(e), type='error')
     self.make_button()
Example #7
0
def main_menu():
    global main_menu_item
    main_menu_item = menu = PrettyMenu()

    version = 'version %s' % features.get('app.version')
    if features.get('gold.status') != 'none':
        version += '+' + features.get('gold.status')
    if features.get('gold.session_warning'):
        version += ' WARNING! Login with Dropbox in options menu to save your purchases.'
    menu.add(ui.Label(version,
                      color=(255, 0, 0, 150), font=ui.consolefont), (0, 0))

    new_game_button = MenuButton('New\ngame', new_game_menu)
    menu.left.add(new_game_button)

    load_game_button = MenuButton('Load\ngame', save.load_dialog)
    menu.left.add(load_game_button)

    if features.get('gold.enable'):
        gold_button = MenuButton(u'civsync\n  Gold', gold.menu)
        gold_button.fg = (255, 215, 0)
        gold_button.bg = (255, 215, 0, 100)
        menu.left.add(gold_button)

    if features.get('app.multiplayer'):
        menu.left.add(MenuButton('Connect', save.connect_dialog))

    menu.right.add(MenuButton('', options.show_options, image=ui.load_image('data/user/options.png')))
    menu.right.add(MenuButton('Exit', ui.back))
    menu.right.add(ui.Spacing(0, 0))

    ui.replace(menu)
Example #8
0
def show_options():
    options = OptionsPanel(marginleft=10)
    options.add(ui.Label('Touch an option to change'))
    options.add_feature('Shutdown game after %d seconds of pause', 'app.shutdown')
    #options.add_feature_bool('New joystick', 'Old joystick', 'app.new_joystick')
    options.add(ui.Button('Change joystick', change_joystick))
    options.add(ui.Button('Change ruleset for new games', change_ruleset))
    st = 'Full city label toggle button:'
    options.add_feature_bool(st + ' show', st + ' hide', 'app.full_label_toggle_button')

    options.add(dropbox.DBButton('Login to Dropbox', lambda: dropbox.login()))

    if features.get('app.debug'):
        options.add(ui.Button('Debug', debug_menu))


    options.add(ui.Label('Freeciv for Android is licensed under GNU/GPL. \n' \
                         'Dropbox and Dropbox logo are trademarks of Dropbox, Inc.\n', ))
    ui.set(options)
Example #9
0
def maybe_check_products():
    if features.get('gold.initiated'):
        # if user ever wanted to get gold, check if he did it
        check_products()
Example #10
0
def tell_civsync():
    ui.async(lambda: sync.request_with_sid('/sync/register',
                                           key=features.get('civsync.key'),
                                           secret=features.get('civsync.secret'),
                                           install_time=sync.get_install_time()))
Example #11
0
 def console_line(self, text):
     if self.out_window_callback:
         self.out_window_callback(text)
     monitor.log('outwindow', text)
     if features.get('debug.outwindow'):
         print '[OutWindow]', text
 def console_line(self, text):
     if self.out_window_callback:
         self.out_window_callback(text)
     monitor.log('outwindow', text)
     if features.get('debug.outwindow'):
         print '[OutWindow]', text
Example #13
0
 def make_button(self):
     text = self.label_t if features.get(self.feature_key) else self.label_f
     self.set_text(text)
Example #14
0
 def make_button(self):
     text = self.feature_label % features.get(self.feature_key)
     self.set_text(text)