From de4b58fbf9b3507b43ae343eca7cc03c429e4b41 Mon Sep 17 00:00:00 2001 From: Simeon Simeonov Date: Thu, 25 Dec 2025 23:05:03 +0100 Subject: Use only the main window --- src/scorecounter/app.py | 109 ++++++++++++++++++++++++------------------------ 1 file changed, 55 insertions(+), 54 deletions(-) diff --git a/src/scorecounter/app.py b/src/scorecounter/app.py index 32217aa..fecdf9d 100644 --- a/src/scorecounter/app.py +++ b/src/scorecounter/app.py @@ -20,55 +20,7 @@ class ScoreCounter(toga.App): title=self.formal_name, on_resize=self.cb_main_window_resize ) - self._score_label1 = toga.Label( - f'{self._name_team1}: {self._score_team1}', - margin=(0, 5), - color=RED, - font_weight='bold', - font_size=24, - ) - self._score_label2 = toga.Label( - f'{self._name_team2}: {self._score_team2}', - margin=(0, 5), - color=BLUE, - font_weight='bold', - font_size=24, - ) - separator_label = toga.Label('', flex=1) - score_box = toga.Box( - direction=ROW, - margin=5, - children=[self._score_label1, separator_label, self._score_label2], - ) - - self._button_team1 = toga.Button( - f'{self._name_team1} (+1)', - on_press=self.cb_score_team1, - background_color=RED, - flex=1, - font_size=18, - color=WHITE, - ) - self._button_team2 = toga.Button( - f'{self._name_team2} (+1)', - on_press=self.cb_score_team2, - background_color=BLUE, - flex=1, - font_size=18, - color=WHITE, - ) - button_box = toga.Box( - direction=COLUMN, - children=[self._button_team1, self._button_team2], - margin=(20, 5, 0), - ) - - self.main_window.content = toga.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) + self._draw_main_view() scoreboard_group = toga.Group('Scoreboard') command_clear = toga.Command( @@ -109,12 +61,10 @@ class ScoreCounter(toga.App): self._name_team1 = self._input_team1.value self._name_team2 = self._input_team2.value self.refresh() - self._settings_window.close() + self._draw_main_view() 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, @@ -138,11 +88,10 @@ class ScoreCounter(toga.App): ], ) - self._settings_window.content = toga.Box( + self.main_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""" @@ -151,6 +100,58 @@ class ScoreCounter(toga.App): self._score_label1.text = f'{self._name_team1}: {self._score_team1}' self._score_label2.text = f'{self._name_team2}: {self._score_team2}' + def _draw_main_view(self): + """Draws the main view in the main window""" + self._score_label1 = toga.Label( + f'{self._name_team1}: {self._score_team1}', + margin=(0, 5), + color=RED, + font_weight='bold', + font_size=24, + ) + self._score_label2 = toga.Label( + f'{self._name_team2}: {self._score_team2}', + margin=(0, 5), + color=BLUE, + font_weight='bold', + font_size=24, + ) + separator_label = toga.Label('', flex=1) + score_box = toga.Box( + direction=ROW, + margin=5, + children=[self._score_label1, separator_label, self._score_label2], + ) + + self._button_team1 = toga.Button( + f'{self._name_team1} (+1)', + on_press=self.cb_score_team1, + background_color=RED, + flex=1, + font_size=18, + color=WHITE, + ) + self._button_team2 = toga.Button( + f'{self._name_team2} (+1)', + on_press=self.cb_score_team2, + background_color=BLUE, + flex=1, + font_size=18, + color=WHITE, + ) + button_box = toga.Box( + direction=COLUMN, + children=[self._button_team1, self._button_team2], + margin=(20, 5, 0), + ) + + self.main_window.content = toga.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) + def main(): """main entry point""" -- cgit v1.3