def show(): option_tuple = ('New flight route', 'Show all flight routes') valid_user_inputs = ComponentUI.make_valid_menu_options_tuple( len(option_tuple)) frame_functions = (FlightRouteUI.__show_new_flight_route_constructor, FlightRouteUI.__show_all_flight_routes) return ComponentUI.run_frame(option_tuple, FlightRouteUI.__FRAME_IN_USE_STR, valid_user_inputs, frame_functions)
def show(): valid_user_inputs = ComponentUI.make_valid_menu_options_tuple( len(EmployeeUI.__option_tuple)) frame_functions = (EmployeeUI.__show_new_employee_constructor, EmployeeUI.__show_all_employees, EmployeeUI.__show_all_pilots,\ EmployeeUI.__show_all_flight_attendants, EmployeeUI.__show_employee_by_name_finder, EmployeeUI.__show_pilot_by_license_finder,\ EmployeeUI.__show_employees_on_duty, EmployeeUI.__show_employees_off_duty) return ComponentUI.run_frame(EmployeeUI.__option_tuple, EmployeeUI.__FRAME_IN_USE_STR, valid_user_inputs, frame_functions)
def show(): #The options that show up at the start of this frame option_tuple = ('New airplane', 'Show all airplanes', 'Show airplanes in use', 'Show all airplane types') #The different inputs that allow the user to interact with this frame valid_user_inputs = ComponentUI.make_valid_menu_options_tuple(len(option_tuple)) #The functions that this frame has stored in a tuple frame_functions = (AirplanesUI.__show_new_airplane_constructor, AirplanesUI.__show_all_airplanes,\ AirplanesUI.__show_airplanes_in_use, AirplanesUI.__show_all_airplane_types) return ComponentUI.run_frame(option_tuple, AirplanesUI.__FRAME_IN_USE_STR, valid_user_inputs, frame_functions)
def __show_new_airplane_constructor(): option_tuple = ("Name", "Type", "Manufacturer", "Seating capacity") valid_user_inputs = ComponentUI.make_valid_menu_options_tuple(len(option_tuple)) input_message_tuple = ("Insert Name: ", "Insert Type: ", "Insert Manufacturer: ", "Insert Seating capacity: ") user_input_list = [""] * len(option_tuple) user_input_list.append(State.get_airplane_states()[0]) #State default value valid_for_submit_list = [False, False] # only 2 chosse here * len(option_tuple) #list that contains bools if all true then ok to submit user_input = "" while user_input not in AirplanesUI.__NAVIGATION_BAR_OPTIONS: ComponentUI.print_frame_constructor_menu(option_tuple, ComponentUI.get_main_options()[2],\ "New airplane", user_input_list, True, 1000, [2,3], True) user_input = ComponentUI.get_user_input() if not user_input: continue user_input = ComponentUI.remove_brackets(user_input) if user_input in valid_user_inputs: index = int(user_input) - 1 if index == 0: ComponentUI.print_frame_constructor_menu(option_tuple, ComponentUI.get_main_options()[2],\ "New airplane", user_input_list, False, index) user_input = input(input_message_tuple[index]).strip() elif index == 1: #### PICK AIRPLANE TYPE BY TABLE LIST ### table_header_tuple = ("Type", "Manufacturer", "Seats") airplane_type_list = LogicAPI.get_all_airplane_types() airplanes_type_getfunctions_tuple = ([aircraft_type.get_plane_type() for aircraft_type in airplane_type_list],[aircraft_type.get_manufacturer() for aircraft_type in airplane_type_list],\ [aircraft_type.get_seat_count() for aircraft_type in airplane_type_list]) table_height = len(airplane_type_list) ComponentUI.print_frame_table_menu(table_header_tuple, airplanes_type_getfunctions_tuple, table_height,\ ComponentUI.get_main_options()[2], "New airplane") user_input = ComponentUI.get_user_input("Insert number of desired type: ") user_input = ComponentUI.remove_brackets(user_input) if not user_input.isdigit() or int(user_input) > table_height or not user_input: continue table_index = int(user_input) - 1 chosen_table_line = airplane_type_list[table_index] ### LINE PICKED ## user_input_list[1] = chosen_table_line.get_plane_type() user_input_list[2] = chosen_table_line.get_manufacturer() user_input_list[3] = chosen_table_line.get_seat_count() valid_for_submit_list[1] = True #Check if airplane name already exists if index == 0: user_input = user_input.capitalize() if not LogicAPI.is_airplane_name_available(user_input): user_input = user_input + " " + TextEditor.color_text_background("Airplane name already exists, another input is required", TextEditor.RED_BACKGROUND) valid_for_submit_list[0] = False else: valid_for_submit_list[0] = True if index == 0: user_input_list[index] = user_input user_input = "" elif user_input.startswith('s'): if all(valid_for_submit_list): new_airplane = Airplane( user_input_list[0], user_input_list[1], user_input_list[2], user_input_list[3], user_input_list[4] ) LogicAPI.save_new_airplane(new_airplane) user_input = "A new airplane has been registered" break return user_input
def __show_new_flight_route_constructor(): valid_user_inputs = ComponentUI.make_valid_menu_options_tuple( len(FlightRouteUI.FLIGHT_ROUTE_OPTION_TUBLE)) input_message_tuple = ("Insert Country: ", "Insert Destination: ", "Insert Airport id: ", "Insert Flight time(hh:mm): ",\ "Insert Distance from Iceland in km: ", "Insert Contact name: ", "Insert Emergency phonenumber: ") user_input_list = [""] * len(FlightRouteUI.FLIGHT_ROUTE_OPTION_TUBLE) valid_for_submit_list = [False] * len( FlightRouteUI.FLIGHT_ROUTE_OPTION_TUBLE ) #list that contains bools if all true then ok to submit user_input = "" #flight_route_info_already_exists = False while user_input not in FlightRouteUI.__NAVIGATION_BAR_OPTIONS: ComponentUI.print_frame_constructor_menu(FlightRouteUI.FLIGHT_ROUTE_OPTION_TUBLE, \ ComponentUI.get_main_options()[3], "New flight route", user_input_list, True) user_input = ComponentUI.get_user_input() if not user_input: continue user_input = ComponentUI.remove_brackets(user_input) if user_input in valid_user_inputs: index = int(user_input) - 1 ComponentUI.print_frame_constructor_menu(FlightRouteUI.FLIGHT_ROUTE_OPTION_TUBLE,\ ComponentUI.get_main_options()[3], "New flight route", user_input_list, False, index) user_input = input(input_message_tuple[index]).strip() if not user_input: continue #Capitalize the first letter of the Country and Destination if index == 0 or index == 1: user_input = user_input[0].upper() + user_input[1:] if user_input: valid_for_submit_list[index] = True #Check if the airport id already exists elif index == 2: if not LogicAPI.is_airport_id_available(user_input): user_input = user_input + " " + TextEditor.color_text_background( "Airport id already exists", TextEditor.RED_BACKGROUND) valid_for_submit_list[index] = False else: valid_for_submit_list[index] = True #Flight time test if format is right elif index == 3: test_list = user_input.split(':') error_msg_str = 'Time must be written in format of "hours:minutes"' if ':' in user_input and len(test_list) == 2: if all(test_list) and test_list[0].isdigit and len(test_list[0]) <= 2 and test_list[1].isdigit and len(test_list[1]) == 2\ and int(test_list[1])<60 and int(test_list[0])>=0 and int(test_list[1])>=0: if len(test_list[0]) == 1: user_input = "0" + user_input valid_for_submit_list[index] = True else: user_input = user_input + " " + TextEditor.color_text_background( error_msg_str, TextEditor.RED_BACKGROUND) valid_for_submit_list[index] = False else: user_input = user_input + " " + TextEditor.color_text_background( error_msg_str, TextEditor.RED_BACKGROUND) valid_for_submit_list[index] = False #Distance from Iceland can not contain letters excluding 'km' elif index == 4: if 'km' in user_input: user_input = user_input.replace('km', '') user_input = user_input.strip() if not user_input.isdigit(): user_input = user_input + " " + TextEditor.color_text_background( "Can not contain letters", TextEditor.RED_BACKGROUND) valid_for_submit_list[index] = False else: valid_for_submit_list[index] = True #Capitalize the first letters in the contacts name elif index == 5: contact_name_list = [] for name in user_input.split(): contact_name_list.append(name.capitalize()) user_input = " ".join(contact_name_list) valid_for_submit_list[index] = True #Remove any spaces or dashes from the phonenumber elif index == 6: if '-' in user_input: user_input = user_input.replace('-', '') if '' in user_input: user_input = user_input.replace(' ', '') #Put a message on the screen indicating the phonenumber is invalid if not user_input.isdigit(): user_input = user_input + " " + TextEditor.color_text_background( "Can not contain letters", TextEditor.RED_BACKGROUND) valid_for_submit_list[index] = False else: valid_for_submit_list[index] = True user_input_list[index] = user_input user_input = "" elif user_input.startswith('s'): if all(valid_for_submit_list): new_flight_route = FlightRoute( user_input_list[0], user_input_list[1], user_input_list[2], user_input_list[3], str(user_input_list[4]) + "km", user_input_list[5], user_input_list[6]) LogicAPI.save_new_flight_route(new_flight_route) user_input = "A new flight route has been registered" break return user_input
def __show_new_employee_constructor(): input_message_tuple = ("Insert job title(" + TextEditor.format_text('f', TextEditor.BOLD_TEXT) + " for flight attendant, "\ + TextEditor.format_text('p', TextEditor.BOLD_TEXT)+ " for pilot): ", "Insert Name: ", "Insert Social security number: ",\ "Insert Phone number: ", "Insert Home address: ", "Insert E-mail: ", "Insert License: ") user_input = "" option_tuple = ("Job title", "Name", "Social security number", "Phone number", "Home address", "E-mail", "License") user_input_list = [""] * len(option_tuple) valid_user_inputs = ComponentUI.make_valid_menu_options_tuple( len(option_tuple)) valid_user_inputs_bool_list = [True] * len(option_tuple) while user_input not in EmployeeUI.__NAVIGATION_BAR_OPTIONS: greyed_out_option_index_list = [ 6 ] if not user_input_list[0].lower().startswith('p') else [] ComponentUI.print_frame_constructor_menu(option_tuple, EmployeeUI.__FRAME_IN_USE_STR, "New employeee",\ user_input_list, True, greyed_out_option_index_list=greyed_out_option_index_list) user_input = ComponentUI.get_user_input() if not user_input: continue user_input = ComponentUI.remove_brackets(user_input) if user_input in valid_user_inputs: index = int(user_input) - 1 #Don't allow the user to enter a license if the employee ain't a pilot if index == 6: if not user_input_list[0].lower().startswith('p'): continue ComponentUI.print_frame_constructor_menu(option_tuple, EmployeeUI.__FRAME_IN_USE_STR, "New employeee",\ user_input_list, False, index) if index == 6: #display table of airplane types and return the type-name the of chosen one , head above the the table user_input = EmployeeUI.__airplane_type_picker( "New employeee") else: user_input = input(input_message_tuple[index]).strip() if not user_input: continue user_input = EmployeeUI.__constructor_error_check(user_input,\ valid_user_inputs_bool_list, index, user_input_list) elif user_input.startswith('s'): job_title_str = user_input_list[0].lower() if all(user_input_list) and job_title_str.startswith( 'p') and all(valid_user_inputs_bool_list): pilot = Pilot(user_input_list[1], user_input_list[2], user_input_list[3], user_input_list[4], user_input_list[5], State.get_employee_states()[0], user_input_list[6]) LogicAPI.save_new_pilot(pilot) user_input = "A new pilot has been registered" break elif all(user_input_list[:-1]) and job_title_str.startswith( 'f') and all(valid_user_inputs_bool_list[:-1]): flight_attendant = FlightAttendant( user_input_list[1], user_input_list[2], user_input_list[3], user_input_list[4], user_input_list[5], "Not scheduled for flight today") LogicAPI.save_new_flight_attendant(flight_attendant) user_input = "A new flight attendant has been registered" break return user_input