1
1
import flet as ft
2
2
import os
3
3
import services .lectura_fichero as lf
4
+ import services .analizador_lexico .lexico as al
5
+
4
6
class vista :
5
7
def __init__ (self ,page :ft .Page ) -> None :
6
8
self .page = page
7
9
# self.text = ft.TextField(width=200,height=200,multiline=True)
8
10
# self.table = ft.DataTable(columns=[ft.Text("1"),ft.Text("2")])
11
+ #ventanas emergentes:
12
+ self .pick_files_dialog = ft .FilePicker (on_result = self .pick_files_result )
13
+ self .selected_files = ft .Text ("hola" )
9
14
#Botones :
10
15
self .btn_dec_asig = ft .ElevatedButton (text = "Declaración y asignación" ,width = 250 ,on_click = self .action_btn_dec_asig )
11
16
self .btn_io = ft .ElevatedButton ("IO" ,width = 250 ,on_click = self .action_btn_io )
12
17
self .btn_lexico = ft .ElevatedButton ("Analisis Lexico" ,width = 250 ,on_click = self .action_analisis_lexico )
13
18
self .btn_borrar = ft .ElevatedButton ("Borrar" ,width = 250 ,on_click = self .action_borrar )
14
- self .btn_archivo = ft .ElevatedButton ("Cargar archivo" ,width = 250 ,on_click = self .action_carga_archivo )
19
+ self .btn_archivo = ft .ElevatedButton ("Cargar archivo" ,width = 250 ,icon = ft . icons . UPLOAD_FILE , on_click = lambda _ : self .pick_files_dialog . pick_files ( allow_multiple = False ) )
15
20
16
21
17
22
#TextAreas
@@ -67,25 +72,41 @@ def main(self) -> None:
67
72
)
68
73
)
69
74
self .page .title = "Analizador lexico"
75
+ self .page .overlay .append (self .pick_files_dialog )
76
+ self .page .add (self .selected_files )
70
77
self .page .update ()
71
-
78
+
72
79
#funciones de eventos ----------------------------------------------------------
73
-
80
+ def pick_files_result (self ,e : ft .FilePickerResultEvent ):
81
+ nuevo_archivo = ("" .join (map (lambda f : f .path ,e .files )) if e .files else "No hay archivo" )
82
+ self .action_carga_archivo (nuevo_archivo )
83
+
74
84
def action_btn_dec_asig (self ,e )-> None :
75
- res = lf .leer_fichero ("src/resources/prueba2.txt " )
85
+ res = lf .leer_fichero ("src/resources/prueba.java " )
76
86
self .text_input .value = res
77
87
self .page .update ()
88
+
78
89
def action_btn_io (self ,e )-> None :
90
+ res = lf .leer_fichero ("src/resources/prueba2.java" )
91
+ self .text_input .value = res
92
+ self .page .update ()
79
93
print ("IO" )
80
94
81
95
def action_analisis_lexico (self ,e )-> None :
82
96
print ("analisis lexico" )
97
+ self .text_output .value = al .analizador_lexico (self .text_input .value )
98
+ self .page .update ()
83
99
84
100
def action_borrar (self ,e )-> None :
101
+ self .text_input .value = ""
102
+ self .text_output .value = ""
103
+ self .page .update ()
85
104
print ("borrar" )
86
105
87
- def action_carga_archivo (self ,e )-> None :
106
+ def action_carga_archivo (self ,path : str )-> None :
88
107
print ("carga archivo" )
108
+ self .text_input .value = lf .leer_fichero (path )
109
+ self .page .update ()
89
110
#fin fucniones de eventos ------------------------------------------------------------
90
111
91
112
0 commit comments