Esempio n. 1
0
def maybe_init():
    if features.get('ctrl.enable'):
        print 'ctrl enabled (FD=%d)' % features.get('ctrl.fd')
        t = threading.Thread(target=loop)
        t.daemon = True
        t.start()
        ui.idle_hooks.add(idle_sleep)
Esempio n. 2
0
def maybe_init():
    if features.get('ctrl.enable'):
        print 'ctrl enabled (FD=%d)' % features.get('ctrl.fd')
        t = threading.Thread(target=loop)
        t.daemon = True
        t.start()
        ui.idle_hooks.add(idle_sleep)
Esempio n. 3
0
def run():
    if features.get('debug.garbage'):
        gc.set_debug(gc.DEBUG_LEAK)

    while True:
        if osutil.is_paused():
            if features.get('debug.monitor.stop_on_pause'):
                log('log', 'monitor stopped because of pause')
                osutil.wait_for_resume()

        time.sleep(6)
        log('mem_self', get_mem_usage('self'))
        try:
            servpid = get_server_pid()
            server_use = get_mem_usage(servpid)
        except IOError:
            server_use = 'not running'

        log('mem_server', server_use)
        log('gc_stat',
            'counts=%r garbage=%d' % (gc.get_count(), len(gc.garbage)))

        if features.get('debug.gc_count'):
            gc.collect()
            log('gc_count', len(gc.get_objects()))
Esempio n. 4
0
def main_menu():
    global main_menu_item
    main_menu_item = menu = PrettyMenu()

    menu.add(
        ui.Label('version %s' % features.get('app.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('app.multiplayer'):
        menu.left.add(MenuButton('Connect', save.connect_dialog))

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

    ui.replace(menu)
Esempio n. 5
0
def create_window(size):
    graphics.init()
    fullscreen = features.get('ui.fullscreen')
    if fullscreen:
        size = graphics.get_screen_size()
    graphics.create_window(size, fullscreen=fullscreen)
    if features.get('ui.offscreen'):
        graphics.set_offscreen_window(size)
Esempio n. 6
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")))
Esempio n. 7
0
def app_main():
    action = features.get('app.action')
    arg = features.get('app.action_arg')

    if action == 'load_remote':
        from freeciv import dropbox
        dropbox.load_dropbox_save(arg)
    else:
        menus.main_menu()
Esempio n. 8
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(),
        )
    )
Esempio n. 9
0
def app_main():
    action = features.get('app.action')
    arg = features.get('app.action_arg')

    if action == 'load_remote':
        from freeciv import dropbox
        dropbox.load_dropbox_save(arg)
    else:
        menus.main_menu()
Esempio n. 10
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)
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)
Esempio n. 12
0
def get_joystick_type():
    sel = features.get('app.joystick')
    if sel:
        return sel
    else:
        new = features.get('app.new_joystick')
        if new == None:
            return 'tile'
        elif new:
            return 'new'
        else:
            return 'old'
Esempio n. 13
0
def get_joystick_type():
    sel = features.get('app.joystick')
    if sel:
        return sel
    else:
        new = features.get('app.new_joystick')
        if new == None:
            return 'tile'
        elif new:
            return 'new'
        else:
            return 'old'
Esempio n. 14
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)
Esempio n. 15
0
    def __init__(self, client):
        super(ScreenWidget, self).__init__()
        width = 150

        def make_button(name, func):
            return ui.Button(name,
                             func,
                             force_width=ui.scale_for_device(width - 15),
                             padding=1)

        self.client = client

        if features.get('app.map_tiles'):
            import maptiles
            self.map = maptiles.MapWidget(client)
        else:
            self.map = mapdrawer.MapWidget(client, ui.init_zoom_levels())
        self.overview = OverviewWidget(client)
        self.console = ConsoleWidget(client)
        self.menu = gamemenu.Menu(client, ui.screen_width - width)
        self.end_turn_button = make_button('End turn', self.client.end_turn)
        self.empire_button = make_button('Empire', self.empire_dialog)
        self.taxes_panel = TaxesPanel(client)

        self.left_panel = ui.LinearLayoutWidget(spacing=0,
                                                center=True,
                                                marginleft=0)
        self.left_panel.widget_background = (190, 160, 110, 170)

        self.add(self.map, (0, 0))
        self.add(self.menu, (width, 0), align=ui.BOTTOM)
        self.add(self.left_panel, (0, 0), align=ui.LEFT)
        self.update_layout()

        self.left_panel.add(self.overview)
        self.left_panel.add(self.console.scroll)
        self.left_panel.add(self.end_turn_button)
        self.left_panel.add(self.taxes_panel)
        self.left_panel.add(ui.Spacing(0, 10))
        self.left_panel.add(self.empire_button)
        self.left_panel.add(self.menu.left_widget)

        if features.get('app.full_label_toggle_button'):
            full_label_toggle_button = ui.Button('city labels',
                                                 client.toggle_full_labels,
                                                 font=ui.consolefont)
            self.left_panel.add(full_label_toggle_button)

        # key_end_turn()

        self.focus = self.map
Esempio n. 16
0
def main():
    if sys.argv[1:] and sys.argv[1] == 'server':
        from freeciv.client import _freeciv
        import os
        _freeciv.func.py_server_main_run(sys.argv[2:])
        os._exit(0)

    features.parse_options()
    if features.get('debug.dsn'):
        sys.excepthook = early_except_hook

    maybe_setup_launch_param()

    setup_game_version()
    setup_android_version()
    setup_errors()

    maybe_notify_about_launch()
    maybe_start_remote_debug()

    monitor.start()
    if features.get('app.fork'):
        save.start_zygote()

    init_window()
    client.window.init_screen()
    osutil.init()

    #Disable "set_logical_size" feature because
    # - it needs patching SDL
    # - there is a zoom feature in the game.
    # - it makes the graphics to be more blurred because they are zoomed twice when using game zoom
    #if not osutil.is_desktop:
    #    set_logical_size() # Deleted. See lib/ui/core.py:scale_for_device


    ui.init()
    ui.set_fill_image(graphics.load_image('userdata/background.jpg'))

    client.window.init()
    gamescreen.init()

    start_autoupdate()
    start_marketnotice()

    if ctrl:
        ctrl.maybe_init()
    client.freeciv.run(['--log', monitor.get_log_path_base() + '.log'])
Esempio n. 17
0
 def _get_max_size():
     fake = features.get('ui.fake_max_size')
     if fake:
         return map(int, fake.split(','))
     else:
         return pygame.display.Info().current_w, pygame.display.Info(
         ).current_h
Esempio n. 18
0
def show_options():
    options = OptionsPanel(marginleft=10)
    options.add(ui.Label(("Touch" if osutil.is_android else "Click") + " 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")

    if osutil.is_desktop:
        st = "Fullscreen (restart to take effect): "
        options.add_feature_bool(st + "Yes", st + "No", "ui.fullscreen")

    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)
Esempio n. 19
0
def server_loop(port, args=(), line_callback=None, quit_on_disconnect=True):
    assert quit_on_disconnect
    args = (
        '--Ppm',
        '-p',
        str(port),
        '-s',
        get_save_dir(),
    ) + args

    piddir = get_save_dir()
    print 'server args', args

    if features.get('app.fork'):
        stream = zygote_start_server(args)
    else:
        stream = subprocess_start_server(args)

    while True:
        line = stream.readline()
        if not line:
            break
        if line_callback:
            line_callback(line)
        print 'server:', line.rstrip()
Esempio n. 20
0
def init():
    print 'stream enabled (FD=%d)' % features.get('stream.fd')
    import ctrl
    ctrl.bind_event('init_cache', lambda msg: _client_cache.clear())
    ctrl.bind_event('ping', lambda msg: add_message({'type': 'pong'}))
    ui.draw_hooks.add(run)
    ui.layer_hooks.add(layer_hook)
Esempio n. 21
0
def loop():
    input = os.fdopen(features.get('ctrl.fd'), 'r', 1)
    for line in iter(input.readline, ''):
        message = json.loads(line)
        with _message_available:
            _messages.append(message)
            _message_available.notify()
Esempio n. 22
0
def new_game():
    port = random.randint(2000, 15000)
    args = ('-r', './data/%s.serv' % features.get('app.ruleset'))
    gui = ServerGUI()
    start_server(port, args=args, line_callback=gui.server_line_callback)
    gui.connect(port)
    ui.set(gui.ui)
Esempio n. 23
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:
        traceback.print_exc()
        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
Esempio n. 24
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()
Esempio n. 25
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
Esempio n. 26
0
def maybe_notify_about_launch():
    token = features.get('app.launch_token')
    if token:
        ui. async (
            lambda: sync.request('/play/notify',
                                 token=token,
                                 install_time=str(sync.get_install_time())))
Esempio n. 27
0
    def __init__(self, client):
        super(ScreenWidget, self).__init__()
        self.client = client

        self.map = MapWidget(client)
        self.overview = OverviewWidget(client)
        self.console = ConsoleWidget(client)
        self.menu = gamemenu.Menu(client)
        self.end_turn_button = ui.Button('End turn', self.client.end_turn)
        self.empire_button = ui.Button('Empire', self.empire_dialog)
        self.taxes_panel = TaxesPanel(client)

        self.left_panel = ui.LinearLayoutWidget(spacing=0, center=True)
        self.map_wrapper = ui.AbsoluteLayoutWidget()

        self.add(self.left_panel)
        self.add(self.map_wrapper)

        self.map_wrapper.add(self.map, (0, 0))
        self.map_wrapper.add(self.menu, (0, 0), align=ui.BOTTOM)

        self.left_panel.add(self.overview)
        self.left_panel.add(self.console.scroll)
        self.left_panel.add(self.end_turn_button)
        self.left_panel.add(self.taxes_panel)
        self.left_panel.add(ui.Spacing(0, 10))
        self.left_panel.add(self.empire_button)

        if features.get('app.full_label_toggle_button'):
            full_label_toggle_button = ui.Button('city labels', client.toggle_full_labels, font=ui.consolefont)
            self.left_panel.add(full_label_toggle_button)

        # key_end_turn()

        self.focus = self.map
Esempio n. 28
0
def main(args):
    # Get list of feature class names
    feature_list = []
    for name, obj in inspect.getmembers(features):
        if inspect.isclass(obj) and name not in ['SentimentIntensityAnalyzer', 'Feature']:
            feature_list.append(name)

    # construct feature file for each data file
    for data_file in args.data:
        print "\nLoading %s..." % data_file
        with open(data_file, 'rb') as handle:
            data = json.load(handle)
        print "got %d examples" % len(data)

        print "building data..."
        # show a progression bar on the screen
        for feat in feature_list:
            print "feature %s" % feat
            bar = pyprind.ProgBar(len(data), monitor=False, stream=sys.stdout)
            data_features = []
            for idx, msg in enumerate(data):
                # create list of Feature instances
                feature_object = features.get(msg['article'], msg['context'], msg['candidate'], [feat])
                feature_object = feature_object[0]  # only one feature at a time
                data_features.append(feature_object.feat.tolist())
                bar.update()
            # saving feature file
            feature_path = data_file.replace('.json', '.features')
            if not os.path.exists(feature_path):
                os.makedirs(feature_path)
            with open("%s/%s.json" % (feature_path, feat), "wb") as handle:
                json.dump(data_features, handle)
            print "saved feature file %s/%s.json" % (feature_path, feat)
Esempio n. 29
0
def init():
    print 'stream enabled (FD=%d)' % features.get('stream.fd')
    import ctrl
    ctrl.bind_event('init_cache', lambda msg: _client_cache.clear())
    ctrl.bind_event('ping', lambda msg: add_message({'type': 'pong'}))
    ui.draw_hooks.add(run)
    ui.layer_hooks.add(layer_hook)
Esempio n. 30
0
def check_auth():
    if not features.get('civsync.key'):
        login()
        return False
    else:
        init()
        return True
Esempio n. 31
0
 def __init__(self, client):
     super(ScreenWidget, self).__init__()
     self.client = client
     
     self.map = MapWidget(client)
     self.overview = OverviewWidget(client)
     self.console = ConsoleWidget(client)
     self.menu = gamemenu.Menu(client)
     self.end_turn_button = ui.Button('End turn', self.client.end_turn)
     self.empire_button = ui.Button('Empire', self.empire_dialog)
     self.taxes_panel = TaxesPanel(client)
     
     self.left_panel = ui.LinearLayoutWidget(spacing=0, center=True)
     self.map_wrapper = ui.AbsoluteLayoutWidget()
     
     self.add(self.left_panel)
     self.add(self.map_wrapper)
     
     self.map_wrapper.add(self.map, (0, 0))
     self.map_wrapper.add(self.menu, (0, 0), align=ui.BOTTOM)
     
     self.left_panel.add(self.overview)
     self.left_panel.add(self.console.scroll)
     self.left_panel.add(self.end_turn_button)
     self.left_panel.add(self.taxes_panel)
     self.left_panel.add(ui.Spacing(0, 10))
     self.left_panel.add(self.empire_button)
     
     if features.get('app.full_label_toggle_button'):
         full_label_toggle_button = ui.Button('city labels', client.toggle_full_labels, font=ui.consolefont)
         self.left_panel.add(full_label_toggle_button)
     
     # key_end_turn()
     
     self.focus = self.map
def check_auth():
    if not features.get('civsync.key'):
        login()
        return False
    else:
        init()
        return True
Esempio n. 33
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()
Esempio n. 34
0
def loop():
    input = os.fdopen(features.get('ctrl.fd'), 'r', 1)
    for line in iter(input.readline, ''):
        message = json.loads(line)
        with _message_available:
            _messages.append(message)
            _message_available.notify()
Esempio n. 35
0
def show_options():
    options = OptionsPanel(marginleft=10)
    options.add(
        ui.Label(('Touch' if osutil.is_android else 'Click') +
                 ' 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')

    if osutil.is_desktop:
        st = 'Fullscreen (restart to take effect): '
        options.add_feature_bool(st + 'Yes', st + 'No', 'ui.fullscreen')

    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)
Esempio n. 36
0
    def __init__(self, client):
        super(ScreenWidget, self).__init__()
        width = 150

        def make_button(name, func):
            return ui.Button(name, func,
                             force_width=width - 15,
                             padding=1)

        self.client = client

        if features.get('app.map_tiles'):
            import maptiles
            self.map = maptiles.MapWidget(client)
        else:
            self.map = mapdrawer.MapWidget(client)
        self.overview = OverviewWidget(client)
        self.console = ConsoleWidget(client)
        self.menu = gamemenu.Menu(client)
        self.end_turn_button = make_button('End turn', self.client.end_turn)
        self.empire_button = make_button('Empire', self.empire_dialog)
        self.taxes_panel = TaxesPanel(client)

        self.left_panel = ui.LinearLayoutWidget(spacing=0, center=True)
        self.map_wrapper = ui.AbsoluteLayoutWidget()

        self.add(self.left_panel)
        self.add(self.map_wrapper)

        self.map_wrapper.add(self.map, (0, 0))
        self.map_wrapper.add(self.menu, (0, 0), align=ui.BOTTOM)

        self.left_panel.add(self.overview)
        self.left_panel.add(self.console.scroll)
        self.left_panel.add(self.end_turn_button)
        self.left_panel.add(self.taxes_panel)
        self.left_panel.add(ui.Spacing(0, 10))
        self.left_panel.add(self.empire_button)
        self.left_panel.add(self.menu.left_widget)

        if features.get('app.full_label_toggle_button'):
            full_label_toggle_button = ui.Button('city labels', client.toggle_full_labels, font=ui.consolefont)
            self.left_panel.add(full_label_toggle_button)

        # key_end_turn()

        self.focus = self.map
Esempio n. 37
0
def is_paused():
    if is_android:
        if features.get("app.disable_android_pause"):
            return False
        else:
            return android.check_pause()
    else:
        return sig_state == PAUSED
Esempio n. 38
0
def main_menu():
    global main_menu_item
    main_menu_item = menu = PrettyMenu()

    menu.add(ui.Label('version %s' % features.get('app.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('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)
Esempio n. 39
0
def show_options():
    options = OptionsPanel()
    options.add(ui.Label('Touch an option to change'))
    options.add_feature('Shutdown game after %d seconds of pause', 'app.shutdown')
    options.add(ui.Button('Change ruleset for new games', change_ruleset))
    if features.get('app.debug'):
        options.add(ui.Button('Debug', debug_menu))
    ui.set(options)
Esempio n. 40
0
def _impl_save(name, path):
    if not check_auth(): return
    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')))
Esempio n. 41
0
    def __init__(self, client):
        super(ScreenWidget, self).__init__()
        width = 150

        def make_button(name, func):
            return ui.Button(name, func,
                             force_width=ui.scale_for_device(width - 15),
                             padding=1)

        self.client = client

        if features.get('app.map_tiles'):
            import maptiles
            self.map = maptiles.MapWidget(client)
        else:
            self.map = mapdrawer.MapWidget(client, ui.init_zoom_levels())
        self.overview = OverviewWidget(client)
        self.console = ConsoleWidget(client)
        self.menu = gamemenu.Menu(client, ui.screen_width - width)
        self.end_turn_button = make_button('End turn', self.client.end_turn)
        self.empire_button = make_button('Empire', self.empire_dialog)
        self.taxes_panel = TaxesPanel(client)

        self.left_panel = ui.LinearLayoutWidget(spacing=0, center=True, marginleft=0)
        self.left_panel.widget_background = (190, 160, 110, 170)

        self.add(self.map, (0, 0))
        self.add(self.menu, (width, 0), align=ui.BOTTOM)
        self.add(self.left_panel, (0, 0), align=ui.LEFT)
        self.update_layout()

        self.left_panel.add(self.overview)
        self.left_panel.add(self.console.scroll)
        self.left_panel.add(self.end_turn_button)
        self.left_panel.add(self.taxes_panel)
        self.left_panel.add(ui.Spacing(0, 10))
        self.left_panel.add(self.empire_button)
        self.left_panel.add(self.menu.left_widget)

        if features.get('app.full_label_toggle_button'):
            full_label_toggle_button = ui.Button('city labels', client.toggle_full_labels, font=ui.consolefont)
            self.left_panel.add(full_label_toggle_button)

        # key_end_turn()

        self.focus = self.map
Esempio n. 42
0
def is_paused():
    if is_android:
        if features.get("app.disable_android_pause"):
            return False
        else:
            return android.check_pause()
    else:
        return sig_state == PAUSED
Esempio n. 43
0
def main():
    if sys.argv[1:] and sys.argv[1] == 'server':
        from freeciv.client import _freeciv
        import os
        _freeciv.func.py_server_main_run(sys.argv[2:])
        os._exit(0)

    features.parse_options()
    if features.get('debug.dsn'):
        sys.excepthook = early_except_hook

    maybe_setup_launch_param()

    setup_game_version()
    setup_android_version()
    setup_errors()

    maybe_notify_about_launch()
    maybe_start_remote_debug()

    monitor.start()
    if features.get('app.fork'):
        save.start_zygote()

    init_window()
    client.window.init_screen()
    osutil.init()
    if not osutil.is_desktop:
        set_logical_size()

    ui.init()
    ui.set_fill_image(graphics.load_image('data/user/background.jpg'))

    setup_freeciv_config()
    client.window.init()
    gamescreen.init()

    start_autoupdate()
    start_marketnotice()

    if ctrl:
        ctrl.maybe_init()

    client.freeciv.run()
Esempio n. 44
0
def main():
    if sys.argv[1:] and sys.argv[1] == 'server':
        from freeciv.client import _freeciv
        import os
        _freeciv.func.py_server_main_run(sys.argv[2:])
        os._exit(0)

    features.parse_options()
    if features.get('debug.dsn'):
        sys.excepthook = early_except_hook

    maybe_setup_launch_param()

    setup_game_version()
    setup_android_version()
    setup_errors()

    maybe_notify_about_launch()
    maybe_start_remote_debug()

    monitor.start()
    if features.get('app.fork'):
        save.start_zygote()

    init_window()
    client.window.init_screen()
    osutil.init()
    if not osutil.is_desktop:
        set_logical_size()

    ui.init()
    ui.set_fill_image(graphics.load_image('data/user/background.jpg'))

    setup_freeciv_config()
    client.window.init()
    gamescreen.init()

    start_autoupdate()
    start_marketnotice()

    if ctrl:
        ctrl.maybe_init()

    client.freeciv.run()
Esempio n. 45
0
def raven_report(dsn, exc_info=None):
    import ravensimple
    print 'Raven: report exception to', dsn
    exc_type, exc_val, tb = exc_info or sys.exc_info()
    meta = {
        'install_time': sync.get_install_time(),
        'version': features.get('civsync.ua'),
    }
    ui. async (
        lambda: ravensimple.report_exception(exc_val, tb, dsn=dsn, extra=meta))
Esempio n. 46
0
def init():
    graphics.init()

    ui.consolefont = load_font(None, 20)
    ui.smallfont = font = load_font(None, 25)
    ui.mediumfont = load_font(None, 32)
    ui.font = ui.bigfont = load_font(None, 50)

    if features.get('stream.enable'):
        from . import stream
        stream.init()
Esempio n. 47
0
 def _get_request_size(max_size):
     if osutil.is_desktop and not features.get('ui.fake_max_size'):
         return (1280, 800)
     else:
         w, h = max_size
         MAX_W = 1000
         if w > MAX_W:
             scale = h / float(w)
             size = (MAX_W, int(MAX_W * scale))
         else:
             size = (w, h)
         return size
Esempio n. 48
0
def show_main_menu():
    global main_menu
    main_menu = menu = ui.Menu()
    
    menu.add('New game', new_game)
    menu.add('Load game', save.load_dialog)
    menu.add('Feedback', feedback)
    menu.add('Options', options.show_options)
    if features.get('app.multiplayer'):
        menu.add('Connect', save.connect_dialog)
    
    ui.set(menu)
Esempio n. 49
0
def load_dialog():
    menu = ui.LinearLayoutWidget()
    was_any = False
    if features.get('civsync.enable'):
        menu.add(ui.Button('Show CivSync saves', sync.show_load))
    for name, path in get_saves():
        callback = functools.partial(load_game, path)
        menu.add(ui.Button(name, callback))
        was_any = True
    if not was_any:
        menu.add(ui.Label('No saved games yet...'))
    ui.set(ui.ScrollWrapper(menu))
Esempio n. 50
0
def show_options():
    options = OptionsPanel()
    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')
    if features.get('app.debug'):
        options.add(ui.Button('Debug', debug_menu))
    ui.set(options)
Esempio n. 51
0
def client_main():
    if try_resume():
        ui.main()
        return

    ui.set(ui.Label('loading...'))
    ui.execute_later(app_main)

    if features.get('app.profile'):
        profile_main()
    else:
        ui.main()
Esempio n. 52
0
def raven_report(dsn, exc_info=None):
    import ravensimple
    print 'Raven: report exception to', dsn
    exc_type, exc_val, tb = exc_info or sys.exc_info()
    meta = {
        'install_time': sync.get_install_time(),
        'version': features.get('civsync.ua'),
    }
    ui.async(lambda:
             ravensimple.report_exception(
                 exc_val, tb,
                 dsn=dsn, extra=meta))
Esempio n. 53
0
def load_dialog():
    menu = ui.LinearLayoutWidget()
    was_any = False
    if features.get('civsync.enable'):
        menu.add(ui.Button('Show CivSync saves', sync.show_load))
    for name, path in get_saves():
        callback = functools.partial(load_game, path)
        menu.add(ui.Button(name, callback))
        was_any = True
    if not was_any:
        menu.add(ui.Label('No saved games yet...'))
    ui.set(ui.ScrollWrapper(menu))
Esempio n. 54
0
def client_main():
    if try_resume():
        ui.main()
        return

    ui.set(ui.Label('loading...'))
    ui.execute_later(app_main)

    if features.get('app.profile'):
        profile_main()
    else:
        ui.main()
Esempio n. 55
0
 def _get_request_size(max_size):
     if osutil.is_desktop and not features.get('ui.fake_max_size'):
         return (1280, 800)
     else:
         w, h = max_size
         MAX_W = 1000
         if w > MAX_W:
             scale = h / float(w)
             size = (MAX_W, int(MAX_W * scale))
         else:
             size = (w, h)
         return size
Esempio n. 56
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('civsync.com; ' + 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)
Esempio n. 57
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('civsync.com; ' + version + '     ' + get_renderer_label(),
                      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('userdata/options.png')))
    menu.right.add(MenuButton('Exit', ui.back))
    menu.right.add(ui.Spacing(0, 0))

    ui.replace(menu)
Esempio n. 58
0
def start_server(port, args=(), line_callback=None, quit_on_disconnect=True):
    assert quit_on_disconnect
    args = ('-p', str(port), '-s', get_save_dir(), ) + args

    piddir = get_save_dir()
    print 'server args', args

    if features.get('app.fork'):
        stream = zygote_start_server(args)
    else:
        stream = subprocess_start_server(args)
    thread.start_new_thread(server_loop, (stream, line_callback))
    time.sleep(0.3)