Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to display current entry ranking #20

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/main/python/gui/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ def _init_layout(self):
self.display_flags_check.setChecked(False)
self.display_flags_check.stateChanged.connect(self._validate_flags)

self.display_ranking_check = QCheckBox('Display Ranking')
self.display_ranking_check.setChecked(False)

scoreboard_details_grid.addWidget(QLabel('Scoreboard Title'), 0, 0)
scoreboard_details_grid.addWidget(self.scoreboard_title_le, 0, 1, 1, 2)
scoreboard_details_grid.addWidget(self.main_color_btn, 1, 0)
Expand All @@ -130,7 +133,8 @@ def _init_layout(self):
scoreboard_details_grid.addWidget(self.accent_color_btn, 2, 0)
scoreboard_details_grid.addWidget(self.reset_accent_color_btn, 2, 1)
scoreboard_details_grid.addWidget(self.accent_color_le, 2, 2)
scoreboard_details_grid.addWidget(self.display_flags_check, 3, 0, 1, 3)
scoreboard_details_grid.addWidget(self.display_flags_check, 3, 0, 1, 1)
scoreboard_details_grid.addWidget(self.display_ranking_check, 3, 1, 1, 2)
scoreboard_details_group = QGroupBox('Scoreboard Details')
scoreboard_details_group.setLayout(scoreboard_details_grid)

Expand Down Expand Up @@ -303,6 +307,7 @@ def _generate_scoreboards(self):
main_color=self.main_color_le.text(),
accent_color=self.accent_color_le.text(),
display_flags=self.display_flags_check.isChecked(),
display_ranking=self.display_ranking_check.isChecked(),
windows_dpi_scaling=dpi_scaling_factor
))

Expand Down
27 changes: 17 additions & 10 deletions src/main/python/scoreboard/scoreboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,61 +70,68 @@ def _draw_scoreboard(self, painter, sizes, voter_num):
x_offset = 10 * scaling + sizes.rectangle
y_offset = i - left_col

# Display the entry's current ranking
if self.details.display_ranking:
self._draw_text(painter, QPoint(27 * scaling + x_offset,
87 * scaling + 35 * scaling * y_offset),
str(i + 1),
self.fonts.ranking, self.colors.grey_text, Qt.AlignHCenter)

# Display the entry's country flag
if self.details.display_flags:
try:
flag = QImage(self.app_context.get_resource(join("flags", entry.flag)))
flag = flag.scaledToWidth(
20 * scaling, Qt.SmoothTransformation)
self._draw_rectangle(painter,
QPoint(27 * scaling - flag.width() / 2.0 + x_offset, 87 *
QPoint(27 * scaling - flag.width() / 2.0 + x_offset + sizes.rank_offset, 87 *
scaling - flag.height() / 2.0 + 35 * scaling * y_offset),
QPoint(flag.width() + 0.5, flag.height() + 0.5),
self.colors.white, border=self.colors.grey_text, border_width=0.5 * scaling)
painter.drawImage(QPoint(27 * scaling - flag.width() / 2.0 + x_offset,
painter.drawImage(QPoint(27 * scaling - flag.width() / 2.0 + x_offset + sizes.rank_offset,
87 * scaling - flag.height() / 2.0 + 35 * scaling * y_offset), flag)
except FileNotFoundError:
continue

# Display entry details
self._draw_text(painter,
QPoint(20 * scaling + x_offset + sizes.flag_offset, 80 * scaling + 35 * scaling * y_offset),
QPoint(20 * scaling + x_offset + sizes.rank_offset + sizes.flag_offset, 80 * scaling + 35 * scaling * y_offset),
entry.country, self.fonts.country, self.colors.country_text, Qt.AlignLeft)
self._draw_text(painter,
QPoint(20 * scaling + x_offset + sizes.flag_offset, 94 * scaling + 35 * scaling * y_offset),
QPoint(20 * scaling + x_offset + sizes.rank_offset + sizes.flag_offset, 94 * scaling + 35 * scaling * y_offset),
"{} – {}".format(entry.artist, entry.song), self.fonts.entry_details, self.colors.black,
Qt.AlignLeft)

# Display the entry's total number of received points
if entry.dq_statuses[voter_num]:
self._draw_rectangle(painter, QPoint(30 * scaling + x_offset + sizes.flag_offset + sizes.entry_details,
self._draw_rectangle(painter, QPoint(30 * scaling + x_offset + sizes.rank_offset + sizes.flag_offset + sizes.entry_details,
77 * scaling + 35 * scaling * y_offset),
QPoint(29 * scaling, 20 * scaling), self.colors.grey_text)
self._draw_text(painter, QPoint(44.5 * scaling + x_offset + sizes.flag_offset + sizes.entry_details,
self._draw_text(painter, QPoint(44.5 * scaling + x_offset + sizes.rank_offset + sizes.flag_offset + sizes.entry_details,
87 * scaling + 35 * scaling * y_offset),
"{}".format(entry.display_pts[voter_num]),
self.fonts.total_pts, self.colors.black, Qt.AlignHCenter)
else:
self._draw_rectangle(painter, QPoint(30 * scaling + x_offset + sizes.flag_offset + sizes.entry_details,
self._draw_rectangle(painter, QPoint(30 * scaling + x_offset + sizes.rank_offset + sizes.flag_offset + sizes.entry_details,
77 * scaling + 35 * scaling * y_offset),
QPoint(29 * scaling, 20 * scaling), self.colors.main)
self._draw_text(painter, QPoint(44.5 * scaling + x_offset + sizes.flag_offset + sizes.entry_details,
self._draw_text(painter, QPoint(44.5 * scaling + x_offset + sizes.rank_offset + sizes.flag_offset + sizes.entry_details,
87 * scaling + 35 * scaling * y_offset),
"{}".format(entry.display_pts[voter_num]),
self.fonts.total_pts, self.colors.main_text, Qt.AlignHCenter)

# Display the entry's number of points received by the current voter
if len(entry.votes[voter_num]) > 0:
self._draw_rectangle(painter,
QPoint(59 * scaling + x_offset + sizes.flag_offset + sizes.entry_details,
QPoint(59 * scaling + x_offset + sizes.rank_offset + sizes.flag_offset + sizes.entry_details,
77 * scaling + 35 * scaling * y_offset),
QPoint(24 * scaling, 20 * scaling), self.colors.accent)

try:
votes_string = int(float(entry.votes[voter_num]))
except ValueError:
votes_string = entry.votes[voter_num]
self._draw_text(painter, QPoint(71 * scaling + x_offset + sizes.flag_offset + sizes.entry_details,
self._draw_text(painter, QPoint(71 * scaling + x_offset + sizes.rank_offset + sizes.flag_offset + sizes.entry_details,
87 * scaling + 35 * scaling * y_offset),
str(votes_string), self.fonts.awarded_pts, self.colors.accent_text, Qt.AlignHCenter)

Expand Down
11 changes: 9 additions & 2 deletions src/main/python/scoreboard/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


class ScoreboardDetails:
def __init__(self, contest, output_dir, title, main_color, accent_color, display_flags=True,
def __init__(self, contest, output_dir, title, main_color, accent_color, display_flags=True, display_ranking=True,
image_scaling=DEFAULT_IMAGE_scaling, windows_dpi_scaling=DEFAULT_WINDOWS_DPI_SCALING):
self.contest = contest
self.output_dir = output_dir
Expand All @@ -22,6 +22,7 @@ def __init__(self, contest, output_dir, title, main_color, accent_color, display
self.main_color = main_color
self.accent_color = accent_color
self.display_flags = display_flags
self.display_ranking = display_ranking
self.scaling = image_scaling

# On Windows, text is rendered differently depending on the DPI scaling factor which we need to account for
Expand All @@ -44,6 +45,7 @@ def __init__(self, image_scaling=DEFAULT_IMAGE_scaling, windows_dpi_scaling=DEFA
self.entry_details = QFont(DEFAULT_BASE_FONT_FAMILY, 12 * image_scaling * font_os_scaling)
self.awarded_pts = QFont(DEFAULT_POINTS_FONT_FAMILY, 14 * image_scaling * font_os_scaling)
self.total_pts = QFont(DEFAULT_POINTS_FONT_FAMILY, 14 * image_scaling * font_os_scaling, weight=QFont.DemiBold)
self.ranking = QFont(DEFAULT_POINTS_FONT_FAMILY, 14 * image_scaling * font_os_scaling, weight=QFont.DemiBold)


class ScoreboardColors:
Expand Down Expand Up @@ -102,8 +104,13 @@ def __init__(self, details, fonts, voter_num):
else:
self.flag_offset = 0

if details.display_ranking:
self.rank_offset = 24 * details.scaling
else:
self.rank_offset = 0

self.rectangle = max(
self.country, self.entry_details) + self.flag_offset + 80 * details.scaling
self.country, self.entry_details) + self.rank_offset + self.flag_offset + 80 * details.scaling

self.width = max(max(30 * details.scaling + 2 * self.rectangle, 48 *
details.scaling + self.contest_header), 10 * details.scaling + self.voter_header)
Expand Down