summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/scorecounter/app.py109
1 files 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):
20 title=self.formal_name, on_resize=self.cb_main_window_resize 20 title=self.formal_name, on_resize=self.cb_main_window_resize
21 ) 21 )
22 22
23 self._score_label1 = toga.Label( 23 self._draw_main_view()
24 f'{self._name_team1}: {self._score_team1}',
25 margin=(0, 5),
26 color=RED,
27 font_weight='bold',
28 font_size=24,
29 )
30 self._score_label2 = toga.Label(
31 f'{self._name_team2}: {self._score_team2}',
32 margin=(0, 5),
33 color=BLUE,
34 font_weight='bold',
35 font_size=24,
36 )
37 separator_label = toga.Label('', flex=1)
38 score_box = toga.Box(
39 direction=ROW,
40 margin=5,
41 children=[self._score_label1, separator_label, self._score_label2],
42 )
43
44 self._button_team1 = toga.Button(
45 f'{self._name_team1} (+1)',
46 on_press=self.cb_score_team1,
47 background_color=RED,
48 flex=1,
49 font_size=18,
50 color=WHITE,
51 )
52 self._button_team2 = toga.Button(
53 f'{self._name_team2} (+1)',
54 on_press=self.cb_score_team2,
55 background_color=BLUE,
56 flex=1,
57 font_size=18,
58 color=WHITE,
59 )
60 button_box = toga.Box(
61 direction=COLUMN,
62 children=[self._button_team1, self._button_team2],
63 margin=(20, 5, 0),
64 )
65
66 self.main_window.content = toga.Box(
67 direction=COLUMN,
68 children=[score_box, toga.Box(flex=1), button_box],
69 )
70 self._button_team1.style.height = int(self.main_window.size.height / 5)
71 self._button_team2.style.height = int(self.main_window.size.height / 5)
72 24
73 scoreboard_group = toga.Group('Scoreboard') 25 scoreboard_group = toga.Group('Scoreboard')
74 command_clear = toga.Command( 26 command_clear = toga.Command(
@@ -109,12 +61,10 @@ class ScoreCounter(toga.App):
109 self._name_team1 = self._input_team1.value 61 self._name_team1 = self._input_team1.value
110 self._name_team2 = self._input_team2.value 62 self._name_team2 = self._input_team2.value
111 self.refresh() 63 self.refresh()
112 self._settings_window.close() 64 self._draw_main_view()
113 65
114 def cb_settings(self, _widget): 66 def cb_settings(self, _widget):
115 """Create settings window menu""" 67 """Create settings window menu"""
116 self._settings_window = toga.Window()
117
118 self._input_team1 = toga.TextInput(flex=1, value=self._name_team1) 68 self._input_team1 = toga.TextInput(flex=1, value=self._name_team1)
119 box_team1 = toga.Box( 69 box_team1 = toga.Box(
120 direction=ROW, 70 direction=ROW,
@@ -138,11 +88,10 @@ class ScoreCounter(toga.App):
138 ], 88 ],
139 ) 89 )
140 90
141 self._settings_window.content = toga.Box( 91 self.main_window.content = toga.Box(
142 direction=COLUMN, 92 direction=COLUMN,
143 children=[box_team1, box_team2, toga.Box(flex=1), button_box], 93 children=[box_team1, box_team2, toga.Box(flex=1), button_box],
144 ) 94 )
145 self._settings_window.show()
146 95
147 def refresh(self): 96 def refresh(self):
148 """Refreshes the score labels""" 97 """Refreshes the score labels"""
@@ -151,6 +100,58 @@ class ScoreCounter(toga.App):
151 self._score_label1.text = f'{self._name_team1}: {self._score_team1}' 100 self._score_label1.text = f'{self._name_team1}: {self._score_team1}'
152 self._score_label2.text = f'{self._name_team2}: {self._score_team2}' 101 self._score_label2.text = f'{self._name_team2}: {self._score_team2}'
153 102
103 def _draw_main_view(self):
104 """Draws the main view in the main window"""
105 self._score_label1 = toga.Label(
106 f'{self._name_team1}: {self._score_team1}',
107 margin=(0, 5),
108 color=RED,
109 font_weight='bold',
110 font_size=24,
111 )
112 self._score_label2 = toga.Label(
113 f'{self._name_team2}: {self._score_team2}',
114 margin=(0, 5),
115 color=BLUE,
116 font_weight='bold',
117 font_size=24,
118 )
119 separator_label = toga.Label('', flex=1)
120 score_box = toga.Box(
121 direction=ROW,
122 margin=5,
123 children=[self._score_label1, separator_label, self._score_label2],
124 )
125
126 self._button_team1 = toga.Button(
127 f'{self._name_team1} (+1)',
128 on_press=self.cb_score_team1,
129 background_color=RED,
130 flex=1,
131 font_size=18,
132 color=WHITE,
133 )
134 self._button_team2 = toga.Button(
135 f'{self._name_team2} (+1)',
136 on_press=self.cb_score_team2,
137 background_color=BLUE,
138 flex=1,
139 font_size=18,
140 color=WHITE,
141 )
142 button_box = toga.Box(
143 direction=COLUMN,
144 children=[self._button_team1, self._button_team2],
145 margin=(20, 5, 0),
146 )
147
148 self.main_window.content = toga.Box(
149 direction=COLUMN,
150 children=[score_box, toga.Box(flex=1), button_box],
151 )
152 self._button_team1.style.height = int(self.main_window.size.height / 5)
153 self._button_team2.style.height = int(self.main_window.size.height / 5)
154
154 155
155def main(): 156def main():
156 """main entry point""" 157 """main entry point"""