from Logic.FormationDB import FormationDB from Logic.PlayerDB import PlayerDB from Logic.TeamDB import TeamDB from Logic.HelperFunctions import delete_all_temp_images if __name__ == '__main__': multiprocessing.freeze_support() # Load defaults with open(config_filename, 'r') as f: configs = json.load(f) f.close() default_dbs = configs['default_databases'] # Set defaults player_db = PlayerDB() player_list = PlayerDB() formation_db = FormationDB() formation_list = FormationDB() team_list = TeamDB() player_db.load(default_dbs['player_db'], 'db') player_list.load(default_dbs['player_list'], 'list') formation_db.load(default_dbs['formation_db'], 'db') formation_list.load(default_dbs['formation_list'], 'list') team_list.load(default_dbs['team_list']) db_dict = { 'player_db': (default_dbs['player_db'], player_db), 'player_list': (default_dbs['player_list'], player_list), 'formation_db': (default_dbs['formation_db'], formation_db),
def enter_btn_func(): # Get file name and save if create_list_settings['process_step'] == 'file name': # Get file name and file prefix file_name = value_tf.value file_prefix = get_file_prefix('current_' + create_list_settings['list_type'] + '_list') if len(file_name) > 0: if not isfile('JSONs/' + file_prefix + file_name + '.json'): # Create list object, set message, and set process step if create_list_settings['list_type'] == 'player': new_list = PlayerDB() message.text = "Enter player rating/name or just name." create_list_settings['process_step'] = 'get player' elif create_list_settings['list_type'] == 'formation': new_list = FormationDB() message.text = "Enter part or full formation name, or nothing for full list." create_list_settings['process_step'] = 'get formation' elif create_list_settings['list_type'] == 'team': new_list = TeamDB() message.text = "Blank team list created. Add teams from Search menu." create_list_settings['process_step'] = 'get team' back_btn.title = "Done" enter_btn.enabled = 0 else: new_list = PlayerDB() print "Invalid list type." # Assign file name and file object create_list_settings['list'] = new_list create_list_settings['file_name'] = file_name # Clear box content value_tf.value = '' else: message.text = "A file with that name already exists." else: message.text = "File name must be at least 1 character." # Get player to add to list elif create_list_settings['process_step'] == 'get player': # Get input player_input = value_tf.value # Remove result messages off page for result_message in create_list_settings['results']: view.remove(result_message) if len(player_input) > 0: search_dict = {} # Check for rating if player_input.split(' ')[0].isdigit(): # Check if there is a name and rating if len(player_input.split(' ')) > 1: search_dict['rating'] = (int(player_input.split(' ')[0]), 'exact') # Get name search_dict['name_custom'] = (player_input.split(' ', 1)[1], 'exact') else: message.text = "Invalid. Ex: '99 Superman' or 'Superman'." # No rating, just name (or invalid) else: search_dict['name_custom'] = (player_input, 'exact') # Valid input if len(search_dict) > 0: # Search for players results = PlayerDB(db_dict['player_db'][1].search(search_dict)) results.sort(['rating']) # No matching players found if len(results.db) == 0: message.text = "Unable to find player. Try again." # If only one player in results, add player. elif len(results.db) == 1: add_player_btn_func(results.db[0]) else: message.text = "Multiple players found. Pick correct one." display_players(results, [], (0, num_results)) else: message.text = "Invalid. Ex: '99 Superman' or 'Superman'." # Get formation to add to list elif create_list_settings['process_step'] == 'get formation': # Get input formation_input = value_tf.value # Remove result messages off page for result_message in create_list_settings['results']: view.remove(result_message) search_dict = {'name': (formation_input, 'exact')} # Search for formations results = FormationDB(db_dict['formation_db'][1].search(search_dict)) # Remove formations already on list for formation in create_list_settings['list'].db: if formation in results.db: results.db.remove(formation) results.sort(['name']) # No matching formations found if len(results.db) == 0: message.text = "Unable to find formation. Try again." # If only one formation in results, add formation. elif len(results.db) == 1: add_formation_btn_func(results.db[0]) else: message.text = "Multiple formations found. Pick correct one." display_formations(results, [], (0, num_results)) # Get team to add to list elif create_list_settings['process_step'] == 'get team': stuff = 0 # Invalid process step else: print "Create file process step is invalid." value_tf.become_target()
def select_file_func(file_name): # Save new default to config file if file_type[:7] == 'default': # Load configs from Window.AppConfig import config_filename configs = {} with open(config_filename, 'r') as config_file: configs = json.load(config_file) config_file.close() # Assign new file name to config configs['default_databases'][file_type[8:]] = file_name # Save configs with open(config_file, 'w') as config_file: json.dump(configs, config_file) config_file.close() # Load db to db_dict elif file_type[:7] == 'current': if file_type[8:12] == 'play': load_db = PlayerDB() elif file_type[8:12] == 'form': load_db = FormationDB() elif file_type[8:12] == 'team': load_db = TeamDB() else: load_db = PlayerDB() print "File type is invalid." if file_type[-2:] == 'db': load_file_type = 'db' elif file_type[-4:] == 'list': load_file_type = 'list' else: load_file_type = 'Invalid' # Load db load_db.load(file_name, load_file_type) # Assign db to db_dict db_dict[file_type[8:]] = (file_name, load_db) else: print "File type is invalid." # Enable back button settings['file_changes'] = False settings['file_index'] = 0 if settings['prev_window'] == 'team_creation': CreateUltimateTeams.open_create_ultimate_teams_window( win_pick_file.x, win_pick_file.y, db_dict, settings['prev_window_value'], file_name=settings['create_team_name'], roster=settings['roster'], input_formation=settings['input_formation']) elif settings['prev_window'] == 'search': SearchMenu.open_search_menu(win_pick_file.x, win_pick_file.y, db_dict, settings['attr_dict'], settings['attr_list'], settings) elif settings['prev_window'] == 'pick_player': PickPlayer.open_pick_player_window(win_pick_file.x, win_pick_file.y, db_dict, settings['input_formation'], settings['win_previous'], settings['roster'], settings['pos_symbol'], settings['pick_formations_page'], settings['attr_dict'], settings['attr_list'], settings) else: FilesMenu.open_files_menu(win_pick_file.x, win_pick_file.y, db_dict, settings) win_pick_file.hide()