Skip to content

Commit 2aa5bcc

Browse files
committed
Refactor code, fix dark theme switch, change snack_bar duration
1 parent 088a3ec commit 2aa5bcc

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

main.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,13 @@ def on_pan_update(e: ft.DragUpdateEvent):
115115
page.dark_theme = ft.Theme(color_scheme_seed=settings_values['app_color'])
116116
page.theme = ft.Theme(color_scheme_seed=settings_values['app_color'])
117117

118-
ft.MouseCursor.RESIZE_UP_DOWN
118+
def page_theme():
119+
if settings_values['dark_theme']:
120+
page.theme_mode = ft.ThemeMode.DARK
121+
else:
122+
page.theme_mode = ft.ThemeMode.LIGHT
123+
124+
page_theme()
119125

120126
def save_page_dimensions(e):
121127
try:
@@ -128,16 +134,13 @@ def save_page_dimensions(e):
128134
print(f"Something went wrong with saving page dimensions, {e}")
129135

130136
page.on_resize = save_page_dimensions
131-
page.snack_bar = ft.SnackBar(ft.Text("", ), duration=3000)
137+
page.snack_bar = ft.SnackBar(ft.Text(""))
132138

133139
def update_settings(e):
134140
if cg.value:
135141
settings_values['app_color'] = cg.value
136142
settings_values['dark_theme'] = theme_mode.value
137-
if settings_values['dark_theme']:
138-
page.theme_mode = ft.ThemeMode.DARK
139-
else:
140-
page.theme_mode = ft.ThemeMode.LIGHT
143+
page_theme()
141144
results_container.bgcolor = settings_values['app_color']
142145
printer_wiz_list_container.bgcolor = settings_values['app_color']
143146
page.dark_theme.color_scheme_seed = settings_values['app_color']
@@ -151,7 +154,7 @@ def update_settings(e):
151154
load_settings(e, update=True)
152155
try:
153156
if e.control.text == "Save":
154-
show_message("Settings have been saved.")
157+
show_message("Saved.", duration=700)
155158
except AttributeError:
156159
pass
157160
page.update()
@@ -530,7 +533,12 @@ def are_you_sure(e, text, **kwargs):
530533
close_dynamic_modal(e)
531534
return answer
532535

533-
def show_message(message):
536+
def show_message(message, **kwargs):
537+
duration = 3000
538+
for key, value in kwargs.items():
539+
if key == "duration":
540+
duration = value
541+
page.snack_bar.duration = duration
534542
page.snack_bar.content.value = message
535543
page.snack_bar.open = True
536544
page.update()
@@ -2420,7 +2428,7 @@ def clicked(e):
24202428

24212429
# -------------------- SETTINGS --------------------
24222430
# Settings color choice radio
2423-
app_color_label = ft.Text("App Color:", )
2431+
app_color_label = ft.Text("App appearance:", )
24242432
red_color_radio = ft.Radio(value="red", label="Red", fill_color="red")
24252433
blue_color_radio = ft.Radio(value="blue", label="Blue", fill_color="blue")
24262434
green_color_radio = ft.Radio(value="green", label="Green", fill_color="green")
@@ -2450,7 +2458,7 @@ def clicked(e):
24502458
PowerShell 7, PsTools, and Python's subprocess module to launch built-in custom PowerShell \
24512459
scripts to retrieve the information from remote computers and perform other tasks."], on_click=open_tutorial_modal)
24522460

2453-
theme_mode = ft.Switch(label="Dark Theme", value=True)
2461+
theme_mode = ft.Switch(label="Dark Theme", value=settings_values['dark_theme'])
24542462

24552463
settings_view = ft.Column([
24562464
ft.Row([

0 commit comments

Comments
 (0)