def out_callback(line): if 'Established control over the server. You have command access level' in line: ui.back(anim=False) start_button = ui.Dialog(ui.screen, ui.Button('Touch to start game', callback)) start_button.back = callback ui.set(start_button, anim=False) sc_client.out_window_callback = None
def _finish(): if text.label: graphics.stop_text_input() finish(text.label) ui.back(allow_override=False) else: _cancel()
def downloaded(data): ui.set_dialog(ui.Label("Loading save...")) uncompressed = lzma.decompress(data) print "Uncompressed size", len(uncompressed) dl_path = save.get_save_dir() + "/downloaded_save" try: os.remove(dl_path) except OSError: print "not removed..." with open(dl_path, "wb") as f: f.write(uncompressed) ui.back(anim=False) save.load_game(dl_path)
def downloaded(data): ui.set_dialog(ui.Label('Loading save...')) uncompressed = lzma.decompress(data) print 'Uncompressed size', len(uncompressed) dl_path = save.get_save_dir() + '/downloaded_save' try: os.remove(dl_path) except OSError: print 'not removed...' with open(dl_path, 'wb') as f: f.write(uncompressed) ui.back(anim=False) save.load_game(dl_path)
def pause(): if client.client: print 'pause occured' print 'saving game' client.client.chat('/save %s/pause_save.sav.gz' % save.get_save_dir()) with open(pause_file, 'w') as f: f.write('version=1\n') time.sleep(features.get('app.shutdown')) if not osutil.is_paused(): remove_pause_file() return print 'turning off server' client.client.disconnect() ui.back(allow_override=False) osutil.wait_for_resume() resume() else: osutil.wait_for_resume()
def pause(): if client.client: print 'pause occured' print 'saving game' client.client.chat('/save %s/pause_save.sav.gz' % save.get_save_dir()) with open(pause_file, 'w') as f: f.write('version=1\n') time.sleep(featues.get('app.shutdown')) if not osutil.is_paused(): remove_pause_file() return print 'turning off server' client.client.disconnect() ui.back(allow_override=False) osutil.wait_for_resume() resume() else: osutil.wait_for_resume()
def comment_upload(install_time): ui.execute_later(lambda: ui.message('Compressing log...')) content = lzma.compress(open(save.get_save_dir() + '/more.log').read()) ui.execute_later(lambda: ui.back()) request(lambda result: comment_next(install_time), 'upload_log', content, install_time, banner="Uploading log (%dkB)" % (len(content)/1024))
def pause(): if client.client: print "pause occured" print "saving game" client.client.chat("/save %s/pause_save.sav.gz" % save.get_save_dir()) with open(pause_file, "w") as f: f.write("version=1\n") time.sleep(features.get("app.shutdown")) if not osutil.is_paused(): remove_pause_file() return print "turning off server" client.client.disconnect() ui.back(allow_override=False) osutil.wait_for_resume() resume() else: osutil.wait_for_resume()
def comment_upload(install_time): ui.execute_later(lambda: ui.message('Compressing log...')) content = lzma.compress(open(save.get_save_dir() + '/more.log').read()) ui.execute_later(lambda: ui.back()) request(lambda result: comment_next(install_time), 'upload_log', content, install_time, banner="Uploading log (%dkB)" % (len(content) / 1024))
def comment_upload(install_time): with ui.execute_later_lock: ui.execute_later.append(lambda: ui.message("Compressing log...")) content = lzma.compress(open(save.get_save_dir() + "/more.log").read()) with ui.execute_later_lock: ui.execute_later.append(lambda: ui.back()) request( lambda result: comment_next(install_time), "upload_log", content, install_time, banner="Uploading log (%dkB)" % (len(content) / 1024), )
def sync_request(callback, name, args, kwargs): func = getattr(client(), name) try: try: result = func(*args, **kwargs) except civsync.LoginError as err: print 'Login failed:', err ui.back(anim=False) self = lambda: request(callback, name, *args, **kwargs) ui.execute_later(lambda: show_login_form(self, str(err))) return except Exception as err: traceback.print_exc() ui.back(anim=False) ui.execute_later(lambda: ui.message('Failed to connect to the internet')) return ui.back(anim=False) ui.execute_later(lambda: callback(result))
def sync_request(callback, name, args, kwargs): func = getattr(client(), name) try: try: result = func(*args, **kwargs) except civsync.LoginError as err: print 'Login failed:', err ui.back(anim=False) self = lambda: request(callback, name, *args, **kwargs) ui.execute_later(lambda: show_login_form(self, str(err))) return except Exception as err: traceback.print_exc() ui.back(anim=False) ui.execute_later( lambda: ui.message('Failed to connect to the internet')) return ui.back(anim=False) ui.execute_later(lambda: callback(result))
def quit(): self.disconnect() ui.back(anim=False) # close dialog ui.back(allow_override=False) # close game
def load_game_now(port, username): client.client.chat('/take "%s"' % username) client.client.chat('/start') client.client.tick() ui.back(allow_override=False)
def clicked(it): ui.back(anim=False) (callback or default_callback)(it)
def do_login(): ui.back(anim=False) request(logged, 'login', login_field.get_value(), passwd_field.get_value())
def comment_next(install_time): ui.back() uidialog.open_url( 'http://%s/comment?install_time=%s&sid=%s&ua=%s' % (civsync.HOST, install_time, client()._sessid, civsync.USER_AGENT))
def commit_government_change(gov): gov.change_to() ui.back()
def logout(): request(lambda d: ui.back(), 'logout')
def set_type(name): features.set_perm('app.joystick', name) ui.back()
def meet(player): ui.back() ui.back() player.meet()
def fcallback(action_ident): self.client.get_unit_in_focus().perform_activity(action_ident) ui.back()
def save_and_sync(client): old_set = set(list_saves(save.get_save_dir())) client.chat('/save') ui.back() threading.Thread(target=save_and_sync_next_step, args=(old_set, )).start()
def load_game_now(port, username): client.client.chat('/take "%s"' % username) client.client.chat('/%s' % features.get('app.difficulty')) client.client.chat('/start') client.client.tick() ui.back(allow_override=False)
def set_nation(style, id): self.city_style = style self.nation_id = id self.set_nation_settings() ui.back()
def back(self): client.client.disconnect() ui.back(allow_override=False)
def save(): self.chat('/save') ui.back()
def set_goal(tech): getattr(tech, func)() self.setup_ui() ui.back()
def save_db(): ui.back() self.save_and_get_name(lambda path: dropbox.save(path))
def do_break_treaty(player, type): player.cancel_pact(type) ui.back() ui.back()
def call_callback(): callback() ui.back()
def close(self): if self.is_opened(): ui.back()
def set_goal(tech): tech.set_as_goal() ui.back()
def back(self): ui.back(allow_override=False, anim=False)
def set_ruleset(name): features.set_perm('app.ruleset', name) ui.back()
def okay(): features.set_perm('civsync.allow_sharing', 'true') ui.back() then()
def never(): features.set_perm('app.marketnotice', False) ui.back()
def focus(unit): unit.focus() ui.back()