From 218e636f7226fe10fd816b004c6b6d9fc44b46fe Mon Sep 17 00:00:00 2001 From: Simeon Simeonov Date: Thu, 25 Dec 2025 22:28:21 +0100 Subject: Add support for setting team names --- CHANGELOG | 2 +- src/scorecounter/app.py | 84 +++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 68 insertions(+), 18 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 3a9a25a..076474e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,5 @@ # scorecounter Release Notes -## 0.0.1 (22 Dec 2025) +## 1.0.0 (23 Dec 2025) * Initial release diff --git a/src/scorecounter/app.py b/src/scorecounter/app.py index 26a0c74..32217aa 100644 --- a/src/scorecounter/app.py +++ b/src/scorecounter/app.py @@ -1,6 +1,7 @@ """Simple score counter for two teams""" import toga +from toga.colors import BLUE, RED, WHITE from toga.constants import COLUMN, ROW @@ -12,21 +13,24 @@ class ScoreCounter(toga.App): self._score_team1 = 0 self._score_team2 = 0 + self._name_team1 = 'Team 1' + self._name_team2 = 'Team 2' + self.main_window = toga.MainWindow( title=self.formal_name, on_resize=self.cb_main_window_resize ) self._score_label1 = toga.Label( - f'Team1: {self._score_team1}', + f'{self._name_team1}: {self._score_team1}', margin=(0, 5), - color='red', + color=RED, font_weight='bold', font_size=24, ) self._score_label2 = toga.Label( - f'Team2: {self._score_team2}', + f'{self._name_team2}: {self._score_team2}', margin=(0, 5), - color='blue', + color=BLUE, font_weight='bold', font_size=24, ) @@ -37,24 +41,21 @@ class ScoreCounter(toga.App): children=[self._score_label1, separator_label, self._score_label2], ) - # empty box for consuming vertical space - empty_box = toga.Box(flex=1) - self._button_team1 = toga.Button( - 'Team 1 (+1)', + f'{self._name_team1} (+1)', on_press=self.cb_score_team1, - background_color='red', + background_color=RED, flex=1, font_size=18, - color='white', + color=WHITE, ) self._button_team2 = toga.Button( - 'Team 2 (+1)', + f'{self._name_team2} (+1)', on_press=self.cb_score_team2, - background_color='blue', + background_color=BLUE, flex=1, font_size=18, - color='white', + color=WHITE, ) button_box = toga.Box( direction=COLUMN, @@ -63,16 +64,23 @@ class ScoreCounter(toga.App): ) self.main_window.content = toga.Box( - direction=COLUMN, children=[score_box, empty_box, button_box] + direction=COLUMN, + children=[score_box, toga.Box(flex=1), button_box], ) self._button_team1.style.height = int(self.main_window.size.height / 5) self._button_team2.style.height = int(self.main_window.size.height / 5) + scoreboard_group = toga.Group('Scoreboard') command_clear = toga.Command( - self.cb_clear, text='Clear', group=toga.Group('Scoreboard') + self.cb_clear, text='Clear', group=scoreboard_group ) self.commands.add(command_clear) + command_settings = toga.Command( + self.cb_settings, text='Settings', group=scoreboard_group + ) + self.commands.add(command_settings) + self.main_window.show() def cb_clear(self, _widget): @@ -96,10 +104,52 @@ class ScoreCounter(toga.App): self._button_team1.style.height = int(widget.size.height / 5) self._button_team2.style.height = int(widget.size.height / 5) + def cb_set(self, _widget): + """Set the settings callback""" + self._name_team1 = self._input_team1.value + self._name_team2 = self._input_team2.value + self.refresh() + self._settings_window.close() + + def cb_settings(self, _widget): + """Create settings window menu""" + self._settings_window = toga.Window() + + self._input_team1 = toga.TextInput(flex=1, value=self._name_team1) + box_team1 = toga.Box( + direction=ROW, + margin=5, + children=[toga.Label('Team 1:', margin=5), self._input_team1], + ) + + self._input_team2 = toga.TextInput(flex=1, value=self._name_team2) + box_team2 = toga.Box( + direction=ROW, + margin=5, + children=[toga.Label('Team 2:', margin=5), self._input_team2], + ) + + button_box = toga.Box( + direction=ROW, + children=[ + toga.Label('', flex=1), + toga.Button('Set', on_press=self.cb_set), + toga.Label('', flex=1), + ], + ) + + self._settings_window.content = toga.Box( + direction=COLUMN, + children=[box_team1, box_team2, toga.Box(flex=1), button_box], + ) + self._settings_window.show() + def refresh(self): """Refreshes the score labels""" - self._score_label1.text = f'Team1: {self._score_team1}' - self._score_label2.text = f'Team2: {self._score_team2}' + self._button_team1.text = f'{self._name_team1} (+1)' + self._button_team2.text = f'{self._name_team2} (+1)' + self._score_label1.text = f'{self._name_team1}: {self._score_team1}' + self._score_label2.text = f'{self._name_team2}: {self._score_team2}' def main(): -- cgit v1.3