1
- import toga
2
- from toga .style import Pack
3
- from toga .constants import COLUMN , ROW
1
+ import glob
4
2
import os
5
3
import sys
6
- import glob
7
- import serial
8
4
import time
5
+
6
+ import serial
7
+ import toga
9
8
import uPy_IDE .esptool as esptool
9
+ from toga .constants import COLUMN , ROW
10
+ from toga .style .pack import *
11
+
12
+ # TODO: Exportar un ejecutable de Windows
13
+
14
+ # Correr en un proceso aparte para que no se congele la UI
15
+ def run_in_process (self , button , code_to_run ):
16
+ import timeit
17
+ elapsed_time = timeit .timeit (code_to_run , number = 1 ) # just to save it somewhere
18
+ return elapsed_time
19
+
10
20
11
21
def serial_ports ():
12
22
if sys .platform .startswith ('win' ):
@@ -55,29 +65,23 @@ def startup(self):
55
65
self .commandesp = toga .TextInput (style = Pack (flex = 1 ,width = 450 ))
56
66
57
67
#intento de terminal
58
- self .textterminal = toga .MultilineTextInput (readonly = False , style = Pack ( flex = 1 , width = 600 , height = 600 ) )
68
+ self .textterminal = toga .MultilineTextInput (id = 'terminal' )
59
69
60
70
#textoutputs
61
- self .textoutputs = toga .MultilineTextInput (readonly = True ,style = Pack (flex = 1 ,width = 200 ,height = 200 ))
62
-
63
- #botones
64
- self .btnport = toga .Button ("Abrir puerto" , on_press = self .open_port , style = Pack (padding = 2 ))
71
+ self .textoutputs = toga .MultilineTextInput (id = 'output' )
65
72
66
73
67
74
self .filelabel = toga .Label ("No ha seleccionado ningun archivo" , style = Pack (padding = 2 ))
68
75
self .fname = None
69
- self .main_window .content = toga .Box (
70
- children = [
71
- toga .Box (style = box_style_verti , children = [
72
-
73
- toga .Box (style = Pack (direction = ROW ,padding_left = 25 ), children = [
76
+ # definir los hijos del main box afuera del main box
77
+ left_box = toga .Box (style = box_style_verti )
78
+ left_box .add (toga .Box (style = Pack (direction = ROW ,padding_left = 25 ), children = [
74
79
self .portselect ,
75
80
self .chipselect ,
76
81
self .verselect ,
77
82
self .switchdio
78
- ]),
79
-
80
- toga .Box (style = Pack (direction = COLUMN ,padding_top = 7 ), children = [
83
+ ]))
84
+ left_box .add (toga .Box (style = Pack (direction = COLUMN ,padding_top = 7 ), children = [
81
85
toga .Button ("Ver archivos en ESP" , on_press = self .read_files , style = Pack (padding_top = 15 ,padding_left = 2 )),
82
86
toga .Button ("Seleccionar archivo" , on_press = self .action_open_file_dialog , style = Pack (padding = 2 )),
83
87
self .filelabel ,
@@ -87,27 +91,44 @@ def startup(self):
87
91
toga .Button ("Borrar archivo de ESP" , on_press = self .erase_from_esp , style = Pack (padding = 2 )),
88
92
toga .Button ("Obtener archivo de ESP" , on_press = self .get_file_esp , style = Pack (padding = 2 )),
89
93
self .textoutputs
90
- ])
91
- ]),
92
- toga .Box (style = box_style_verti , children = [
93
- toga .Button ("Flashear" ,on_press = self .flash ),
94
- toga .Button ("Borrar flash/firmware" ,on_press = self .eraseflash ),
95
- toga .Button ("Actualizar puertos" ,on_press = self .update_ports ),
96
- self .btnport ,
97
- self .textterminal ,
98
-
99
- toga .Box (style = Pack (direction = ROW ,padding_top = 7 ), children = [
94
+ ]))
95
+
96
+ # Cambio en la estructura de los boxes para que funcione el rendering de los hijos en Windows, el bug es propio de toga al momento de presentar los boxes
97
+ # Agregar hijos de right_box
98
+ # right_box = toga.Box(style=box_style_verti)
99
+ # right_box.add(toga.Button("Flashear",on_press=self.flash, style=Pack(padding=2)))
100
+ # right_box.add(toga.Button("Borrar flash/firmware",on_press=self.eraseflash, style=Pack(padding=2)))
101
+ # right_box.add(toga.Button("Actualizar puertos",on_press=self.update_ports, style=Pack(padding=2)))
102
+ # right_box.add(toga.Button("Abrir puerto", on_press=self.open_port, style=Pack(padding=2)))
103
+ # right_box.add(self.textterminal)
104
+ # right_box.add(toga.Box(style=Pack(direction=ROW,padding_top=7), children=[
105
+ # self.commandesp,
106
+ # toga.Button("Enviar comando", on_press=self.send_command, style=Pack(padding=2))
107
+ # ])
108
+ # )
109
+
110
+ left_box .add (toga .Button ("Flashear" ,on_press = self .flash , style = Pack (padding = 2 )))
111
+ left_box .add (toga .Button ("Borrar flash/firmware" ,on_press = self .eraseflash , style = Pack (padding = 2 )))
112
+ left_box .add (toga .Button ("Actualizar puertos" ,on_press = self .update_ports , style = Pack (padding = 2 )))
113
+ left_box .add (toga .Button ("Abrir puerto" , on_press = self .open_port , style = Pack (padding = 2 )))
114
+ left_box .add (self .textterminal )
115
+ left_box .add (toga .Box (style = Pack (direction = ROW ,padding_top = 7 ), children = [
100
116
self .commandesp ,
101
117
toga .Button ("Enviar comando" , on_press = self .send_command , style = Pack (padding = 2 ))
102
118
])
119
+ )
120
+
121
+ container = toga .Box ()
122
+ container .add (left_box )
123
+ # container.add(right_box)
103
124
104
- ])
105
-
106
- ])
125
+ self .main_window .content = container
107
126
108
127
self .main_window .show ()
109
128
110
- #metodos para la parte de ampy
129
+
130
+ # TODO: hacer que los metodos inernos sean multi-procesos
131
+ # metodos para la parte de ampy
111
132
def read_files (self ,button ):
112
133
from uPy_IDE .pyboard import Pyboard
113
134
from uPy_IDE import cli
@@ -163,7 +184,8 @@ def get_file_esp(self,button):
163
184
self .textterminal .value = fdata
164
185
165
186
#======================================SOLO MANEJO DE PUERTO========================================================
166
-
187
+
188
+
167
189
def open_port (self ,button ):
168
190
from uPy_IDE .pyboard import Pyboard
169
191
if not self .port_open :
@@ -177,6 +199,7 @@ def open_port(self,button):
177
199
self .btnport .label = "Abrir puerto"
178
200
self .port_open = False
179
201
self .port .exit_raw_repl ()
202
+
180
203
181
204
def send_command (self ,button ):
182
205
if self .port_open :
0 commit comments