def new_guest(file_name): # Add new guest to guest_book file clear() print("<<< Add new guest >>>\n") while True: guest = input("Please enter your guest name: ") if guest == '': display_menu() break else: try: with open(file_name, 'r+') as file_obj: guests = file_obj.read() if guest in guests: print('Guest already exists!') elif len(guest.strip()) > 0: file_obj.write(guest + "\n") print('New guest added to list') else: print('Invlid input!!!') except FileNotFoundError: print(f"\nFilename--> '{file_name} ' not found! Please check you data file.\n") time.sleep(2) display_menu() break
def handle_password_finish(): if ("").join(password_input_array) == PASSWORD: print("解锁成功!") lock_open() screen.clear() text_with_shadow("解锁成功!%d秒后返回..." % WAIT_S_SUCCESS, shadowOffsetX=2) time.sleep_ms(1000) for i in range(WAIT_S_SUCCESS - 1): text_with_shadow("解锁成功!%d秒后返回..." % (WAIT_S_SUCCESS - i - 1), shadowBgColor=False) time.sleep_ms(1000) lock_close() initialize() else: print("解锁失败!") screen.clear() text_with_shadow("解锁失败!%d秒后返回..." % WAIT_S_FAIL, shadowOffsetX=2) time.sleep_ms(1000) for i in range(WAIT_S_FAIL - 1): text_with_shadow("解锁失败!%d秒后返回..." % (WAIT_S_FAIL - i - 1), shadowBgColor=False) time.sleep_ms(1000) initialize()
def draw_points_screen(): screen.set_cursor_visibility(False) points = 0 points += survivors.distance_travelled for survivor in survivors.survivor_list: if survivor["alive"]: points += survivor["health"] big_font = figlet_helper.load_font("resources/fonts/big.flf") score_title_x = int((screen.get_width() / 2) - ( figlet_helper.get_text_width("Total Score", big_font) / 2)) score_x = int((screen.get_width() / 2) - (figlet_helper.get_text_width(str(int(points)), big_font) / 2)) screen.draw_ascii_font_text(score_title_x - 1, 1, "Total Score", big_font) screen.draw_ascii_font_text(score_x - 1, big_font["height"] + 1, str(int(points)), big_font) screen.flush() time.sleep(2) screen.print_notification("Press any key to exit.", False) screen.clear() quit()
def start_up(): prompt = '\nPlease select letter on Option Menu:' select_menu = True display_menu() while select_menu: choices = input(prompt) choices = choices.upper() if choices == 'N': new_guest(file_name) elif choices == 'D': clear() display_guests(file_name) input("\nPlease any key to back to main menu....") display_menu() elif choices == 'R': remove_guests(file_name) elif choices == "E": empty_guests(file_name) elif choices == 'Q': clear() select_menu = False else: print("Invalid selection!")
def remove_guests(file_name): clear() display_guests(file_name) print("\n<< Removed Guest form guestbook >>\n") try: guest_book = open(file_name) guests_list = guest_book.readlines() guest_book.close() name = input("Please enter name of guest to be REMOVED: ") name = name+"\n" if name in guests_list: guests_list.remove(name) with open(file_name,'w') as edit_file_obj: for guest in guests_list: edit_file_obj.write(guest) print(f'{name.strip()} was removed from guest book.') else: print(f'{name} was not found!') input("\nPlease any key to back to main menu....") display_menu() except FileNotFoundError: print(f"\nFilename--> '{file_name} ' not found! Please check you data file.\n")
def main(): screen.clear() printScreen() edad = pedirEdad() precioTotal = 0 while edad != 0: tipoE = tipoEntrada(edad) precioE = preciosE[tipoE] numEntradas[tipoE] += 1 screen.Print(numEntradas[tipoE], entradaQ[tipoE]['cantidad'][0], entradaQ[tipoE]['cantidad'][1]) screen.Print("{:7.2f}€".format(precioE * numEntradas[tipoE]), entradaQ[tipoE]['precioA'][0], entradaQ[tipoE]['precioA'][1]) precioTotal += precioE screen.Format(1) screen.Print("{:7.2f}€".format(precioTotal), 9, 19) screen.Format(0) edad = pedirEdad() screen.locate(12, 1)
def shutdown(): screen.clear() screen.line1("Goodbye!", True) sleep(1) screen.stop() os.system("sudo poweroff") exit()
def handle_password_finish(): if ("").join(password_input_array) == PASSWORD: print("解锁成功!") lock_open() screen.clear() pic_tab["tip_success"].draw(135, 115) pic_tab["tip_delay"].draw(87, 110) for i in range(WAIT_S_SUCCESS): pic_tab["password"]["nums"][WAIT_S_SUCCESS - i].draw(87, 112) time.sleep_ms(1000) lock_close() initialize() else: print("解锁失败!") screen.clear() pic_tab["tip_failed"].draw(135, 115) pic_tab["tip_delay"].draw(87, 110) for i in range(WAIT_S_FAIL): pic_tab["password"]["nums"][WAIT_S_FAIL - i].draw(87, 112) time.sleep_ms(1000) initialize()
def editList(title, data): if len(data[title]) > 0: response = user_input.getSafeInput( f"Would you like to ADD or REMOVE {title} from the list? ", ["ADD", "REMOVE", "QUIT"]) response = response.upper() if response == "QUIT": return else: response = "ADD" screen.clear() if response == "REMOVE": screen.printUuid(title, data[title]) print(strings.list_edit(title, response)) new_list = user_input.checkInput() if response == "ADD": for new in new_list: data[title] = listAppend(new, data[title]) else: errors = [] for new in new_list: try: data[title] = listRemove(new, data[title]) except: errors.append(new) if len(errors) > 0: print("The following could not be removed:", ', '.join(errors)) return data
def __init__(self, hour, minute, second): # 布局变量 self.startX = 10 # 时钟左上角坐标X self.startY = 100 # 时钟左上角坐标Y self.margin = 8 # 数字健距 self.edgeL = 24 # 数字边长 self.edgeW = 2 # 数字边宽 self.colon = int(self.edgeL / 2) # 冒号间距 # 显示变量 self.colorDict = {0: 0xffffff, 1: 0x000000} # 数字边颜色0白色1黑色 self.numDict = {0: (1, 0, 1, 1, 1, 1, 1), # 数字对应的显示列表 1: (0, 0, 0, 0, 0, 1, 1), 2: (1, 1, 1, 0, 1, 1, 0), 3: (1, 1, 1, 0, 0, 1, 1), 4: (0, 1, 0, 1, 0, 1, 1), 5: (1, 1, 1, 1, 0, 0, 1), 6: (1, 1, 1, 1, 1, 0, 1), 7: (1, 0, 0, 0, 0, 1, 1), 8: (1, 1, 1, 1, 1, 1, 1), 9: (1, 1, 1, 1, 0, 1, 1)} # 时间变量 self.hur = hour self.min = minute self.sec = second # 初始化显示 screen.clear() self.displayColon()
def displayInit(self): #开始游戏初始化 screen.clear() self.grid() for self.selectYi in range(11): for self.selectXi in range(11): self.board[self.selectYi][self.selectXi][2] = 0 self.selectInit()
def __init__(self, name='unknown'): self.name = name self.pos = [10, 10] self.oldpos = None self.HP_TOTAL = 100 self.hp = 50 self.BP_TOTAL = 100 # fa li zhi self.bp = 50 self.originX = 4 self.originY = 4 self.map_width = 60 self.map_height = 20 self.map_color = screen.c(const.FORE_WHITE, const.BACK_WHITE, ' ') self.start_time = time.time() screen.clear() self._draw_map() self._draw_status() def update_time(): while True: self._draw_time(time.time()-self.start_time) time.sleep(0.5) self.damage(-1) self.consume(-2) t = threading.Thread(target=update_time, name='update_time') t.setDaemon(True) t.start()
def initialize(): global password_input_array global key_last_state global key_new_state global password_show #初始化界面 screen.clear() password_show = False for i in range(len(password_input_array)): password_input_array.pop() for i in range(len(key_last_state)): key_last_state.pop() for i in range(len(PADS)): key_last_state.append(False) for i in range(len(KEYS)): key_last_state.append(False) for i in range(len(key_new_state)): key_new_state.pop() text_with_shadow("请输入解锁密码:", y=67, shadowOffsetX=2) if PASSWORD_SHOW_ENABLE: text_with_shadow("【S1】显示密码", y=212, shadowOffsetX=2) text_with_shadow("【S2】清空密码", y=236, shadowOffsetX=2) text_with_shadow("【S4】删除密码", y=260, shadowOffsetX=2) else: text_with_shadow("【S2】清空密码", y=224, shadowOffsetX=2) text_with_shadow("【S4】删除密码", y=248, shadowOffsetX=2) for i in range(password_len): text_password(i, False)
def _update_menu_screen(): screen.clear() screen.line1(_sub_menus[_sub_menu_index].name, True) select_text = "SELECT" if hasattr(_sub_menus[_sub_menu_index], "get_select_text"): select_text = _sub_menus[_sub_menu_index].get_select_text() screen.line2(select_text, True)
def display_info(heading, *lines, end_line='Press any key to continue.'): """Display a set of lines on screen""" screen.clear() screen.print(make_list(heading, lines)) screen.move(0, -1) if end_line: screen.print(' ' + end_line) wait_for_key()
def draw_info_screen(): screen.clear() print("There should be some info here!") print() print("Press enter to continue...") screen.wait_key() open_screen(screen_list["starting"])
def drawClock(self): screen.clear() # 画表盘 for i in range(60): if i % 5 == 0: # 画时刻度 长线 screen.drawline(self.cirStart[i][0], self.cirStart[i][1], self.cirEnd2[i][0], self.cirEnd2[i][1], 3, 0x000000) else: # 画秒刻度 短线 screen.drawline(self.cirStart[i][0], self.cirStart[i][1], self.cirEnd1[i][0], self.cirEnd1[i][1], 2, 0x000000)
def __init__(self): screen.clear() # 清屏 self.grid = Grid() # 初始化格栅系统 self.snake = Snake(self.grid) # 初始化蛇 self.food = Food(self.grid) # 初始化食物 self.gameover = False # 游戏结束标志位 self.score = 0 # 分数 self.speed = 125 # 时间间隔,反比于速度 self.display_food() # 展示一个食物
def __init__(self): screen.clear() self.grid = Grid() self.snake = Snake(self.grid) self.food = Food(self.grid) self.gameover = False self.score = 0 self.status = ['run', 'stop'] self.speed = 300 self.display_food()
def printScreen(): screen.clear() screen.Print("Bebe....: -", line=4, column=5) screen.Print("Niño....: -", line=5, column=5) screen.Print("Adulto..: -", line=6, column=5) screen.Print("Jubilado: -", line=7, column=5) screen.Format(1) screen.Print("Total....:", line=9, column=8) screen.Reset()
def simple_input(heading, prompt): """Simple single field string input""" h, g = 11, 3 screen.clear() s = tx.overlay(tx.border(), logo(), tx.ln(tx.la(heading, 4), h), tx.ln(tx.la('=' * 69), h + 1), tx.ln(tx.la(prompt, 4), h + g)) screen.print(s) screen.move(len(prompt) + 6, h + g) x = input() return x
def input_form(heading, types, prompts, *lines): """Ask the user to fill in an input form. Types is a string consisting of the inputs to take. Three types are currently supported: string, number and password. For example, 'ssnpn' passed to types will ask for two strings, one numeric value, one password and one more string in that order. Prompts is an array consisting of prompts for each corresponding input. """ inputs = [] lines = list(lines) if lines: lines.append('') for x in types: inputs.append((x, None)) for i, x in enumerate(inputs): done = False ask_int = False ask_pass = False while not done: s = make_list(heading, lines + prompts) screen.clear() screen.print(s) if ask_int: screen.move(0, -1) screen.print(" Please enter a numeric value.") if ask_pass: screen.move(0, -1) screen.print(" Please enter a valid password.") screen.move(len(prompts[i]) + 6, 14 + len(lines) + i) if x[0] == 'p': import getpass inp = getpass.getpass(prompt='').strip() if ' ' in inp: ask_pass = True continue else: inp = input().strip() if x[0] == 'n': try: inputs[i] = (x[0], float(inp)) except ValueError: if not inp: inputs[i] = (x[0], 0) else: ask_int = True continue else: inputs[i] = (x[0], inp) prompts[i] += ' ' + inp done = True return [x[1] for x in inputs]
def display_menu(): # Display menu option selection clear() print("+- - - - - - - - - - - - - - - -+") print("| This is a Guest Book Sample |") print("| * * * GUEST LIST MENU * * * |") print("+- - - - - - - - - - - - - - - -+") print('\n\t[N]ew Guest') print('\t[D]isplay Guest') print('\t[R]emoved Guest') print('\t[E]mpty Guest List') print('\t[Q]uit Guest Book')
def draw_starting_screen(): title_text = "Survival Trail" big_font = figlet_helper.load_font("resources/fonts/big.flf") title_width = figlet_helper.get_text_width(title_text, big_font) start_title_x = int((screen.get_width() / 2) - (title_width / 2)) while True: selected_index = 1 while True: screen.set_cursor_visibility(False) decisions = [ "Travel the trail", "Learn more about the trail", "Exit the trail" ] screen.draw_ascii_font_text(start_title_x, 0, title_text, big_font) screen.draw_decision(None, 10, decisions, selected_index) screen.flush() selected_index, finished = screen.get_decision_input( decisions, selected_index) if finished: screen.set_cursor_visibility(True) break if selected_index == 1: screen.set_cursor_visibility(False) screen.draw_decision_box( "You wake up in a dark, abandoned hospital. Looking around the room you notice that the windows are boarded up with the marks all over the walls: \"There is no escape you will all die and suffer\". You quickly get out of your bed, your legs feel shaky as you notice that the calendar says is turned to October 15th 2020. The last memory you have was a hospital visit for a friend on that exact day four years before.\n\nYou quickly compose your thoughts, and decide to head for New York. Before you leave, you gather up 3 friends you know you can count on.", ["Continue"]) screen.flush() screen.wait_key() screen.set_cursor_visibility(True) open_screen(screen_list["survivor_name"]) elif selected_index == 2: open_screen(screen_list["info"]) elif selected_index == 3: screen.clear() quit() else: continue return
def on_press(key): servo_list = [arm.servos[6], arm.servos[2], arm.servos[1]] linear_move = False rotation_move = False try: if key == Key.up: arm.z += 5 linear_move = True if key == Key.down: arm.z -= 5 linear_move = True if key == Key.left: arm.x -= 5 linear_move = True if key == Key.right: arm.x += 5 linear_move = True if key == KeyCode(char='w'): arm.theta += 1 linear_move = True if key == KeyCode(char='s'): arm.theta -= 1 linear_move = True if key == KeyCode(char='a'): servo_list[0].deg += 5 rotation_move = True if key == KeyCode(char='d'): servo_list[0].deg -= 5 rotation_move = True if key == KeyCode(char='q'): servo_list[1].deg -= 5 rotation_move = True if key == KeyCode(char='e'): servo_list[1].deg += 5 rotation_move = True if key == KeyCode(char='o'): servo_list[2].deg -= 20 rotation_move = True if key == KeyCode(char='c'): servo_list[2].deg += 20 rotation_move = True if key == Key.esc: exit(0) clear() if linear_move: arm.generate_position(arm.x, arm.z, arm.theta) if rotation_move: arm.move_to_pos(servo_list, 100) except ValueError: print('Cannot move there')
def draw_survivor_name_screen(): screen.clear() name = get_max_user_input("Try to remember your name: ", "Enter a valid name: ", 16) # Leave the name as default when player enters nothing if len(name) > 0: survivors.survivor_list[0]["name"] = name for i in range(0, 3): name = get_max_user_input( "Enter a friend's name who you can count on: ", "Enter a valid friend's name: ", 16) if len(name) > 0: survivors.survivor_list[i + 1]["name"] = name open_screen(screen_list["city"])
def finish(): """Display the exit screen""" screen.clear() random.seed(time.time()) backs = random.sample([ cl.Back.MAGENTA, cl.Back.GREEN, cl.Back.RED, cl.Back.YELLOW, cl.Back.LIGHTRED_EX, cl.Back.LIGHTBLACK_EX, cl.Back.LIGHTMAGENTA_EX, cl.Back.MAGENTA ], 8) screen.print( cl.Fore.BLACK + random.choice(backs) + tx.overlay(tx.border(), logo(), tx.ln(tx.la("Have a nice day!"), -2), tx.ln(tx.la("Thanks for using bank9000™."), -3))) time.sleep(2) screen.print(cl.Fore.RESET + cl.Back.RESET) screen.clear() screen.print("bank9000™\n")
def empty_guests(file_name): clear() print("<< Guestbook Deletion >>\n") yes_no = input('Are you sure you want to ERASE all you guest list[Y]es/[N]? :') if yes_no.upper() == 'Y': try: f = open(file_name, 'w') f.write('') f.close() print("Guest List is now empty!!!") except FileNotFoundError: print(f"\nFilename--> '{file_name} ' not found! Please check you data file.\n") else: print("Deletion Cancelled...") input("\nPlease any key to back to main menu....") display_menu()