From 8ad11db860898dcfc9269f2b84df7e301a6e8e5c Mon Sep 17 00:00:00 2001 From: Simeon Simeonov Date: Tue, 23 Dec 2025 01:44:38 +0100 Subject: Initial commit --- __init__.py | 0 __main__.py | 6 +++++ app.py | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ resources/README | 2 ++ 4 files changed, 83 insertions(+) create mode 100644 __init__.py create mode 100644 __main__.py create mode 100644 app.py create mode 100644 resources/README diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/__main__.py b/__main__.py new file mode 100644 index 0000000..8fac33c --- /dev/null +++ b/__main__.py @@ -0,0 +1,6 @@ +"""main entry point""" + +from scorecounter.app import main + +if __name__ == '__main__': + main().main_loop() diff --git a/app.py b/app.py new file mode 100644 index 0000000..cf4bc1d --- /dev/null +++ b/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() diff --git a/resources/README b/resources/README new file mode 100644 index 0000000..4ef2794 --- /dev/null +++ b/resources/README @@ -0,0 +1,2 @@ +Put any application resources (e.g., icons and resources) here; +they can be referenced in code as "resources/filename". -- cgit v1.3