Ejemplo n.º 1
0
def open_enter_text_window(window_x, window_y, db_dict, settings, box_type, fill_text='', file_prefix=''):

    general_display = []

    if box_type == 'rename':
        title = 'Rename File'
        old_file_name = fill_text
        message_text = 'Enter new file name.'
    elif box_type == 'duplicate':
        title = 'Duplicate File'
        old_file_name = fill_text
        message_text = 'Enter new file name.'
    elif box_type == 'download':
        title = 'Download Player Database'
        message_text = 'Enter player database name.'
        download_settings = {'overwrite_counter': 0, 'last_entered_text': ''}
    else:
        title = 'Enter Text'
        message_text = 'Enter text.'

    # ========== Window ==========
    win_enter_text = Window()
    win_enter_text.title = title
    win_enter_text.auto_position = False
    win_enter_text.position = (window_x+100, window_y+100)
    win_enter_text.size = (win_width-200, win_height-400)
    win_enter_text.resizable = 0
    win_enter_text.name = enter_text_title + " Window"
    win_enter_text.show()

    # ========== Window Image View ==========
    class StartWindowImageView(View):
        def draw(self, c, r):
            c.backcolor = view_backcolor
            c.erase_rect(r)

    view = StartWindowImageView(size=win_enter_text.size)

    # ========== Title ==========
    title = Label(text=title)
    title.font = title_font
    title.width = title_width
    title.height = title_height
    title.x = (win_enter_text.width - title_width) / 2
    title.y = top_border
    title.color = title_color
    title.just = 'center'
    general_display.append(title)

    # ========== Message Label ==========
    message = Label(font=title_font_2, width=win_enter_text.width - 50, height=title_height,
                    x=25, y=title.bottom + top_border, color=title_color, just='center')
    message.text = message_text
    general_display.append(message)

    # ========== Button Declarations ==========
    enter_btn = Button("Enter")
    back_btn = Button("Back")

    # ========== Button Functions ==========
    def enter_btn_func():
        # Rename file
        if box_type == 'rename':

            # Get new name
            new_file_name = value_tf.value

            if len(new_file_name) > 0:

                if not isfile('JSONs/' + file_prefix + new_file_name + '.json'):
                    # Rename file
                    rename('JSONs/' + file_prefix + old_file_name + '.json',
                           'JSONs/' + file_prefix + new_file_name + '.json')

                    # Disable pick file back button in case the selected file has changed
                    settings['file_changes'] = True

                    PickFile.open_pick_file_window(window_x, window_y, db_dict, settings)
                    win_enter_text.hide()

                else:
                    message.text = "A file with that name already exists."

            else:
                message.text = "File name must be at least 1 character."

        # Duplicate file
        elif box_type == 'duplicate':

            # Get new name
            duplicate_file_name = value_tf.value

            if len(duplicate_file_name) > 0:

                if not isfile('JSONs/' + file_prefix + duplicate_file_name + '.json'):
                    # Create duplicate file
                    copyfile('JSONs/' + file_prefix + old_file_name + '.json',
                             'JSONs/' + file_prefix + duplicate_file_name + '.json')

                    PickFile.open_pick_file_window(window_x, window_y, db_dict, settings)
                    win_enter_text.hide()

                else:
                    message.text = "A file with that name already exists."

            else:
                message.text = "File name must be at least 1 character."

        elif box_type == 'download':
            valid_name = False

            # Get new player database name
            new_player_db_name = value_tf.value

            if new_player_db_name != download_settings['last_entered_text']:
                download_settings['overwrite_counter'] = 0
                message.text = message_text

            if len(new_player_db_name) > 0:

                if not isfile('JSONs/play_db_' + new_player_db_name + '.json'):
                    valid_name = True

                else:
                    download_settings['last_entered_text'] = new_player_db_name

                    if download_settings['overwrite_counter'] == 0:
                        download_settings['overwrite_counter'] += 1
                        message.text = "File already exists. Overwrite?"
                    elif download_settings['overwrite_counter'] == 1:
                        download_settings['overwrite_counter'] += 1
                        message.text = "Are you sure you want to overwrite?"
                    elif download_settings['overwrite_counter'] == 2:
                        download_settings['overwrite_counter'] += 1
                        message.text = "Really, really, really sure?"
                    elif download_settings['overwrite_counter'] >= 3:
                        valid_name = True

                if valid_name:
                    # Open status window to start download of players
                    StatusWindow.open_status_window(win_enter_text.x, win_enter_text.y, db_dict,
                                                    get_prices=sort_order_radio_group.value,
                                                    file_name=new_player_db_name, settings=settings,
                                                    win_previous=win_enter_text, win_next='FilesMenu')
                    win_enter_text.hide()

            else:
                message.text = "File name must be at least 1 character."

    def back_btn_func():
        if box_type == 'download':
            FilesMenu.open_files_menu(window_x, window_y, db_dict, settings)
        else:
            PickFile.open_pick_file_window(window_x, window_y, db_dict, settings)
        win_enter_text.hide()

    # ========== Buttons ==========
    enter_btn.x = (win_enter_text.width - 2*button_width - button_spacing) / 2
    enter_btn.y = win_enter_text.height - 70
    enter_btn.height = button_height
    enter_btn.width = button_width
    enter_btn.font = button_font
    enter_btn.action = enter_btn_func
    enter_btn.style = 'default'
    enter_btn.color = button_color
    enter_btn.just = 'right'
    general_display.append(enter_btn)

    back_btn.x = enter_btn.right + button_spacing
    back_btn.y = enter_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'
    general_display.append(back_btn)

    # ========== Value Textfield ==========
    value_tf = TextField()
    value_tf.width = 200
    value_tf.x = (win_enter_text.width - value_tf.width) / 2
    value_tf.y = enter_btn.top - 65
    value_tf.height = 25
    value_tf.font = std_tf_font
    value_tf.value = fill_text
    general_display.append(value_tf)

    def get_attribute_sort_order_rg():
        settings['order_rg'] = sort_order_radio_group.value
        win_enter_text.become_target()

    sort_order_radio_group = RadioGroup(action=get_attribute_sort_order_rg)

    prices_label_width = 85
    prices_button_width = 50
    prices_label = Label(text="Get Prices?:", font=std_tf_font, width=prices_label_width, height=std_tf_height,
                         color=title_color)
    prices_label.x = (win_enter_text.width - 2*prices_button_width - 10 - prices_label_width) / 2
    prices_label.y = enter_btn.top - 38
    prices_label.just = 'center'

    prices_yes = RadioButton("Yes")
    prices_yes.width = prices_button_width
    prices_yes.x = prices_label.right + 5
    prices_yes.y = prices_label.top
    prices_yes.group = sort_order_radio_group
    prices_yes.value = True

    prices_no = RadioButton("No")
    prices_no.width = prices_button_width
    prices_no.x = prices_yes.right + 5
    prices_no.y = prices_label.top
    prices_no.group = sort_order_radio_group
    prices_no.value = False

    sort_order_radio_group.value = True

    if box_type == 'download':
        value_tf.y = enter_btn.top - 75

        general_display.append(prices_label)
        general_display.append(prices_yes)
        general_display.append(prices_no)

    # ========== Add buttons to window ==========
    for item in general_display:
        view.add(item)

    win_enter_text.add(view)
    view.become_target()
    win_enter_text.show()
Ejemplo n.º 2
0
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()