From a29c4509a316c0c77450b6fa74b96f036b0f0821 Mon Sep 17 00:00:00 2001 From: Simeon Simeonov Date: Tue, 23 Dec 2025 09:59:50 +0100 Subject: Add structure --- src/scorecounter/__init__.py | 0 src/scorecounter/__main__.py | 6 ++++ src/scorecounter/app.py | 75 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 src/scorecounter/__init__.py create mode 100644 src/scorecounter/__main__.py create mode 100644 src/scorecounter/app.py (limited to 'src') diff --git a/src/scorecounter/__init__.py b/src/scorecounter/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/scorecounter/__main__.py b/src/scorecounter/__main__.py new file mode 100644 index 0000000..8fac33c --- /dev/null +++ b/src/scorecounter/__main__.py @@ -0,0 +1,6 @@ +"""main entry point""" + +from scorecounter.app import main + +if __name__ == '__main__': + main().main_loop() diff --git a/src/scorecounter/app.py b/src/scorecounter/app.py new file mode 100644 index 0000000..cf4bc1d --- /dev/null +++ b/src/scorecounter/app.py @@ -0,0 +1,75 @@ +"""Simple score counter for two teams""" + +import toga +from toga.style.pack import COLUMN, ROW + + +class ScoreCounter(toga.App): + """The main ScoreCounter application""" + + def startup(self): + """startup entry point""" + self.score_team1 = 0 + self.score_team2 = 0 + + main_box = toga.Box(direction=COLUMN) + + self.score_label1 = toga.Label( + f'Team1: {self.score_team1}', margin=(0, 5), color='red' + ) + self.score_label2 = toga.Label( + f'Team2: {self.score_team2}', margin=(0, 5), color='blue' + ) + self.separator_label = toga.Label(' - ', margin=(0, 10)) + + score_box = toga.Box(direction=ROW, margin=5) + score_box.add(self.score_label1) + score_box.add(self.separator_label) + score_box.add(self.score_label2) + + button_clear = toga.Button( + 'Clear', on_press=self.cb_clear, margin=(20, 5, 5) + ) + button_team1 = toga.Button( + 'Team 1 (+1)', on_press=self.cb_score_team1, margin=(20, 5, 5) + ) + button_team1.style.background_color = 'red' + button_team2 = toga.Button( + 'Team 2 (+1)', on_press=self.cb_score_team2, margin=5 + ) + button_team2.style.background_color = 'blue' + + main_box.add(score_box) + main_box.add(button_team1) + main_box.add(button_team2) + main_box.add(button_clear) + + self.main_window = toga.MainWindow(title=self.formal_name) + self.main_window.content = main_box + self.main_window.show() + + def cb_clear(self, _widget): + """Clear on press callback""" + self.score_team1 = 0 + self.score_team2 = 0 + self.refresh() + + def cb_score_team1(self, _widget): + """Team1 on press callback""" + self.score_team1 += 1 + self.refresh() + + def cb_score_team2(self, _widget): + """Team 2 on press callback""" + self.score_team2 += 1 + self.refresh() + + 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}' + + +def main(): + """main entry point""" + return ScoreCounter() -- cgit v1.3