Skip to content

Commit b1b4053

Browse files
Merge pull request #27 from Retro-I/updates-button
Updates button
2 parents 0da9dcb + 7b04acc commit b1b4053

32 files changed

+421
-96
lines changed

components/NavigationBar.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,16 @@ def get_destinations(self):
3232
destinations = [
3333
ft.NavigationDestination(
3434
label="Radiosender",
35-
icon_content=ft.Icon(ft.icons.RADIO_OUTLINED, size=ICON_SIZE, color=self.icon_color),
35+
icon_content=ft.Icon(
36+
ft.icons.RADIO_OUTLINED, size=ICON_SIZE, color=self.icon_color
37+
),
3638
selected_icon_content=ft.Icon(ft.icons.RADIO, size=ICON_SIZE),
3739
),
3840
ft.NavigationDestination(
3941
label="Bluetooth",
40-
icon_content=ft.Icon(ft.icons.BLUETOOTH_OUTLINED, size=ICON_SIZE, color=self.icon_color),
42+
icon_content=ft.Icon(
43+
ft.icons.BLUETOOTH_OUTLINED, size=ICON_SIZE, color=self.icon_color
44+
),
4145
selected_icon_content=ft.Icon(ft.icons.BLUETOOTH, size=ICON_SIZE),
4246
),
4347
]
@@ -58,7 +62,9 @@ def get_destinations(self):
5862
destinations.append(
5963
ft.NavigationDestination(
6064
label="Einstellungen",
61-
icon_content=ft.Icon(ft.icons.SETTINGS_OUTLINED, size=ICON_SIZE, color=self.icon_color),
65+
icon_content=ft.Icon(
66+
ft.icons.SETTINGS_OUTLINED, size=ICON_SIZE, color=self.icon_color
67+
),
6268
selected_icon_content=ft.Icon(ft.icons.SETTINGS, size=ICON_SIZE),
6369
)
6470
)

components/RadioGrid.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,13 @@ def reload(self):
7272
),
7373
ft.Container(
7474
ref=Constants.indicator_refs[i],
75-
on_click=lambda e: self.stop_radio_station(self.on_theme_stop_radio_station),
75+
on_click=lambda e: self.stop_radio_station(
76+
self.on_theme_stop_radio_station
77+
),
7678
visible=False,
77-
content=ft.Image(src=f"{constants.pwd()}/assets/party.gif", opacity=0.7),
79+
content=ft.Image(
80+
src=f"{constants.pwd()}/assets/party.gif", opacity=0.7
81+
),
7882
),
7983
],
8084
)

components/dialogs/DownloadDialog.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,29 @@
22

33

44
class DownloadDialog(ft.AlertDialog):
5-
text = ft.TextSpan("", style=ft.TextStyle(weight=ft.FontWeight.BOLD))
5+
text = ft.TextSpan("", style=ft.TextStyle(weight=ft.FontWeight.BOLD, size=16))
66

77
def __init__(self):
88
super().__init__()
99

10-
self.title = ft.Text(
11-
spans=[ft.TextSpan("Update für Version "), self.text, ft.TextSpan(" werden heruntergeladen...")]
10+
self.content = ft.Column(
11+
[
12+
ft.ProgressRing(),
13+
ft.Text(
14+
spans=[
15+
ft.TextSpan("Updates für Version ", style=ft.TextStyle(size=16)),
16+
self.text,
17+
ft.TextSpan(" werden heruntergeladen...", style=ft.TextStyle(size=16)),
18+
],
19+
),
20+
],
21+
horizontal_alignment=ft.CrossAxisAlignment.CENTER,
22+
tight=True,
1223
)
1324
self.modal = True
1425

1526
def open_dialog(self, revision):
16-
self.text.value = revision
27+
self.text.text = revision
1728
self.text.update()
1829
self.open = True
1930
self.update()

components/dialogs/ErrorDialog.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,25 @@
33

44
class ErrorDialog(ft.AlertDialog):
55
text = ft.Text("")
6+
display_icon = ft.Icon(ft.icons.ERROR, size=36, visible=False)
67

78
def __init__(self):
89
super().__init__()
910

1011
self.title = ft.Text("Ein Fehler ist aufgetreten!")
11-
self.content = self.text
12+
self.content = ft.Column(
13+
[self.display_icon, self.text],
14+
horizontal_alignment=ft.CrossAxisAlignment.CENTER,
15+
tight=True,
16+
)
1217
self.modal = True
1318
self.actions = [ft.FilledButton("Ok", on_click=lambda e: self.close_dialog())]
1419
self.actions_alignment = ft.MainAxisAlignment.END
1520

16-
def open_dialog(self, msg):
21+
def open_dialog(self, msg: str, show_icon: bool = False):
22+
self.display_icon.visible = show_icon
23+
self.display_icon.update()
24+
1725
self.text.value = msg
1826
self.text.update()
1927
self.open = True
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import flet as ft
2+
3+
from helper.SystemHelper import SystemHelper
4+
5+
system_helper = SystemHelper()
6+
7+
8+
class SettingsAppControlDialog(ft.AlertDialog):
9+
def __init__(self):
10+
super().__init__()
11+
12+
self.content = ft.Column(
13+
alignment=ft.MainAxisAlignment.CENTER,
14+
width=500,
15+
tight=True,
16+
controls=[
17+
ft.Row(
18+
alignment=ft.MainAxisAlignment.CENTER,
19+
spacing=75,
20+
controls=[
21+
ft.Column(
22+
[
23+
ft.IconButton(
24+
ft.icons.HIGHLIGHT_OFF,
25+
icon_size=75,
26+
on_click=lambda e: system_helper.stop_app(),
27+
),
28+
ft.Text(
29+
"App beenden",
30+
text_align=ft.TextAlign.CENTER,
31+
style=ft.TextStyle(size=18),
32+
),
33+
],
34+
alignment=ft.MainAxisAlignment.CENTER,
35+
),
36+
ft.Column(
37+
[
38+
ft.IconButton(
39+
ft.icons.REFRESH,
40+
icon_size=75,
41+
on_click=lambda e: system_helper.restart_app(),
42+
),
43+
ft.Text(
44+
"App neustarten",
45+
text_align=ft.TextAlign.CENTER,
46+
style=ft.TextStyle(size=18),
47+
),
48+
],
49+
alignment=ft.MainAxisAlignment.CENTER,
50+
),
51+
],
52+
),
53+
],
54+
)
55+
56+
def open_dialog(self):
57+
self.open = True
58+
self.update()

components/dialogs/SettingsInfoDialog.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import flet as ft
22

3+
from helper.RevisionHelper import RevisionHelper
34
from helper.SystemHelper import SystemHelper
45

56
system_helper = SystemHelper()
7+
revision_helper = RevisionHelper()
68

79

810
class SettingsInfoDialog(ft.AlertDialog):
11+
version_text = ft.TextSpan("")
912
cpu_temp_text = ft.TextSpan("")
1013
ssid_text = ft.TextSpan("")
1114
ip_text = ft.TextSpan("")
@@ -24,7 +27,11 @@ def __init__(self):
2427
controls=[
2528
ft.ListView(
2629
controls=[
27-
ft.Text("Allgemein", weight=ft.FontWeight.BOLD, size=28),
30+
ft.Text("System", weight=ft.FontWeight.BOLD, size=28),
31+
ft.Text(
32+
spans=[ft.TextSpan("Version: "), self.version_text],
33+
size=20,
34+
),
2835
ft.Text(
2936
spans=[
3037
ft.TextSpan("Datum: "),
@@ -64,8 +71,12 @@ def __init__(self):
6471
)
6572

6673
def open_dialog(self):
74+
self.version_text.text = revision_helper.get_current_revision()
75+
self.version_text.update()
76+
6777
self.cpu_temp_text.text = system_helper.get_cpu_temp()
6878
self.cpu_temp_text.update()
79+
6980
self.update_ip_config()
7081
self.open = True
7182
self.update()

components/dialogs/SettingsShutdownDialog.py

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ def __init__(self):
2323
ft.IconButton(
2424
ft.icons.LOGOUT,
2525
icon_size=75,
26-
on_click=system_helper.shutdown_system,
26+
on_click=lambda e: system_helper.shutdown_system(),
2727
),
2828
ft.Text(
29-
"Ausschalten",
29+
"Herunterfahren",
3030
text_align=ft.TextAlign.CENTER,
31-
style=ft.TextStyle(size=16),
31+
style=ft.TextStyle(size=18),
3232
),
3333
],
3434
alignment=ft.MainAxisAlignment.CENTER,
@@ -38,33 +38,18 @@ def __init__(self):
3838
ft.IconButton(
3939
ft.icons.RESTART_ALT,
4040
icon_size=75,
41-
on_click=system_helper.restart_system,
41+
on_click=lambda e: system_helper.restart_system(),
4242
),
4343
ft.Text(
4444
"Neustarten",
4545
text_align=ft.TextAlign.CENTER,
46-
style=ft.TextStyle(size=16),
47-
),
48-
],
49-
alignment=ft.MainAxisAlignment.CENTER,
50-
),
51-
ft.Column(
52-
[
53-
ft.IconButton(
54-
ft.icons.HIGHLIGHT_OFF,
55-
icon_size=75,
56-
on_click=system_helper.stop_app,
57-
),
58-
ft.Text(
59-
"App beenden",
60-
text_align=ft.TextAlign.CENTER,
61-
style=ft.TextStyle(size=16),
46+
style=ft.TextStyle(size=18),
6247
),
6348
],
6449
alignment=ft.MainAxisAlignment.CENTER,
6550
),
6651
],
67-
)
52+
),
6853
],
6954
)
7055

components/dialogs/SettingsUpdateDialog.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import subprocess
2-
from enum import Enum
32

43
import flet as ft
54

65
from components.dialogs.DownloadDialog import DownloadDialog
76
from components.dialogs.ErrorDialog import ErrorDialog
7+
from components.dialogs.SuccessDialog import SuccessDialog
88
from helper.PageState import PageState
99
from helper.RevisionHelper import RevisionHelper
1010
from helper.SystemHelper import SystemHelper
@@ -13,27 +13,26 @@
1313
revision_helper = RevisionHelper()
1414

1515

16-
class RevisionType(Enum):
17-
BRANCH = "BRANCH"
18-
TAG = "TAG"
19-
20-
2116
class SettingsUpdateDialog(ft.AlertDialog):
2217
branches_list = ft.ListView()
2318
tags_list = ft.ListView()
2419

20+
curr_revision_span = ft.TextSpan("", style=ft.TextStyle(weight=ft.FontWeight.BOLD))
21+
2522
def __init__(self):
2623
super().__init__()
2724
self.download_dialog = DownloadDialog()
2825
self.error_dialog = ErrorDialog()
26+
self.success_dialog = SuccessDialog()
2927

3028
PageState.page.add(self.download_dialog)
3129
PageState.page.add(self.error_dialog)
30+
PageState.page.add(self.success_dialog)
3231

3332
self.title = ft.Text(
3433
spans=[
3534
ft.TextSpan("Aktueller Stand: "),
36-
ft.TextSpan(self.get_current_revision(), style=ft.TextStyle(weight=ft.FontWeight.BOLD)),
35+
self.curr_revision_span,
3736
]
3837
)
3938
self.content = ft.Column(
@@ -62,56 +61,58 @@ def __init__(self):
6261
def open_dialog(self):
6362
self.fill_branches_list()
6463
self.fill_tags_list()
64+
self.curr_revision_span.text = self._get_current_revision()
65+
self.curr_revision_span.update()
6566
self.open = True
6667
self.update()
6768

6869
def fill_branches_list(self):
6970
branches = revision_helper.get_branches()
7071

7172
self.branches_list.controls.clear()
72-
self.branches_list.controls = self._get_items(branches, RevisionType.BRANCH)
73+
self.branches_list.controls = self._get_items(branches)
7374
self.branches_list.update()
7475

7576
def fill_tags_list(self):
7677
tags = revision_helper.get_tags()
7778

7879
self.tags_list.controls.clear()
79-
self.tags_list.controls = self._get_items(tags, RevisionType.TAG)
80+
self.tags_list.controls = self._get_items(tags)
8081
self.tags_list.update()
8182

82-
def _get_items(self, revisions: list[str], revision_type: RevisionType):
83+
def _get_items(self, revisions: list[str]):
8384
return [
8485
ft.TextButton(
8586
content=ft.Container(
8687
content=ft.Row(
8788
[
88-
ft.Icon(ft.icons.DONE, visible=(r == self.get_current_revision())),
89+
ft.Icon(
90+
ft.icons.DONE,
91+
visible=(r == self._get_current_revision()),
92+
),
8993
ft.Text(r, size=18),
9094
],
9195
),
9296
),
93-
on_click=lambda e, revision=r: self.on_revision_click(revision, revision_type),
97+
on_click=lambda e, revision=r: self.on_revision_click(revision),
9498
)
9599
for r in revisions
96100
]
97101

98-
def on_revision_click(self, revision, revision_type):
102+
def on_revision_click(self, revision):
99103
self.download_dialog.open_dialog(revision)
100104
try:
101-
result = subprocess.run(
102-
["bash", "scripts/update_project.sh", revision],
103-
capture_output=True,
104-
text=True,
105-
check=True,
105+
system_helper.change_revision(revision)
106+
self.success_dialog.open_dialog(
107+
"Updates", f'Updates für "{revision}" erfolgreich heruntergeladen!', show_icon=True
106108
)
107-
print("✅ Script output:\n", result.stdout)
108109
except subprocess.CalledProcessError as e:
109110
print("Script failed!")
110111
print("Exit code:", e.returncode)
111112
print("STDOUT:\n", e.stdout)
112113
print("STDERR:\n", e.stderr)
113-
self.error_dialog.open_dialog(e.stderr)
114+
self.error_dialog.open_dialog(e.stderr, show_icon=True)
114115
self.download_dialog.close_dialog()
115116

116-
def get_current_revision(self):
117+
def _get_current_revision(self):
117118
return revision_helper.get_current_revision()

components/dialogs/SoundDeleteDialog.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ def submit(self):
1919
self.close()
2020

2121
def open_dialog(self, submit_callback):
22-
self.open = True # TODO - test with "self.open(True)" or remove function
22+
self.open = True
2323
self.submit_callback = submit_callback
2424
self.update()
2525

2626
def close(self):
27-
self.open = False # TODO - test with "self.open(False)" or remove function
27+
self.open = False
2828
self.update()

0 commit comments

Comments
 (0)