forked from andreaGaudino/Lab04
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview.py
83 lines (71 loc) · 3.48 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import flet as ft
import controller as ct
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
#Riga 1
self._menuLingua = ft.Dropdown(width=200,label="Scegli una Lingua",
options=[ft.dropdown.Option("italian"),
ft.dropdown.Option("english"),
ft.dropdown.Option("spanish")],
)
row1 = ft.Row([self._menuLingua])
#Riga 2
self._tipoRicerca = ft.Dropdown(width=150, label="Tipo di ricerca", options=[
ft.dropdown.Option("Default"),
ft.dropdown.Option("Linear"),
ft.dropdown.Option("Dichotomic")])
self._testoUtente = ft.TextField(label="Inserisci il testo", width=500)
#self._stampa = ft.ListView(expand=1, spacing=10, padding=20, auto_scroll=True)
self._correzione = ft.ElevatedButton("Avvia correzione", width=200, on_click=self.__controller.handleSentence)
row2 = ft.Row([self._tipoRicerca, self._testoUtente, self._correzione])
self.page.add(row1, row2)
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()
""""def handle_sentence(self):
tupla = self.__controller.handleSentence(self._testoUtente.value, self._menuLingua.value, self._tipoRicerca.value)
self._stampa = ft.ListView(expand=1, spacing=10, padding=20, auto_scroll=True)
self._stampa.controls.append(ft.Text(f"Frase inserita: {self._testoUtente.value}"))
self._stampa.controls.append(ft.Text(f"Parole errate: {tupla}"))
self._stampa.controls.append(ft.Text(f"Tempo richiesto per la ricerca: {tupla}"))
row3 = ft.Row([self._stampa])
"""""