def open_pick_player_window(window_x, window_y, db_dict, input_formation, win_previous, roster, pos_symbol, pick_formations_page, attr_dict=None, attr_list=None, settings=None): num_results = 20 general_display = [] if attr_dict is None: attr_dict = {} if attr_list is None: attr_list = [] if settings is None: settings = { 'window': 'pick_player', 'p_db_rg': 'player_list', 'pos_search_rg': 'green', 'order_rg': True, 'messages': { 'search': [], 'sort': [], 'results': [] }, 'input_formation': input_formation, 'roster': roster, 'pos_symbol': pos_symbol, 'win_previous': win_previous, 'pick_formations_page': pick_formations_page} # Assign exact position as default position to search for. attr_dict['position'] = (input_formation['positions'][pos_symbol]['symbol'], 'exact') # Not position dependent - search all. if input_formation['name'] == 'Generic': settings['pos_search_rg'] = 'red' attr_dict.pop('position', None) # ========== Window ========== win_pick_player = Window() win_pick_player.title = pick_player_win_title + ' - ' + pos_symbol win_pick_player.auto_position = False win_pick_player.position = (window_x, window_y) win_pick_player.size = (win_width, win_height) win_pick_player.resizable = 0 win_pick_player.name = pick_player_title + " Window" # ========== Window Image View ========== class PickPlayerWindowImageView(View): def draw(self, c, r): c.backcolor = view_backcolor c.erase_rect(r) view = PickPlayerWindowImageView(size=win_pick_player.size) # ========== Title ========== title = Label(text=pick_player_title + ' - ' + pos_symbol) title.font = title_font title.width = title_width title.height = title_height title.x = (win_width - title_width) / 2 title.y = top_border title.color = title_color title.just = 'center' general_display.append(title) # ========== Action Button Declarations ========== start_btn = Button("Start") back_btn = Button("Back") # ========== Tool Button Declarations ========== attribute_btn = Button("Add Search Attribute") sort_btn = Button("Add Sort Attribute") reset_btn = Button("Reset Results") # ========== Action Button Functions ========== def start_btn_func(): # Search - if no attribute selected, return all if len(attr_dict) == 0: search_results = db_dict[p_db_radio_group.value][1] else: search_results = db_dict[p_db_radio_group.value][1].search(attr_dict) search_results = PlayerDB.PlayerDB(search_results) # Sort - if no attribute selected, use rating if len(attr_list) == 0: search_results.sort(['rating'], sort_order_radio_group.value) else: search_results.sort(attr_list, sort_order_radio_group.value) # Get attributes list and avoid duplicates attributes_list = [] for attr in attr_list: if attributes_list.count(attr) == 0: attributes_list.append(attr) for attr_key in attr_dict.iterkeys(): if attributes_list.count(attr_key) == 0: attributes_list.append(attr_key) display_players(search_results, attributes_list, (0, num_results)) win_pick_player.become_target() def back_btn_func(): win_pick_player.hide() win_previous.show() # ========== Tool Button Functions ========== def attribute_btn_func(): # Delete results del settings['messages']['results'][:] # Set type argument attr_type = 'player_search' # Open new window and close current window win_pick_player.hide() AddAttribute.open_attribute_window(win_pick_player.x, win_pick_player.y, db_dict, attr_dict, attr_list, attr_type, settings) def sort_btn_func(): # Delete results del settings['messages']['results'][:] # Set type argument attr_type = 'player_sort' # Open new window and close current window win_pick_player.hide() AddAttribute.open_attribute_window(win_pick_player.x, win_pick_player.y, db_dict, attr_dict, attr_list, attr_type, settings) def reset_btn_func(): # Remove messages off page for message in settings['messages']['search']: view.remove(message) for message in settings['messages']['sort']: view.remove(message) for message in settings['messages']['results']: view.remove(message) # Delete the attribute parameters for search and sort attr_dict.clear() del attr_list[:] del settings['messages']['results'][:] win_pick_player.become_target() def create_attribute_messages(): # ========== Messages ========== lowest_msg_l = start_btn.top lowest_msg_r = start_btn.top attr_msg_offset = 25 # Attribute Messages del settings['messages']['search'][:] del settings['messages']['sort'][:] if len(attr_dict) > 0: settings['messages']['search'].append( Label(text="Search Attributes:", font=title_tf_font, width=std_tf_width, height=std_tf_height, x=attr_msg_offset, y=lowest_msg_l, color=title_color)) lowest_msg_l += std_tf_height for key, value in attr_dict.iteritems(): msg_text = format_attr_name(key) + ": " if key in ['id', 'baseId', 'nationId', 'leagueId', 'clubId']: msg_text += str(value[0]) elif type(value[0]) is int: msg_text += value[1].capitalize() + ' ' + str(value[0]) elif value[1] == 'not': msg_text += value[1].capitalize() + ' "' + str(value[0]) + '"' else: msg_text += '"' + str(value[0]) + '"' attr_label = Label(text=msg_text, font=std_tf_font, width=std_tf_width, height=std_tf_height, x=attr_msg_offset, y=lowest_msg_l, color=title_color) lowest_msg_l += std_tf_height settings['messages']['search'].append(attr_label) if len(attr_list) > 0: settings['messages']['sort'].append(Label(text="Sort Attributes:", font=title_tf_font, width=std_tf_width, height=std_tf_height, x=reset_btn.right + 3 * attr_msg_offset, y=lowest_msg_r, color=title_color)) lowest_msg_r += std_tf_height for value in attr_list: attr_label = Label(text=(format_attr_name(value)), font=std_tf_font, width=std_tf_width, height=std_tf_height, x=reset_btn.right + 3 * attr_msg_offset, y=lowest_msg_r, color=title_color) lowest_msg_r += std_tf_height settings['messages']['sort'].append(attr_label) create_attribute_messages() def player_bio_btn_func(player): win_pick_player.hide() PlayerBio.open_player_bio_window(win_pick_player.x, win_pick_player.y, player, win_pick_player, db_dict, db_dict['player_list'][0], db_dict['player_list'][1], roster, pos_symbol, input_formation, pick_formations_page) win_pick_player.become_target() # ========== Action Buttons ========== start_btn.x = (win_width - 2*small_button_width - small_button_spacing) / 2 start_btn.y = title.bottom + small_button_top_spacing start_btn.height = small_button_height start_btn.width = small_button_width start_btn.font = small_button_font start_btn.action = start_btn_func start_btn.style = 'default' start_btn.color = small_button_color start_btn.just = 'right' general_display.append(start_btn) back_btn.x = start_btn.right + small_button_spacing back_btn.y = start_btn.top back_btn.height = small_button_height back_btn.width = small_button_width back_btn.font = small_button_font back_btn.action = back_btn_func back_btn.style = 'default' back_btn.color = small_button_color back_btn.just = 'right' general_display.append(back_btn) # ========== Tool Buttons ========== attribute_btn.x = (win_width - 3*small_button_width - 2*small_button_spacing) / 2 attribute_btn.y = start_btn.bottom + 10 attribute_btn.height = small_button_height attribute_btn.width = small_button_width attribute_btn.font = small_button_font attribute_btn.action = attribute_btn_func attribute_btn.style = 'default' attribute_btn.color = small_button_color attribute_btn.just = 'right' general_display.append(attribute_btn) sort_btn.x = attribute_btn.right + small_button_spacing sort_btn.y = attribute_btn.top sort_btn.height = small_button_height sort_btn.width = small_button_width sort_btn.font = small_button_font sort_btn.action = sort_btn_func sort_btn.style = 'default' sort_btn.color = small_button_color sort_btn.just = 'right' general_display.append(sort_btn) reset_btn.x = sort_btn.right + small_button_spacing reset_btn.y = attribute_btn.top reset_btn.height = small_button_height reset_btn.width = small_button_width reset_btn.font = small_button_font reset_btn.action = reset_btn_func reset_btn.style = 'default' reset_btn.color = small_button_color reset_btn.just = 'right' general_display.append(reset_btn) # ========== Pick DB/List Button Functions ========== def pick_file(): # Remove old messages off page for message in settings['messages']['results']: view.remove(message) del settings['messages']['results'][:] settings['file_changes'] = False settings['prev_window'] = 'pick_player' settings['input_formation'] = input_formation settings['win_previous'] = win_previous settings['roster'] = roster settings['pos_symbol'] = pos_symbol settings['pick_formations_page'] = pick_formations_page settings['attr_dict'] = attr_dict settings['attr_list'] = attr_list PickFile.open_pick_file_window(win_pick_player.x, win_pick_player.y, db_dict, settings) win_pick_player.hide() def pick_p_db_func(): settings['file_type'] = 'current_player_db' pick_file() def pick_p_list_func(): settings['file_type'] = 'current_player_list' pick_file() # ========== DB Radio Buttons ========== def get_attribute_p_db_rg(): settings['p_db_rg'] = p_db_radio_group.value win_pick_player.become_target() def get_attribute_pos_search_rg(): if settings['pos_search_rg'] != pos_search_radio_group.value: button_click = True else: button_click = False settings['pos_search_rg'] = pos_search_radio_group.value # If new radio button was clicked, clear position in attribute dictionary. if button_click: attr_dict.pop('position', None) # Add position search terms if position and positionFull and not specified and not searching all players. if pos_search_radio_group.value != 'red' and button_click: temp_team = Team.Team() # Get positions of corresponding relevance search_positions_list = temp_team.related_positions( input_formation['positions'][pos_symbol]['symbol'], pos_search_radio_group.value) # Concatenate strings search_positions = "" for position in search_positions_list: search_positions += position + ', ' search_positions = search_positions[:-2] if len(search_positions) < 1: search_positions = 'none' attr_dict['position'] = (search_positions, 'exact') # Erase current search attributes for message in settings['messages']['search']: view.remove(message) # Create new search attributes create_attribute_messages() # Display search attributes for message in settings['messages']['search']: view.add(message) win_pick_player.become_target() p_db_radio_group = RadioGroup(action=get_attribute_p_db_rg) pos_search_radio_group = RadioGroup(action=get_attribute_pos_search_rg) # File Label db_msg_width = 35 db_radio_btn_width = 150 db_file_btn_width = 40 db_radio_btn_space = 5 db_file_btn_space = 2 file_label = Label(text="File", font=std_tf_font, width=db_msg_width, height=std_tf_height, color=title_color) file_label.x = (win_pick_player.width - 2*db_radio_btn_width - 2*db_file_btn_width - db_radio_btn_space - 2*db_file_btn_space - db_msg_width) / 2 file_label.y = reset_btn.bottom + db_radio_btn_space # Players DB RG player_db_radio_btn = RadioButton(db_dict['player_db'][0]) player_db_radio_btn.width = db_radio_btn_width player_db_radio_btn.x = file_label.right player_db_radio_btn.y = file_label.top player_db_radio_btn.group = p_db_radio_group player_db_radio_btn.value = 'player_db' player_db_file_btn = Button("Pick") player_db_file_btn.x = player_db_radio_btn.right + db_file_btn_space player_db_file_btn.y = file_label.top player_db_file_btn.height = std_tf_height player_db_file_btn.width = db_file_btn_width player_db_file_btn.font = small_button_font player_db_file_btn.action = pick_p_db_func player_db_file_btn.style = 'default' player_db_file_btn.color = small_button_color player_db_file_btn.just = 'right' player_list_radio_btn = RadioButton(db_dict['player_list'][0]) player_list_radio_btn.width = db_radio_btn_width player_list_radio_btn.x = player_db_file_btn.right + db_radio_btn_space player_list_radio_btn.y = file_label.top player_list_radio_btn.group = p_db_radio_group player_list_radio_btn.value = 'player_list' player_list_file_btn = Button("Pick") player_list_file_btn.x = player_list_radio_btn.right + db_file_btn_space player_list_file_btn.y = file_label.top player_list_file_btn.height = std_tf_height player_list_file_btn.width = db_file_btn_width player_list_file_btn.font = small_button_font player_list_file_btn.action = pick_p_list_func player_list_file_btn.style = 'default' player_list_file_btn.color = small_button_color player_list_file_btn.just = 'right' p_db_radio_group.value = settings['p_db_rg'] view.add(file_label) view.add(player_db_radio_btn) view.add(player_db_file_btn) view.add(player_list_radio_btn) view.add(player_list_file_btn) # Position Search RG pos_search_radio_btn_width = 60 pos_search_msg_width = 140 pos_search_rg_msg = Label(text="Positions to Search:", font=std_tf_font, width=pos_search_msg_width, height=std_tf_height, color=title_color) pos_search_rg_msg.x = (win_pick_player.width-4*pos_search_radio_btn_width-db_radio_btn_space-pos_search_msg_width)/2 pos_search_rg_msg.y = file_label.bottom + db_radio_btn_space pos_search_green_radio_btn = RadioButton("Exact") pos_search_green_radio_btn.width = pos_search_radio_btn_width pos_search_green_radio_btn.x = pos_search_rg_msg.right pos_search_green_radio_btn.y = pos_search_rg_msg.top pos_search_green_radio_btn.group = pos_search_radio_group pos_search_green_radio_btn.value = 'green' pos_search_yellow_radio_btn = RadioButton("Similar") pos_search_yellow_radio_btn.width = pos_search_radio_btn_width pos_search_yellow_radio_btn.x = pos_search_green_radio_btn.right + db_radio_btn_space pos_search_yellow_radio_btn.y = pos_search_green_radio_btn.top pos_search_yellow_radio_btn.group = pos_search_radio_group pos_search_yellow_radio_btn.value = 'yellow' pos_search_orange_radio_btn = RadioButton("Related") pos_search_orange_radio_btn.width = pos_search_radio_btn_width pos_search_orange_radio_btn.x = pos_search_yellow_radio_btn.right + db_radio_btn_space pos_search_orange_radio_btn.y = pos_search_yellow_radio_btn.top pos_search_orange_radio_btn.group = pos_search_radio_group pos_search_orange_radio_btn.value = 'orange' pos_search_red_radio_btn = RadioButton("All") pos_search_red_radio_btn.width = pos_search_radio_btn_width pos_search_red_radio_btn.x = pos_search_orange_radio_btn.right + db_radio_btn_space pos_search_red_radio_btn.y = pos_search_orange_radio_btn.top pos_search_red_radio_btn.group = pos_search_radio_group pos_search_red_radio_btn.value = 'red' pos_search_radio_group.value = settings['pos_search_rg'] view.add(pos_search_rg_msg) view.add(pos_search_green_radio_btn) view.add(pos_search_yellow_radio_btn) view.add(pos_search_orange_radio_btn) view.add(pos_search_red_radio_btn) if input_formation['name'] == 'Generic': pos_search_green_radio_btn.enabled = 0 pos_search_yellow_radio_btn.enabled = 0 pos_search_orange_radio_btn.enabled = 0 # ========== Sort Order Radio Buttons ========== def get_attribute_sort_order_rg(): settings['order_rg'] = sort_order_radio_group.value win_pick_player.become_target() sort_order_radio_group = RadioGroup(action=get_attribute_sort_order_rg) asc_desc_radio_btn_width = 75 asc_msg_width = 80 radio_btn_space = 5 asc_desc_rg_msg = Label(text="Sort Order:", font=std_tf_font, width=asc_msg_width, height=std_tf_height, color=title_color) asc_desc_rg_msg.x = (win_pick_player.width - 2*asc_desc_radio_btn_width - radio_btn_space - asc_msg_width) / 2 asc_desc_rg_msg.y = pos_search_green_radio_btn.bottom + radio_btn_space general_display.append(asc_desc_rg_msg) descend_radio_btn = RadioButton("Descending") descend_radio_btn.width = asc_desc_radio_btn_width descend_radio_btn.x = asc_desc_rg_msg.right descend_radio_btn.y = asc_desc_rg_msg.top descend_radio_btn.group = sort_order_radio_group descend_radio_btn.value = True general_display.append(descend_radio_btn) ascend_radio_btn = RadioButton("Ascending") ascend_radio_btn.width = asc_desc_radio_btn_width ascend_radio_btn.x = descend_radio_btn.right + radio_btn_space ascend_radio_btn.y = descend_radio_btn.top ascend_radio_btn.group = sort_order_radio_group ascend_radio_btn.value = False general_display.append(ascend_radio_btn) sort_order_radio_group.value = settings['order_rg'] # ========== Previous, Add to List, Next Buttons ========== previous_btn = Button("<<< Previous %d" % num_results) add_to_list_btn = Button("") next_btn = Button("Next %d >>>" % num_results) total_num_results_label = Label() pages_label = Label() def previous_btn_func(results_list, attributes, index_range): # display previous results display_players(results_list, attributes, index_range) win_pick_player.become_target() def next_btn_func(results_list, attributes, index_range): # display next results display_players(results_list, attributes, index_range) win_pick_player.become_target() add_to_list_btn.x = attribute_btn.right + small_button_spacing add_to_list_btn.y = descend_radio_btn.bottom + 5 add_to_list_btn.height = tiny_button_height add_to_list_btn.width = small_button_width add_to_list_btn.font = small_button_font add_to_list_btn.style = 'default' add_to_list_btn.color = small_button_color add_to_list_btn.just = 'right' add_to_list_btn.action = win_pick_player.become_target() previous_btn.height = tiny_button_height previous_btn.width = small_button_width previous_btn.x = add_to_list_btn.left - previous_btn.width - small_button_spacing previous_btn.y = add_to_list_btn.top previous_btn.font = small_button_font previous_btn.style = 'default' previous_btn.color = small_button_color previous_btn.just = 'right' next_btn.height = tiny_button_height next_btn.width = small_button_width next_btn.x = add_to_list_btn.right + small_button_spacing next_btn.y = add_to_list_btn.top next_btn.font = small_button_font next_btn.style = 'default' next_btn.color = small_button_color next_btn.just = 'right' total_num_results_label.font = std_tf_font total_num_results_label.width = 100 total_num_results_label.height = std_tf_height total_num_results_label.x = previous_btn.left + - 100 - 10 total_num_results_label.y = add_to_list_btn.top total_num_results_label.color = title_color total_num_results_label.just = 'right' pages_label.font = std_tf_font pages_label.width = 125 pages_label.height = std_tf_height pages_label.x = next_btn.right + 10 pages_label.y = add_to_list_btn.top pages_label.color = title_color pages_label.just = 'left' # ========== Display players from search ========== def display_players(results_list, attributes, index_range): # Remove old messages off page for message in settings['messages']['results']: view.remove(message) del settings['messages']['results'][:] previous_range = (index_range[0]-num_results, index_range[0]) previous_btn.action = (previous_btn_func, results_list, attributes, previous_range) next_range = (index_range[1], index_range[1]+num_results) next_btn.action = (next_btn_func, results_list, attributes, next_range) total_num_results_label.text = str(len(results_list.db)) + " Players" pages_label.text = "Page %d of %d" % (int(index_range[1]/num_results), math.ceil(len(results_list.db)/float(num_results))) if index_range[0] > 0: previous_btn.enabled = 1 else: previous_btn.enabled = 0 if index_range[1] <= len(results_list.db) - 1: next_btn.enabled = 1 else: next_btn.enabled = 0 settings['messages']['results'].append(add_to_list_btn) settings['messages']['results'].append(previous_btn) settings['messages']['results'].append(next_btn) settings['messages']['results'].append(total_num_results_label) settings['messages']['results'].append(pages_label) # Print out labels labels = player_info_labels(attributes) stat_index = 0 # Spacing values for each of the stats spacing_list = [125, 40, 40, 65, 115, 115, 115, 40] # Calculate the maximum number of stat fields that will fit on screen max_player_fields = len(spacing_list[:-1]) + (win_pick_player.width - sum(spacing_list[:-1]))/spacing_list[-1] # Calculate the left border of the stats based on the number and width of the stats left_border = (win_width - sum(spacing_list[:-1]) - (len(labels[:max_player_fields]) - len(spacing_list) + 1) * spacing_list[-1])/2 msg_x = left_border msg_y = add_to_list_btn.bottom + 5 for info_label in labels[:max_player_fields]: player_label = Label(text=info_label, font=std_tf_font_bold, width=spacing_list[stat_index]-5, height=std_tf_height, x=msg_x, y=msg_y, color=title_color) settings['messages']['results'].append(player_label) msg_x += spacing_list[stat_index] if stat_index < len(spacing_list)-1: stat_index += 1 msg_y += std_tf_height + 5 # Print out players for idx, player in enumerate(results_list.db[index_range[0]:index_range[1]]): msg_x = left_border player_stats = player_info(player, attributes) stat_index = 0 # Check for names that are too long name = player_stats[0] if len(name) > 20: name = player['lastName'] bio_btn = Button(title=name, width=spacing_list[stat_index]-5, height=15, x=msg_x, y=msg_y, action=(player_bio_btn_func, player)) settings['messages']['results'].append(bio_btn) msg_x += spacing_list[stat_index] stat_index += 1 for player_stat in player_stats[1:max_player_fields]: player_label = Label(text=player_stat, font=small_button_font, width=spacing_list[stat_index]-5, height=std_tf_height, x=msg_x, y=msg_y, color=title_color) settings['messages']['results'].append(player_label) msg_x += spacing_list[stat_index] if stat_index < len(spacing_list) - 1: stat_index += 1 msg_y += std_tf_height for results_msg in settings['messages']['results']: view.add(results_msg) # ========== Add components to view and add view to window ========== for msg in general_display: view.add(msg) for msg in settings['messages']['search']: view.add(msg) for msg in settings['messages']['sort']: view.add(msg) for msg in settings['messages']['results']: view.add(msg) win_pick_player.add(view) view.become_target() win_pick_player.show()
def open_create_ultimate_teams_window(window_x, window_y, db_dict, win_previous, player_judge_list=None, team_judge_list=None, file_name=None, roster=None, input_formation=None): display_items = [] # Get create ultimate team configuration values with open(config_filename, 'r') as f: settings = json.load(f)['ultimate_team_configs'] f.close() # Set the attributes lists if player_judge_list is not None: settings['player_sort_attributes'] = player_judge_list if team_judge_list is not None: settings['team_sort_attributes'] = team_judge_list if roster is None: roster = {} settings['roster'] = roster # Assign input formation, or lack thereof, to settings settings['input_formation'] = input_formation # ========== Window ========== win_ultimate_teams = Window() win_ultimate_teams.title = create_ultimate_teams_win_title win_ultimate_teams.auto_position = False win_ultimate_teams.position = (window_x, window_y) win_ultimate_teams.size = (win_width, win_height) win_ultimate_teams.resizable = 0 win_ultimate_teams.name = create_ultimate_teams_title + " Window" # ========== Window Image View ========== class CreateUltimateTeamsWindowImageView(View): def draw(self, c, r): c.backcolor = view_backcolor c.erase_rect(r) view = CreateUltimateTeamsWindowImageView(size=win_ultimate_teams.size) # ========== Title ========== title = Label(text=create_ultimate_teams_title) title.font = title_font title.width = title_width title.height = title_height title.x = (win_width - title_width) / 2 title.y = top_border title.color = title_color title.just = 'center' display_items.append(title) # ========== Settings ========== # ========== Current player list and formation list ========== file_name_width = 125 file_button_width = 200 # Functions for picking files def player_list_current_btn_func(): save_settings() settings['file_type'] = 'current_player_list' settings['file_changes'] = False settings['prev_window'] = 'team_creation' settings['prev_window_value'] = win_previous settings['create_team_name'] = team_list_name_tf.value PickFile.open_pick_file_window(win_ultimate_teams.x, win_ultimate_teams.y, db_dict, settings) win_ultimate_teams.hide() def player_db_current_btn_func(): save_settings() settings['file_type'] = 'current_player_db' settings['file_changes'] = False settings['prev_window'] = 'team_creation' settings['prev_window_value'] = win_previous settings['create_team_name'] = team_list_name_tf.value PickFile.open_pick_file_window(win_ultimate_teams.x, win_ultimate_teams.y, db_dict, settings) win_ultimate_teams.hide() def formation_list_current_btn_func(): save_settings() settings['file_type'] = 'current_formation_list' settings['file_changes'] = False settings['prev_window'] = 'team_creation' settings['prev_window_value'] = win_previous settings['create_team_name'] = team_list_name_tf.value PickFile.open_pick_file_window(win_ultimate_teams.x, win_ultimate_teams.y, db_dict, settings) win_ultimate_teams.hide() player_list_label = Label(text="Player List:", font=std_tf_font_bold, width=file_name_width, height=std_tf_height, x=(win_width-file_name_width-file_button_width-5)/2, y=title.bottom + title_border*3, color=title_color, just='right') display_items.append(player_list_label) player_list_button = Button(title=db_dict['player_list'][0], font=small_tf_font, width=file_button_width, height=std_tf_height, x=player_list_label.right + 5, y=player_list_label.top, color=title_color, just='center', action=player_list_current_btn_func) display_items.append(player_list_button) player_db_label = Label(text="Player DB:", font=std_tf_font_bold, width=file_name_width, height=std_tf_height, x=player_list_label.left, y=player_list_label.bottom + title_border, color=title_color, just='right') display_items.append(player_db_label) player_db_button = Button(title=db_dict['player_db'][0], font=small_tf_font, width=file_button_width, height=std_tf_height, x=player_list_label.right + 5, y=player_db_label.top, color=title_color, just='center', action=player_db_current_btn_func) display_items.append(player_db_button) formation_list_label = Label(text="Formation List:", font=std_tf_font_bold, width=file_name_width, height=std_tf_height, x=player_list_label.left, y=player_db_label.bottom + title_border, color=title_color, just='right') display_items.append(formation_list_label) formation_list_button = Button(title=db_dict['formation_list'][0], font=small_tf_font, width=file_button_width, height=std_tf_height, x=formation_list_label.right + 5, y=formation_list_label.top, color=title_color, just='center', action=formation_list_current_btn_func) display_items.append(formation_list_button) if input_formation is not None and input_formation['name'] != 'Generic': formation_list_button.enabled = 0 formation_list_button.title = input_formation['name'] settings_indent = 3*win_width/7 # ========== Team Name ========== tf_width = 235 team_name_label_width = 130 disabled_msg = "Disabled" team_list_name_label = Label(text="Team List Name: ", font=std_tf_font_bold, width=team_name_label_width, height=std_tf_height, x=settings_indent - team_name_label_width, y=formation_list_label.bottom + title_border*2, color=title_color, just='right') display_items.append(team_list_name_label) team_list_name_tf = TextField(font=std_tf_font, width=tf_width, height=std_tf_height + 5, x=team_list_name_label.right + small_button_spacing, y=team_list_name_label.top) display_items.append(team_list_name_tf) if file_name is not None: team_list_name_tf.value = file_name radio_btn_width = 75 radio_btn_space = 5 # ========== Process Type Label ========== process_type_label = Label(text="Processing Type: ", font=std_tf_font_bold, width=std_tf_width, height=std_tf_height, x=settings_indent - std_tf_width, y=team_list_name_label.bottom + title_border, color=title_color, just='right') display_items.append(process_type_label) def get_process_type_rg(): settings['process_type'] = process_type_radio_group.value win_ultimate_teams.become_target() process_type_radio_group = RadioGroup(action=get_process_type_rg) # Process Type Radio Buttons multi_process_radio_btn = RadioButton('Multi', width=radio_btn_width, x=process_type_label.right + radio_btn_space, y=process_type_label.top, group=process_type_radio_group, value='multi') display_items.append(multi_process_radio_btn) single_process_radio_btn = RadioButton('Single', width=radio_btn_width, x=multi_process_radio_btn.right + radio_btn_space, y=process_type_label.top, group=process_type_radio_group, value='single') display_items.append(single_process_radio_btn) process_type_radio_group.value = settings['process_type'] # If building a team based on one formation, there is no benefit to using multiple processes. if input_formation is not None: if input_formation['name'] != 'Generic': process_type_radio_group.value = 'single' settings['process_type'] = 'single' multi_process_radio_btn.enabled = 0 single_process_radio_btn.enabled = 0 # ========== Chemistry Matters Label ========== chemistry_matters_label = Label(text="Chemistry Matters: ", font=std_tf_font_bold, width=std_tf_width, height=std_tf_height, x=settings_indent - std_tf_width, y=process_type_label.bottom + title_border, color=title_color, just='right') display_items.append(chemistry_matters_label) def get_chemistry_matters_rg(): settings['chemistry_matters'] = chemistry_matters_radio_group.value win_ultimate_teams.become_target() chemistry_matters_radio_group = RadioGroup(action=get_chemistry_matters_rg) # Process Type Radio Buttons multi_process_radio_btn = RadioButton('Yes', width=radio_btn_width, x=chemistry_matters_label.right + radio_btn_space, y=chemistry_matters_label.top, group=chemistry_matters_radio_group, value=True) display_items.append(multi_process_radio_btn) single_process_radio_btn = RadioButton('No', width=radio_btn_width, x=multi_process_radio_btn.right + radio_btn_space, y=chemistry_matters_label.top, group=chemistry_matters_radio_group, value=False) display_items.append(single_process_radio_btn) chemistry_matters_radio_group.value = settings['chemistry_matters'] # ========== Judging Teams Label ========== judging_teams_label = Label(text="How to Judge Teams: ", font=std_tf_font_bold, width=std_tf_width, height=std_tf_height, x=settings_indent - std_tf_width, y=chemistry_matters_label.bottom + title_border, color=title_color, just='right') display_items.append(judging_teams_label) judging_teams_attributes = Label(font=std_tf_font, width=std_tf_width, height=std_tf_height, x=judging_teams_label.right + radio_btn_space, y=judging_teams_label.top, color=title_color, just='left') judging_teams_attributes_text = '' for attr in settings['team_sort_attributes']: judging_teams_attributes_text += format_attr_name(attr) + ', ' # Remove extra comma and space judging_teams_attributes_text = judging_teams_attributes_text[:-2] # Truncate if too long if len(judging_teams_attributes_text) > 26: judging_teams_attributes_text = judging_teams_attributes_text[:26] + '...' judging_teams_attributes.text = judging_teams_attributes_text display_items.append(judging_teams_attributes) # Judging Teams Edit Button def judging_teams_edit_btn_func(): save_settings() attr_dict = {} attr_list = settings['team_sort_attributes'] attr_type = 'team_sort' attribute_settings = {'window': 'ultimate_team_judging', 'file_name': team_list_name_tf.value, 'roster': roster, 'input_formation': input_formation, 'prev_window_value': win_previous} AddAttribute.open_attribute_window( win_ultimate_teams.x, win_ultimate_teams.y, db_dict, attr_dict, attr_list, attr_type, attribute_settings) win_ultimate_teams.hide() judging_edit_btn_width = 40 judging_teams_edit_btn = Button("Edit", #x=teams_to_return_tf.right - judging_edit_btn_width, x=judging_teams_attributes.right, y=judging_teams_label.top, height=small_button_height-7, width=judging_edit_btn_width, font=small_button_font, action=judging_teams_edit_btn_func, style = 'default', color=button_color, just='right') display_items.append(judging_teams_edit_btn) # ========== Judging Players Label ========== judging_players_label = Label(text="How to Judge Players: ", font=std_tf_font_bold, width=std_tf_width, height=std_tf_height, x=settings_indent - std_tf_width, y=judging_teams_label.bottom + title_border, color=title_color, just='right') display_items.append(judging_players_label) judging_players_attributes = Label(font=std_tf_font, width=std_tf_width, height=std_tf_height, x=judging_players_label.right + radio_btn_space, y=judging_players_label.top, color=title_color, just='left') judging_players_attributes_text = '' for attr in settings['player_sort_attributes']: judging_players_attributes_text += format_attr_name(attr) + ', ' # Remove extra comma and space judging_players_attributes_text = judging_players_attributes_text[:-2] # Truncate if too long if len(judging_players_attributes_text) > 26: judging_players_attributes_text = judging_players_attributes_text[:26] + '...' judging_players_attributes.text = judging_players_attributes_text display_items.append(judging_players_attributes) # Judging Teams Edit Button def judging_players_edit_btn_func(): save_settings() attr_dict = {} attr_list = settings['player_sort_attributes'] attr_type = 'player_sort' attribute_settings = {'window': 'ultimate_player_judging', 'file_name': team_list_name_tf.value, 'roster': roster, 'input_formation': input_formation, 'prev_window_value': win_previous} AddAttribute.open_attribute_window(win_ultimate_teams.x, win_ultimate_teams.y, db_dict, attr_dict, attr_list, attr_type, attribute_settings) win_ultimate_teams.hide() judging_edit_btn_width = 40 judging_players_edit_btn = Button("Edit", #x=teams_to_return_tf.right - judging_edit_btn_width, x=judging_players_attributes.right, y=judging_players_label.top, height=small_button_height-7, width=judging_edit_btn_width, font=small_button_font, action=judging_players_edit_btn_func, style = 'default', color=button_color, just='right') display_items.append(judging_players_edit_btn) # ========== New Player Budget ========== budget_tf = TextField(font=std_tf_font, width=tf_width, height=std_tf_height_plus) def budget_btn_func(): if not settings['budget'][0]: settings['budget'][0] = True budget_tf.value = str(settings['budget'][1]) budget_tf.enabled = 1 player_db_button.enabled = 1 else: # Get value from text field and assign to settings if str.isdigit(budget_tf.value): settings['budget'][1] = int(budget_tf.value) settings['budget'][0] = False budget_tf.value = disabled_msg budget_tf.enabled = 0 player_db_button.enabled = 0 win_ultimate_teams.become_target() budget_btn = Button(title="New Player Budget", font=std_tf_font_bold, width=std_tf_width, height=std_tf_height_plus, x=settings_indent - std_tf_width, y=judging_players_label.bottom + title_border*2, action=budget_btn_func, color=title_color, just='right') display_items.append(budget_btn) budget_tf.x = budget_btn.right + radio_btn_space budget_tf.y = budget_btn.top display_items.append(budget_tf) # Disable based on settings if not settings['budget'][0]: budget_tf.value = disabled_msg budget_tf.enabled = 0 player_db_button.enabled = 0 else: budget_tf.value = str(settings['budget'][1]) # ========== Limits Label ========== limits_label = Label(text="Limitations", font=title_font_3, width=std_tf_width, height=title_height-25, x=(win_ultimate_teams.width - std_tf_width)/2, y=budget_tf.bottom + title_border*2, color=title_color, just='center') display_items.append(limits_label) # ========== Players per Position Label ========== players_per_pos_tf = TextField(font=std_tf_font, width=tf_width, height=std_tf_height_plus) def players_per_pos_btn_func(): if not settings['players_per_position'][0]: settings['players_per_position'][0] = True players_per_pos_tf.value = str(settings['players_per_position'][1]) players_per_pos_tf.enabled = 1 else: # Get value from text field and assign to settings if str.isdigit(players_per_pos_tf.value): settings['players_per_position'][1] = int(players_per_pos_tf.value) settings['players_per_position'][0] = False players_per_pos_tf.value = disabled_msg players_per_pos_tf.enabled = 0 win_ultimate_teams.become_target() players_per_pos_btn = Button(title="Players per Position", font=std_tf_font_bold, width=std_tf_width, height=std_tf_height_plus, x=settings_indent - std_tf_width, y=limits_label.bottom + 5, action=players_per_pos_btn_func, color=title_color, just='right') display_items.append(players_per_pos_btn) players_per_pos_tf.x = players_per_pos_btn.right + radio_btn_space players_per_pos_tf.y = players_per_pos_btn.top display_items.append(players_per_pos_tf) # Disable based on settings if not settings['players_per_position'][0]: players_per_pos_tf.value = disabled_msg players_per_pos_tf.enabled = 0 else: players_per_pos_tf.value = str(settings['players_per_position'][1]) # ========== Max Teams per Formation Label ========== teams_per_formation_tf = TextField(font=std_tf_font, width=tf_width, height=std_tf_height_plus) def teams_per_formation_btn_func(): if not settings['teams_per_formation'][0]: settings['teams_per_formation'][0] = True teams_per_formation_tf.value = str(settings['teams_per_formation'][1]) teams_per_formation_tf.enabled = 1 else: # Get value from text field and assign to settings if str.isdigit(teams_per_formation_tf.value): settings['teams_per_formation'][1] = int(teams_per_formation_tf.value) settings['teams_per_formation'][0] = False teams_per_formation_tf.value = disabled_msg teams_per_formation_tf.enabled = 0 win_ultimate_teams.become_target() teams_per_formation_btn = Button(title="Max Teams per Formation", font=std_tf_font_bold, width=std_tf_width, height=std_tf_height_plus, x=settings_indent - std_tf_width, y=players_per_pos_btn.bottom + 5, action=teams_per_formation_btn_func, color=title_color, just='right') display_items.append(teams_per_formation_btn) teams_per_formation_tf.x = teams_per_formation_btn.right + radio_btn_space teams_per_formation_tf.y = teams_per_formation_btn.top display_items.append(teams_per_formation_tf) # Disable based on settings if not settings['teams_per_formation'][0]: teams_per_formation_tf.value = disabled_msg teams_per_formation_tf.enabled = 0 else: teams_per_formation_tf.value = str(settings['teams_per_formation'][1]) # ========== Max Teams to Return Label ========== teams_to_return_tf = TextField(font=std_tf_font, width=tf_width, height=std_tf_height_plus) def teams_to_return_btn_func(): if not settings['num_teams_returned'][0]: settings['num_teams_returned'][0] = True teams_to_return_tf.value = str(settings['num_teams_returned'][1]) teams_to_return_tf.enabled = 1 else: # Get value from text field and assign to settings if str.isdigit(teams_to_return_tf.value): settings['num_teams_returned'][1] = int(teams_to_return_tf.value) settings['num_teams_returned'][0] = False teams_to_return_tf.value = disabled_msg teams_to_return_tf.enabled = 0 win_ultimate_teams.become_target() teams_to_return_btn = Button(title="Max Teams to Return", font=std_tf_font_bold, width=std_tf_width, height=std_tf_height_plus, x=settings_indent - std_tf_width, y=teams_per_formation_btn.bottom + 5, action=teams_to_return_btn_func, color=title_color, just='right') display_items.append(teams_to_return_btn) teams_to_return_tf.x = teams_to_return_btn.right + radio_btn_space teams_to_return_tf.y = teams_to_return_btn.top display_items.append(teams_to_return_tf) # Disable based on settings if not settings['num_teams_returned'][0]: teams_to_return_tf.value = disabled_msg teams_to_return_tf.enabled = 0 else: teams_to_return_tf.value = str(settings['num_teams_returned'][1]) # ========== Time Limit Label ========== time_limit_tf = TextField(font=std_tf_font, width=tf_width, height=std_tf_height_plus) def time_limit_btn_func(): if not settings['time_limit'][0]: settings['time_limit'][0] = True time_limit_val = 0.0 if settings['time_limit'][2] == 'days': time_limit_val = settings['time_limit'][1] / 86400.0 elif settings['time_limit'][2] == 'hours': time_limit_val = settings['time_limit'][1] / 3600.0 if settings['time_limit'][2] == 'minutes': time_limit_val = settings['time_limit'][1] / 60.0 time_limit_tf.value = str(time_limit_val) time_limit_tf.enabled = 1 days_time_limit_radio_btn.enabled = 1 hours_time_limit_radio_btn.enabled = 1 minutes_time_limit_radio_btn.enabled = 1 time_limit_radio_group.enabled = 1 else: # Get value from text field, convert to seconds, and assign to settings try: if settings['time_limit'][2] == 'days': settings['time_limit'][1] = int(float(time_limit_tf.value) * 86400.0) elif settings['time_limit'][2] == 'hours': settings['time_limit'][1] = int(float(time_limit_tf.value) * 3600.0) elif settings['time_limit'][2] == 'minutes': settings['time_limit'][1] = int(float(time_limit_tf.value) * 60.0) except ValueError: print "Invalid time limit." settings['time_limit'][0] = False time_limit_tf.value = disabled_msg time_limit_tf.enabled = 0 days_time_limit_radio_btn.enabled = 0 hours_time_limit_radio_btn.enabled = 0 minutes_time_limit_radio_btn.enabled = 0 time_limit_radio_group.enabled = 0 win_ultimate_teams.become_target() time_limit_btn = Button(title="Time Limit", font=std_tf_font_bold, width=std_tf_width, height=std_tf_height_plus, x=settings_indent - std_tf_width, y=teams_to_return_btn.bottom + 5, action=time_limit_btn_func, color=title_color, just='right') display_items.append(time_limit_btn) def get_time_limit_rg(): # Get value from text field, convert to seconds, and assign to settings if time_limit_tf.value == '': time_limit_tf.value = '0' else: try: if settings['time_limit'][2] == 'days': settings['time_limit'][1] = int(float(time_limit_tf.value) * 86400.0) elif settings['time_limit'][2] == 'hours': settings['time_limit'][1] = int(float(time_limit_tf.value) * 3600.0) elif settings['time_limit'][2] == 'minutes': settings['time_limit'][1] = int(float(time_limit_tf.value) * 60.0) except ValueError: print "Invalid time limit." # Get new time limit units settings['time_limit'][2] = time_limit_radio_group.value time_limit_val = 0.0 if settings['time_limit'][2] == 'days': time_limit_val = settings['time_limit'][1] / 86400.0 elif settings['time_limit'][2] == 'hours': time_limit_val = settings['time_limit'][1] / 3600.0 elif settings['time_limit'][2] == 'minutes': time_limit_val = settings['time_limit'][1] / 60.0 time_limit_tf.value = str(time_limit_val) win_ultimate_teams.become_target() time_limit_radio_group = RadioGroup(action=get_time_limit_rg) # Time Limit Units Radio Buttons days_time_limit_radio_btn = RadioButton('Days', width=radio_btn_width, x=time_limit_btn.right + radio_btn_space, y=time_limit_btn.bottom + 5, group=time_limit_radio_group, value='days') display_items.append(days_time_limit_radio_btn) hours_time_limit_radio_btn = RadioButton('Hours', width=radio_btn_width, x=days_time_limit_radio_btn.right + radio_btn_space, y=days_time_limit_radio_btn.top, group=time_limit_radio_group, value='hours') display_items.append(hours_time_limit_radio_btn) minutes_time_limit_radio_btn = RadioButton('Minutes', width=radio_btn_width, x=hours_time_limit_radio_btn.right + radio_btn_space, y=days_time_limit_radio_btn.top, group=time_limit_radio_group, value='minutes') display_items.append(minutes_time_limit_radio_btn) time_limit_radio_group.value = settings['time_limit'][2] time_limit_tf.x = time_limit_btn.right + radio_btn_space time_limit_tf.y = time_limit_btn.top display_items.append(time_limit_tf) # Disable based on settings if not settings['time_limit'][0]: time_limit_tf.value = disabled_msg time_limit_tf.enabled = 0 days_time_limit_radio_btn.enabled = 0 hours_time_limit_radio_btn.enabled = 0 minutes_time_limit_radio_btn.enabled = 0 time_limit_radio_group.enabled = 0 else: time_limit_value = 0.0 if settings['time_limit'][2] == 'days': time_limit_value = settings['time_limit'][1] / 86400.0 elif settings['time_limit'][2] == 'hours': time_limit_value = settings['time_limit'][1] / 3600.0 elif settings['time_limit'][2] == 'minutes': time_limit_value = settings['time_limit'][1] / 60.0 time_limit_tf.value = str(time_limit_value) # ========== Button Declarations ========== start_btn = Button("Start") menu_btn = Button("Main Menu") back_btn = Button("Back") # ========== Button Functions ========== def save_settings(): """ Save the ultimate team creation configuration settings """ # Get the values from the text fields # New player budget if str.isdigit(budget_tf.value): settings['budget'][1] = int(budget_tf.value) # Players per position if str.isdigit(players_per_pos_tf.value): settings['players_per_position'][1] = int(players_per_pos_tf.value) # Teams per formation if str.isdigit(teams_per_formation_tf.value): settings['teams_per_formation'][1] = int(teams_per_formation_tf.value) # Number of teams returned if str.isdigit(teams_to_return_tf.value): settings['num_teams_returned'][1] = int(teams_to_return_tf.value) # Time limit if time_limit_tf.value != disabled_msg: try: if settings['time_limit'][2] == 'days': settings['time_limit'][1] = int(float(time_limit_tf.value) * 86400.0) elif settings['time_limit'][2] == 'hours': settings['time_limit'][1] = int(float(time_limit_tf.value) * 3600.0) elif settings['time_limit'][2] == 'minutes': settings['time_limit'][1] = int(float(time_limit_tf.value) * 60.0) except ValueError: print "Invalid time limit." # Load configurations from Window.AppConfig import config_filename with open(config_filename, 'r') as config_file: configurations = json.load(config_file) config_file.close() # Edit configurations configurations['ultimate_team_configs'] = settings # Save the settings with open(config_filename, 'w') as config_file: json.dump(configurations, config_file) config_file.close() def start_btn_func(): save_settings() # Assign formation(s) to use if input_formation is None or input_formation['name'] == "Generic": formations = db_dict['formation_list'][1] else: formations = FormationDB.FormationDB(input_formation) # If budget is not used, set player DB to an empty object. if budget_btn.enabled: player_db = db_dict['player_db'][1] else: player_db = PlayerDB.PlayerDB() # Open status page """StatusWindow.open_status_window(win_ultimate_teams.x, win_ultimate_teams.y, db_dict, file_name=team_list_name_tf.value, win_previous=win_ultimate_teams) win_ultimate_teams.hide()""" # Run team creation here team = Team.Team() teams = TeamDB.TeamDB(team.create_team_ultimate(db_dict['player_list'][1], player_db, formations)) if len(teams.db) > 0: teams.save(team_list_name_tf.value) else: print 'Not saved because no teams created.' # Erase file name team_list_name_tf.value = '' win_ultimate_teams.become_target() def menu_btn_func(): save_settings() StartMenu.open_start_menu(win_ultimate_teams.x, win_ultimate_teams.y, db_dict) win_ultimate_teams.hide() def back_btn_func(): save_settings() win_previous.show() win_ultimate_teams.hide() # Save the attribute lists if they were changed if player_judge_list is not None: save_settings() if team_judge_list is not None: save_settings() # ========== Buttons ========== start_btn.x = (win_width - 3*button_width - 2*button_spacing) / 2 start_btn.y = win_ultimate_teams.height - 100 start_btn.height = button_height start_btn.width = button_width start_btn.font = button_font start_btn.action = start_btn_func start_btn.style = 'default' start_btn.color = button_color start_btn.just = 'right' display_items.append(start_btn) menu_btn.x = start_btn.right + button_spacing menu_btn.y = start_btn.top menu_btn.height = button_height menu_btn.width = button_width menu_btn.font = button_font menu_btn.action = menu_btn_func menu_btn.style = 'default' menu_btn.color = button_color menu_btn.just = 'right' display_items.append(menu_btn) back_btn.x = menu_btn.right + button_spacing back_btn.y = start_btn.top back_btn.height = button_height back_btn.width = button_width back_btn.font = button_font back_btn.action = back_btn_func back_btn.style = 'default' back_btn.color = button_color back_btn.just = 'right' display_items.append(back_btn) # ========== Add components to view and add view to window ========== for item in display_items: view.add(item) win_ultimate_teams.add(view) view.become_target() win_ultimate_teams.show()