summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG2
-rw-r--r--src/scorecounter/app.py84
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 @@
1# scorecounter Release Notes 1# scorecounter Release Notes
2 2
3## 0.0.1 (22 Dec 2025) 3## 1.0.0 (23 Dec 2025)
4 4
5* Initial release 5* 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 @@
1"""Simple score counter for two teams""" 1"""Simple score counter for two teams"""
2 2
3import toga 3import toga
4from toga.colors import BLUE, RED, WHITE
4from toga.constants import COLUMN, ROW 5from toga.constants import COLUMN, ROW
5 6
6 7
@@ -12,21 +13,24 @@ class ScoreCounter(toga.App):
12 self._score_team1 = 0 13 self._score_team1 = 0
13 self._score_team2 = 0 14 self._score_team2 = 0
14 15
16 self._name_team1 = 'Team 1'
17 self._name_team2 = 'Team 2'
18
15 self.main_window = toga.MainWindow( 19 self.main_window = toga.MainWindow(
16 title=self.formal_name, on_resize=self.cb_main_window_resize 20 title=self.formal_name, on_resize=self.cb_main_window_resize
17 ) 21 )
18 22
19 self._score_label1 = toga.Label( 23 self._score_label1 = toga.Label(
20 f'Team1: {self._score_team1}', 24 f'{self._name_team1}: {self._score_team1}',
21 margin=(0, 5), 25 margin=(0, 5),
22 color='red', 26 color=RED,
23 font_weight='bold', 27 font_weight='bold',
24 font_size=24, 28 font_size=24,
25 ) 29 )
26 self._score_label2 = toga.Label( 30 self._score_label2 = toga.Label(
27 f'Team2: {self._score_team2}', 31 f'{self._name_team2}: {self._score_team2}',
28 margin=(0, 5), 32 margin=(0, 5),
29 color='blue', 33 color=BLUE,
30 font_weight='bold', 34 font_weight='bold',
31 font_size=24, 35 font_size=24,
32 ) 36 )
@@ -37,24 +41,21 @@ class ScoreCounter(toga.App):
37 children=[self._score_label1, separator_label, self._score_label2], 41 children=[self._score_label1, separator_label, self._score_label2],
38 ) 42 )
39 43
40 # empty box for consuming vertical space
41 empty_box = toga.Box(flex=1)
42
43 self._button_team1 = toga.Button( 44 self._button_team1 = toga.Button(
44 'Team 1 (+1)', 45 f'{self._name_team1} (+1)',
45 on_press=self.cb_score_team1, 46 on_press=self.cb_score_team1,
46 background_color='red', 47 background_color=RED,
47 flex=1, 48 flex=1,
48 font_size=18, 49 font_size=18,
49 color='white', 50 color=WHITE,
50 ) 51 )
51 self._button_team2 = toga.Button( 52 self._button_team2 = toga.Button(
52 'Team 2 (+1)', 53 f'{self._name_team2} (+1)',
53 on_press=self.cb_score_team2, 54 on_press=self.cb_score_team2,
54 background_color='blue', 55 background_color=BLUE,
55 flex=1, 56 flex=1,
56 font_size=18, 57 font_size=18,
57 color='white', 58 color=WHITE,
58 ) 59 )
59 button_box = toga.Box( 60 button_box = toga.Box(
60 direction=COLUMN, 61 direction=COLUMN,
@@ -63,16 +64,23 @@ class ScoreCounter(toga.App):
63 ) 64 )
64 65
65 self.main_window.content = toga.Box( 66 self.main_window.content = toga.Box(
66 direction=COLUMN, children=[score_box, empty_box, button_box] 67 direction=COLUMN,
68 children=[score_box, toga.Box(flex=1), button_box],
67 ) 69 )
68 self._button_team1.style.height = int(self.main_window.size.height / 5) 70 self._button_team1.style.height = int(self.main_window.size.height / 5)
69 self._button_team2.style.height = int(self.main_window.size.height / 5) 71 self._button_team2.style.height = int(self.main_window.size.height / 5)
70 72
73 scoreboard_group = toga.Group('Scoreboard')
71 command_clear = toga.Command( 74 command_clear = toga.Command(
72 self.cb_clear, text='Clear', group=toga.Group('Scoreboard') 75 self.cb_clear, text='Clear', group=scoreboard_group
73 ) 76 )
74 self.commands.add(command_clear) 77 self.commands.add(command_clear)
75 78
79 command_settings = toga.Command(
80 self.cb_settings, text='Settings', group=scoreboard_group
81 )
82 self.commands.add(command_settings)
83
76 self.main_window.show() 84 self.main_window.show()
77 85
78 def cb_clear(self, _widget): 86 def cb_clear(self, _widget):
@@ -96,10 +104,52 @@ class ScoreCounter(toga.App):
96 self._button_team1.style.height = int(widget.size.height / 5) 104 self._button_team1.style.height = int(widget.size.height / 5)
97 self._button_team2.style.height = int(widget.size.height / 5) 105 self._button_team2.style.height = int(widget.size.height / 5)
98 106
107 def cb_set(self, _widget):
108 """Set the settings callback"""
109 self._name_team1 = self._input_team1.value
110 self._name_team2 = self._input_team2.value
111 self.refresh()
112 self._settings_window.close()
113
114 def cb_settings(self, _widget):
115 """Create settings window menu"""
116 self._settings_window = toga.Window()
117
118 self._input_team1 = toga.TextInput(flex=1, value=self._name_team1)
119 box_team1 = toga.Box(
120 direction=ROW,
121 margin=5,
122 children=[toga.Label('Team 1:', margin=5), self._input_team1],
123 )
124
125 self._input_team2 = toga.TextInput(flex=1, value=self._name_team2)
126 box_team2 = toga.Box(
127 direction=ROW,
128 margin=5,
129 children=[toga.Label('Team 2:', margin=5), self._input_team2],
130 )
131
132 button_box = toga.Box(
133 direction=ROW,
134 children=[
135 toga.Label('', flex=1),
136 toga.Button('Set', on_press=self.cb_set),
137 toga.Label('', flex=1),
138 ],
139 )
140
141 self._settings_window.content = toga.Box(
142 direction=COLUMN,
143 children=[box_team1, box_team2, toga.Box(flex=1), button_box],
144 )
145 self._settings_window.show()
146
99 def refresh(self): 147 def refresh(self):
100 """Refreshes the score labels""" 148 """Refreshes the score labels"""
101 self._score_label1.text = f'Team1: {self._score_team1}' 149 self._button_team1.text = f'{self._name_team1} (+1)'
102 self._score_label2.text = f'Team2: {self._score_team2}' 150 self._button_team2.text = f'{self._name_team2} (+1)'
151 self._score_label1.text = f'{self._name_team1}: {self._score_team1}'
152 self._score_label2.text = f'{self._name_team2}: {self._score_team2}'
103 153
104 154
105def main(): 155def main():