Esempio n. 1
0
    def display_players(results_list, attributes, index_range):
        # Remove old messages off page
        for result_message in create_list_settings['results']:
            view.remove(result_message)
        del create_list_settings['results'][:]

        # Add navigation buttons to page
        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

        create_list_settings['results'].append(previous_btn)
        create_list_settings['results'].append(next_btn)
        create_list_settings['results'].append(total_num_results_label)
        create_list_settings['results'].append(pages_label)

        # Print out labels
        labels = [''] + player_info_labels(attributes)
        stat_index = 0
        add_btn_width = 30
        add_btn_space = add_btn_width + 10
        spacing_list = [add_btn_space, 125, 40, 40, 65, 115, 115, 115]
        left_border = (win_create_list.width - sum(spacing_list)) / 2
        msg_x = left_border
        msg_y = previous_btn.bottom + 5

        for info_label in labels:
            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)
            create_list_settings['results'].append(player_label)
            msg_x += spacing_list[stat_index]
            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

            add_btn = Button("Add", width=add_btn_width, height=15, x=msg_x, y=msg_y,
                             action=(add_player_btn_func, player))
            create_list_settings['results'].append(add_btn)
            msg_x += spacing_list[stat_index]
            stat_index += 1

            for player_stat in player_stats:
                player_label = Label(text=player_stat, font=small_button_font, width=win_width-(2*left_border),
                                     height=std_tf_height, x=msg_x, y=msg_y, color=title_color)

                create_list_settings['results'].append(player_label)
                msg_x += spacing_list[stat_index]
                stat_index += 1

            msg_y += std_tf_height

        for results_msg in create_list_settings['results']:
            view.add(results_msg)
Esempio n. 2
0
    def display_players(display_db, attributes, index_range):
        # Remove old messages off page
        for message in settings['messages']['results']:
            view.remove(message)
        del settings['messages']['results'][:]

        # Add navigation buttons to page
        if settings['edit_type'] == 'add':
            add_to_list_btn.title = 'Add All Players'
            add_to_list_btn.action = (add_to_list_btn_func, display_db.db, 'add all')
        elif settings['edit_type'] == 'edit':
            add_to_list_btn.title = 'Remove All Players'
            add_to_list_btn.action = (add_to_list_btn_func, display_db.db, 'remove all')
        else:
            print "Invalid edit type."

        previous_range = (index_range[0]-num_results, index_range[0])
        previous_btn.action = (previous_btn_func, display_db, attributes, previous_range)

        next_range = (index_range[1], index_range[1]+num_results)
        next_btn.action = (next_btn_func, display_db, attributes, next_range)

        total_num_results_label.text = str(len(display_db.db)) + " Players"
        pages_label.text = "Page %d of %d" % (int(index_range[1]/num_results),
                                              math.ceil(len(display_db.db) / float(num_results)))

        if index_range[0] > 0:
            previous_btn.enabled = 1
        else:
            previous_btn.enabled = 0
        if index_range[1] <= len(display_db.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 = 1
        spacing_list = [25, 125, 40, 40, 65, 115, 115, 115, 40]
        left_border = (win_width - sum(spacing_list[:-1]) - (len(labels) - len(spacing_list) + 2) * spacing_list[-1])/2
        msg_x = left_border + spacing_list[0]
        msg_y = add_to_list_btn.bottom + 5

        for info_label in labels:
            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(display_db.db[index_range[0]:index_range[1]]):
            msg_x = left_border
            player_stats = player_info(player, attributes)
            stat_index = 0

            player_data = list_players.search({'id': (player['id'], 'exact')})
            if len(player_data) > 0:
                add_btn_text = '-'
                temp_player = player_data[0]
            else:
                add_btn_text = '+'
                temp_player = player
            add_btn = Button(title=add_btn_text, width=spacing_list[stat_index]-5, height=15, x=msg_x, y=msg_y)
            add_btn.action = (add_btn_func, temp_player, add_btn)
            settings['messages']['results'].append(add_btn)
            msg_x += spacing_list[stat_index]
            stat_index += 1

            # 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, temp_player))
            settings['messages']['results'].append(bio_btn)
            msg_x += spacing_list[stat_index]
            stat_index += 1

            for player_stat in player_stats[1:]:
                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)

                # Save values for position edit button
                if stat_index == 3:
                    edit_x = msg_x
                    edit_y = msg_y

                msg_x += spacing_list[stat_index]
                if stat_index < len(spacing_list) - 1:
                    stat_index += 1

            if settings['edit_type'] == 'edit':
                pos_btn = Button(title=player_stats[2], width=28, height=15, x=edit_x, y=edit_y)
                pos_btn.action = (pos_btn_func, player, pos_btn)
                settings['messages']['results'].append(pos_btn)

            msg_y += std_tf_height

        for results_msg in settings['messages']['results']:
            view.add(results_msg)
Esempio n. 3
0
    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"][:]

        # Add navigation buttons to page
        if settings["p_db_rg"] == "player_db":
            add_to_list_btn.title = "Add All Players"
            add_to_list_btn.action = (add_to_list_btn_func, results_list.db, "add all")
        elif settings["p_db_rg"] == "player_list":
            add_to_list_btn.title = "Remove All Players"
            add_to_list_btn.action = (add_to_list_btn_func, results_list.db, "remove all")
        else:
            print "Invalid edit type."

        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_search.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)