-
Notifications
You must be signed in to change notification settings - Fork 93
/
view.py
53 lines (46 loc) · 1.83 KB
/
view.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import flet as ft
class View(object):
def __init__(self, page: ft.Page):
# Page
self.page = page
self.page.title = "TdP 2024 - Lab 04 - SpellChecker ++"
self.page.horizontal_alignment = 'CENTER'
self.page.theme_mode = ft.ThemeMode.LIGHT
# Controller
self.__controller = None
# UI elements
self.__title = None
self.__theme_switch = None
# define the UI elements and populate the page
def add_content(self):
"""Function that creates and adds the visual elements to the page. It also updates
the page accordingly."""
# title + theme switch
self.__title = ft.Text("TdP 2024 - Lab 04 - SpellChecker ++", size=24, color="blue")
self.__theme_switch = ft.Switch(label="Light theme", on_change=self.theme_changed)
self.page.controls.append(
ft.Row(spacing=30, controls=[self.__theme_switch, self.__title, ],
alignment=ft.MainAxisAlignment.START)
)
# Add your stuff here
self.page.add([])
self.page.update()
def update(self):
self.page.update()
def setController(self, controller):
self.__controller = controller
def theme_changed(self, e):
"""Function that changes the color theme of the app, when the corresponding
switch is triggered"""
self.page.theme_mode = (
ft.ThemeMode.DARK
if self.page.theme_mode == ft.ThemeMode.LIGHT
else ft.ThemeMode.LIGHT
)
self.__theme_switch.label = (
"Light theme" if self.page.theme_mode == ft.ThemeMode.LIGHT else "Dark theme"
)
# self.__txt_container.bgcolor = (
# ft.colors.GREY_900 if self.page.theme_mode == ft.ThemeMode.DARK else ft.colors.GREY_300
# )
self.page.update()