def decision_round(player): s = "Your hand: " for card in player.memory["cards"]: s += str(card) + " " s += " | " s += "Hand value: " + str(player.memory["cards_val"]) s += "\n" qprompt.info(s) # Allow user to make a decision in the game if player.memory["cards_val"] >= 21: options = ["Stay", "Exit"] item = qprompt.enum_menu(options).show(header="OPTIONS:") print("Selected " + options[int(item)-1] + ".") qprompt.hrule() return options[int(item)-1] else: options = ["Hit","Stay","Exit"] if player.memory["no_cards"] == 2 and SPLIT_FLAG == False: options.append("Double down") if player.memory["cards"][0].number == player.memory["cards"][1].number: options.append("Split") item = qprompt.enum_menu(options).show(header="OPTIONS:") print("Selected " + options[int(item)-1] + ".") qprompt.clear() return options[int(item)-1]
def test_menu_2(test): """Check for enum_menu() functionality.""" items = ["foo", "bar"] for idx in range(len(items),1): setinput(str(idx)) result = enum_menu(items).show() test.assertEqual(items[idx], items[int(result)])
def test_menu_2(test): """Check for enum_menu() functionality.""" items = ["foo", "bar"] for idx in range(len(items), 1): setinput(str(idx)) result = enum_menu(items).show() test.assertEqual(items[idx], items[int(result)])
def ask_file(dpath, msg="File to review (blank to list)"): """Prompts user for a file to review. Returns the file name.""" path = q.ask_str(msg, blk=True) if not path or not op.isfile(path): vfiles = [op.basename(f) for f in listdir(dpath) if f.endswith(".txt")] path = q.enum_menu(vfiles).show(returns="desc", limit=20) path = op.join(dpath, path) return path
def _config_model(self, config=None): output('开始配置解读模型...') default_model_id = '' default_runtime = 'python3' default_memory_size = 128 default_timeout = 900 if config is not None: section_name = DEFAULT_MODEL_SECTION default_model_id = config_get(config.get, section_name, 'model_id') default_runtime = config_get(config.get, section_name, 'runtime') default_memory_size = config_get(config.getint, section_name, 'memory_size') default_timeout = config_get(config.getint, section_name, 'timeout') model_id = self._input_model_id(default=default_model_id) try: index = RUNTIME_CHOICES.index(default_runtime) except IndexError: index = 0 prompt = '请选择运行环境 [{}]'.format(default_runtime) input_prompt = "请选择" runtime = qprompt.enum_menu(RUNTIME_CHOICES).show(header=prompt, dft=index + 1, returns="desc", msg=input_prompt) try: index = MEMORY_SIZE_CHOICES.index(default_memory_size) except IndexError: index = 0 prompt = '请选择内存占用(MB) [{}]'.format(default_memory_size) input_prompt = "请选择" memory_size = qprompt.enum_menu(MEMORY_SIZE_CHOICES).show( header=prompt, dft=index + 1, returns="desc", msg=input_prompt) prompt = '请输入模型运行超时时间,类型为整数' while True: timeout = qprompt.ask_int(msg=prompt, dft=default_timeout) if (MIN_TIMEOUT and timeout < MIN_TIMEOUT) \ or (MAX_TIMEOUT and timeout > MAX_TIMEOUT): output('超出范围 [{},{}],请重新输入'.format(MIN_TIMEOUT or '', MAX_TIMEOUT or '')) continue break if not timeout: timeout = default_timeout return model_id, runtime, memory_size, timeout
def test_menu_3(test): """Check for enum_menu() functionality.""" menu = Menu() menu.add("s", "skip") items = ["foo", "bar"] menu = enum_menu(items, menu=menu) setinput("1") with test.assertRaises(EOFError): menu.show() setinput("s") result = menu.show(returns="desc") test.assertEqual("skip", result) setinput("2") result = menu.show(returns="desc") test.assertEqual("foo", result) setinput("3") result = menu.show(returns="desc") test.assertEqual("bar", result)
def test_menu_3(test): """Check for enum_menu() functionality.""" menu = Menu() menu.add("s", "skip") items = ["foo", "bar"] menu = enum_menu(items, menu=menu) setinput("1") with test.assertRaises(EOFError): menu.show() setinput("s") result = menu.show(returns="desc") test.assertEqual("skip", result) setinput("2") result = menu.show(returns="desc") test.assertEqual("foo", result) setinput("3") result = menu.show(returns="desc") test.assertEqual("bar", result)
def test_menu_3(self): setinput("n\np\n1") result = enum_menu(self.items).show(limit=3, returns="desc") self.assertEqual("foo", result)
def test_menu_2(self): setinput("n\n4\n") result = enum_menu(self.items).show(limit=3, returns="desc") self.assertEqual("qux", result)
def test_menu_1(self): setinput("4") with self.assertRaises(EOFError): enum_menu(self.items).show(limit=3, returns="desc")
def setUp(test): items = ["foo", "bar", "baz", "qux", "quux"] test.menu = enum_menu(items)
def setUp(test): items = ["foo", "bar", "baz", "qux", "quux"] test.menu = enum_menu(items)
def setUp(self): items = ["foo", "bar", "baz", "qux", "quux"] self.menu = enum_menu(items, default=1)
def test_menu_3(test): setinput("n\np\n1") result = enum_menu(test.items).show(limit=3, returns="desc") test.assertEqual("foo", result)
def test_menu_2(test): setinput("n\n4\n") result = enum_menu(test.items).show(limit=3, returns="desc") test.assertEqual("qux", result)
def test_menu_1(test): setinput("4") with test.assertRaises(EOFError): enum_menu(test.items).show(limit=3, returns="desc")