def palette_menu(): """prompts for image converter palette method info""" response = convert_shared_menu() response['sample_factor'] = cutie.get_number( '-= Sample grid major dimension (integer):', min_value=1, max_value=999, allow_float=False) print() response['palette_size'] = cutie.get_number( '-= Number of Palette Colors to Return per Sample (8 max, enter 0 for automatic selection):', min_value=0, max_value=8, allow_float=False) print() response['palette_rescale'] = cutie.prompt_yes_or_no( '-= Rescale Image before palette sample (reduces processing time)?', yes_text="Yes, rescale", no_text="No, use original image dimensions", default_is_yes=True, selected_prefix=CON_P, deselected_prefix=DECON_P) return response
def process_args(args, u): processed_args = (True if args.verbose else False, args.limit if args.limit else cutie.get_number( 'Enter post limit:', 0, 999, False), args.sort if args.sort else process_choice_input(), args.threshold if args.threshold else None, True if args.include_albums else False, args.fresh if args.fresh else process_fresh()) manage_playlists(u) if args.playlists else False return processed_args
def connect_udp(self): print("\nConnect by UDP port:") options = ["Manual", "cancel"] settings = load_udp_settings() auto_name = "" if settings: # only show saved option if it loads lip, rport1, rport2 = settings auto_name = "Saved: A-1 ip = "+lip+", computer data port = "+str(rport1)+", computer config port = "+str(rport2) options = [auto_name]+options selected = options[cutie.select(options)] if settings and (selected == auto_name): A1_ip, data_port, config_port = lip, rport1, rport2 elif selected == "Manual": print("enter udp settings: if unsure, connect by com and check configurations") A1_ip = input("A1 ip address: ") data_port = cutie.get_number('data port: ', min_value=1, max_value=65535, allow_float=False) config_port = cutie.get_number('configuration port: ', min_value=1, max_value=65535, allow_float=False) else: # cancel return self.release() #data_connection = UDPConnection(remote_ip=A1_ip, remote_port=UDP_LOCAL_DATA_PORT, local_port=data_port) control_connection = UDPConnection(remote_ip=A1_ip, remote_port=UDP_LOCAL_CONFIG_PORT, local_port=config_port) board = IMUBoard() board.release_connections() board.control_connection = control_connection #board.data_connection = data_connection self.board = board #data_connection = board.data_connection self.serialnum = self.retry_command(method=board.get_serial, response_types=[b'SER']).ser.decode() # this works like a ping - error or timeout if bad connection self.version = self.retry_command(method=board.get_version, response_types=[b'VER']).ver.decode() self.pid = self.retry_command(method=board.get_pid, response_types=[b'PID']).pid.decode() if selected == "Manual": save_udp_settings(A1_ip, data_port, config_port) #send udp start info to io thread: self.udp_ip.value, self.udp_port.value = A1_ip.encode(), data_port self.con_type.value = b"UDP" self.con_on.value = 1 self.con_start.value = 1 return {"type": "UDP", "ip": A1_ip, "port1": str(data_port), "port2": str(config_port)}
def map_size_menu(autoscale=True): """prompts map dimensions""" response = {} if autoscale: response['map_major_dim'] = cutie.get_number('-= Map Major Dimension:', min_value=1, max_value=999, allow_float=False) else: response['map_dim_x'] = cutie.get_number( '-= Map Dimension - Horizontal:', min_value=1, max_value=999, allow_float=False) response['map_dim_y'] = cutie.get_number( '-= Map Dimension - Vertical:', min_value=1, max_value=999, allow_float=False) return response
def main(): """Main. """ if cutie.prompt_yes_or_no('Are you brave enough to continue?'): # List of names to select from, including some captions names = [ 'Kings:', 'Arthur, King of the Britons', 'Knights of the Round Table:', 'Sir Lancelot the Brave', 'Sir Robin the Not-Quite-So-Brave-as-Sir-Lancelot', 'Sir Bedevere the Wise', 'Sir Galahad the Pure', 'Swedish captions:', 'Møøse' ] # Names which are captions and thus not selectable captions = [0, 2, 7] # Get the name name = names[cutie.select(names, caption_indices=captions, selected_index=8)] print(f'Welcome, {name}') # Get an integer greater or equal to 0 age = cutie.get_number('What is your age?', min_value=0, allow_float=False) nemeses_options = [ 'The French', 'The Police', 'The Knights Who Say Ni', 'Women', 'The Black Knight', 'The Bridge Keeper', 'Especially terrifying:', 'The Rabbit of Caerbannog', ] print('Choose your nemeses') # Choose multiple options from a list nemeses_indices = cutie.select_multiple(nemeses_options, caption_indices=[6]) nemeses = [ nemesis for nemesis_index, nemesis in enumerate(nemeses_options) if nemesis_index in nemeses_indices ] # Get input without showing it being typed quest = cutie.secure_input('What is your quest?') print(f'{name}\'s quest (who is {age}) is {quest}.') if nemeses: if len(nemeses) == 1: print(f'His nemesis is {nemeses[0]}.') else: print(f'His nemeses are {" and ".join(nemeses)}.') else: print('He has no nemesis.')
def main(): """Main. """ if cutie.prompt_yes_or_no('Are you brave enough to continue?'): names = [ 'Arthur, King of the Britons', 'Sir Lancelot the Brave', 'Sir Robin the Not-Quite-So-Brave-as-Sir-Lancelot', 'Sir Bedevere the Wise', 'Sir Galahad the Pure', 'Møøse' ] name = names[cutie.select(names, selected_index=5)] print(f'Welcome, {name}') age = cutie.get_number('What is your age?', min_value=0, allow_float=False) quest = cutie.secure_input('What is your quest?') print(f'{name}\'s quest (who is {age}) is {quest}.')
def test_max_value_int_smaller(self): with mock.patch("cutie.input", return_value="1"): self.assertEqual(cutie.get_number("foo", max_value=2), 1)
def test_max_value_int_too_high(self, mock_print): with mock.patch("cutie.input", return_value="2"): with self.assertRaises(MockException): cutie.get_number("foo", max_value=1) mock_print.assert_called_once_with( 'Has to be at most 1.\033[1A\r\033[K', end='')
def test_max_value_float_equal(self): with mock.patch("cutie.input", return_value="1.1"): self.assertEqual(cutie.get_number("foo", max_value=1.1), 1.1)
def test_min_value_int_greater(self): with mock.patch("cutie.input", return_value="2"): self.assertEqual(cutie.get_number("foo", min_value=1), 2)
def main(): # start the game off print("What is your name: ", end="") name = input() player = Player(name) dealer = Player("Dealer") deck = reset_deck() game = True while game: # We stop when you're out of money if player.get_money() <= 0: break # Make a clean screen, show player info print("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n---\n") print(player) print("\n---") # get the bet amount player.set_bet( int( cutie.get_number("What bet would you like to make?", 0, player.get_money()))) player.change_money(0 - player.get_bet()) # Hand should now be two cards player.reset_hand() for i in range(2): card, deck = draw(deck) player.add_to_hand(card) player.print_hand() flag = True busted = False while flag: # Hit and stick become two options in the terminal print("\n~Use the arrow keys and enter to select~\n") opts = ["Hit", "Stick"] opt = cutie.select(opts) if opt == 1: print(f"Hand sum: {player.sum_hand()}") flag = False if opt == 0: card, deck = draw(deck) player.add_to_hand(card) player.print_hand() # Bust if sum > 21 if player.sum_hand() > 21: print("Over 21! You're busted.") busted = True flag = False # if the player stuck, and didn't bust, the dealer goes if not busted: dealer_bust = False # print dealer information print("---\n") print("Dealer:") print("\n---") dealer.reset_hand() for i in range(2): card, deck = draw(deck) dealer.add_to_hand(card) dealer.print_hand() # the wait makes it feel more human time.sleep(1) # dealers hit on 16, stick on 17 while dealer.sum_hand() < 17: print("Dealer hits.\n") card, deck = draw(deck) dealer.add_to_hand(card) dealer.print_hand() time.sleep(1) # the dealer can bust too if dealer.sum_hand() > 21: print("Dealer busts!") dealer_bust = True else: print("Dealer Sticks.") # Victory logic # using the getters to avoid making more variables # tie geets your money back if player.sum_hand() == dealer.sum_hand( ) and player.sum_hand() <= 21: print(f"{player.get_name()} ties.") player.change_money(player.get_bet()) player.set_bet(0) # beating the dealer gets the bet won elif (dealer_bust or player.sum_hand() > dealer.sum_hand() and player.sum_hand() < 21): print(f"{player.get_name()} wins!") player.change_money(2 * player.get_bet()) player.set_bet(0) # blackjack pays 3/2, but that's only Ace and a Face card elif player.sum_hand() > dealer.sum_hand() and player.sum_hand( ) == 21: hand = player.get_hand() if len(hand) == 2 and ("A" in hand): print(f"BLACKJACK!") player.change_money(2 * player.get_bet()) player.change_money(0.5 * player.get_bet()) else: print(f"{player.get_name()} wins!") player.change_money(2 * player.get_bet()) player.set_bet(0) else: print(f"{player.get_name()} loses :(") opts = ["Continue", "Exit"] opt = cutie.select(opts) if opt == 1: game = False final_money = player.get_money() if final_money < 500: print(f"You ended up losing {500-final_money} dollars.") elif final_money == 500: print("You broke even!") else: print(f"You won {final_money-500} dollars!")
def start_ntrip(self): success = False clear_screen() while not success: print("Select NTRIP:") ntrip_settings = load_ntrip_settings() options = ["Manual", "cancel"] captions = [] if ntrip_settings: #saved_string = "Saved: " + str(ntrip_settings) captions = range(1, 1+len(ntrip_settings)) saved_vals = ["\t"+str(k)+": "+str(ntrip_settings[k]) for k in ntrip_settings] options = ["Saved: "] + saved_vals + options selected = options[cutie.select(options, caption_indices=captions)] if selected == "cancel": return elif selected == "Manual": caster = input("caster:") port = int(cutie.get_number("port:")) mountpoint = input("mountpoint:") username = input("username:"******"password:"******"send gga? (requires gps connection)") #TODO - do regular cutie select so style doesn't change? ntrip_settings = {"caster": caster, "port": port, "mountpoint": mountpoint, "username": username, "password": password, "gga": send_gga} save_ntrip_settings(ntrip_settings) # TODO - save later on after confirming it works? else: #Saved #TODO - if any of these missing, can't load from save - check first and hide saved option? caster = ntrip_settings["caster"] port = ntrip_settings["port"] mountpoint = ntrip_settings["mountpoint"] username = ntrip_settings["username"] password = ntrip_settings["password"] send_gga = ntrip_settings["gga"] port = int(port) mountpoint = mountpoint.encode() #ntrip_target = (caster, port) self.ntrip_ip.value = caster.encode() self.ntrip_port.value = port self.ntrip_gga.value = send_gga # seems to convert True/False to 1/0 # _______NTRIP Connection Configs_______ userAgent = b'NTRIP Anello Client' ntrip_version = 1 ntrip_auth = "Basic" #TODO - add more options for these if ntrip_version == 1 and ntrip_auth == "Basic": auth_str = username + ":" + password auth_64 = base64.b64encode(auth_str.encode("ascii")) self.ntrip_req.value = b'GET /' + mountpoint + b' HTTP/1.0\r\nUser-Agent: ' + userAgent + b'\r\nAuthorization: Basic ' + auth_64 + b'\r\n\r\n' else: # TODO make request structure for NTRIP v2, other auth options. print("not implemented: version = " + str(ntrip_version) + ", auth = " + str(ntrip_auth)) self.ntrip_req.value=b'' # will work as False for conditions #signal io_thread to connect the ntrip. clear_screen() self.ntrip_on.value = 1 self.ntrip_start.value = 1 #wait for success or fail message while self.ntrip_succeed.value == 0: continue # should it time out eventually? success = (self.ntrip_succeed.value == 1) # 0 waiting, 1 succeed, 2 fail self.ntrip_succeed.value = 0 debug_print(success)
def test_not_allow_float_returns_int(self): with mock.patch("cutie.input", return_value="1"): val = cutie.get_number("foo", allow_float=False) self.assertIsInstance(val, int) self.assertEqual(val, 1)
def test_allow_float_returns_float(self): with mock.patch("cutie.input", return_value="1.2"): val = cutie.get_number("foo") self.assertIsInstance(val, float) self.assertEqual(val, 1.2)
def test_not_allow_float(self, mock_print): with mock.patch("cutie.input", return_value="1.2"): with self.assertRaises(MockException): cutie.get_number("foo", allow_float=False) mock_print.assert_called_once_with( 'Has to be an integer.\033[K\033[1A\r\033[K', end='')
def test_print_finalize(self, mock_print): with mock.patch("cutie.input", return_value="1"): cutie.get_number("foo") mock_print.assert_called_once_with('\033[K', end='')
def test_invalid_number(self, mock_print): with mock.patch("cutie.input", return_value="foo"): with self.assertRaises(MockException): cutie.get_number("bar") mock_print.assert_called_once_with( 'Not a valid number.\033[K\033[1A\r\033[K', end='')
import cutie import pprint if cutie.prompt_yes_or_no('Are you brave enough to continue?'): # List of names to select from, including some captions names = [ 'Kings:', 'Arthur, King of the Britons', 'Knights of the Round Table:', 'Sir Lancelot the Brave', 'Sir Robin the Not-Quite-So-Brave-as-Sir-Lancelot', 'Sir Bedevere the Wise', 'Sir Galahad the Pure', 'Swedish captions:', 'Møøse' ] # Names which are captions and thus not selectable captions = [0, 2, 7] # Get the name # name = names[cutie.select(names, caption_indices=captions, selected_index=8)] # print(f'Welcome, {name}') # get multiple selected = cutie.select_multiple(names, caption_indices=captions) pprint.pprint(selected) # Get an integer greater or equal to 0 age = cutie.get_number('What is your age?', min_value=0, allow_float=False) # Get input without showing it being typed quest = cutie.secure_input('What is your quest?') print(f'{name}\'s quest (who is {age}) is {quest}.')
def test_min_value_float_greater(self): with mock.patch("cutie.input", return_value="1.3"): self.assertEqual(cutie.get_number("foo", min_value=1.2), 1.3)
def test_min_value_int_too_low(self, mock_print): with mock.patch("cutie.input", return_value="1"): with self.assertRaises(MockException): cutie.get_number("foo", min_value=2) mock_print.assert_called_once_with( 'Has to be at least 2.\033[K\033[1A\r\033[K', end='')