@@ -46,6 +46,15 @@ def startup(self):
46
46
#switchs
47
47
self .switchdio = toga .Switch ('DIO' , is_on = False , style = Pack (padding_left = 10 ,padding_top = 5 ))
48
48
49
+ #textinputs
50
+ self .textfile = toga .TextInput (style = Pack (flex = 1 ,width = 200 ))
51
+
52
+ #intento de terminal
53
+ self .textterminal = toga .MultilineTextInput (readonly = False ,style = Pack (flex = 1 ,width = 600 ,height = 600 ))
54
+
55
+ #textoutputs
56
+ self .textoutputs = toga .MultilineTextInput (readonly = True ,style = Pack (flex = 1 ,width = 200 ,height = 200 ))
57
+
49
58
self .filelabel = toga .Label ("No ha seleccionado ningun archivo" , style = Pack (padding = 2 ))
50
59
self .fname = None
51
60
self .main_window .content = toga .Box (
@@ -60,28 +69,84 @@ def startup(self):
60
69
]),
61
70
62
71
toga .Box (style = Pack (direction = COLUMN ,padding_top = 7 ), children = [
63
- toga .Button ("Seleccionar archivo" , on_press = self .action_open_file_dialog , style = Pack (padding_top = 15 ,padding_left = 2 )),
72
+ toga .Button ("Ver archivos en ESP" , on_press = self .read_files , style = Pack (padding_top = 15 ,padding_left = 2 )),
73
+ toga .Button ("Seleccionar archivo" , on_press = self .action_open_file_dialog , style = Pack (padding = 2 )),
64
74
self .filelabel ,
65
- toga .Button ("Grabar archivo en ESP" , on_press = self .save_to_esp , style = Pack (padding = 2 ))
75
+ toga .Button ("Ejecutar archivo en ESP" , on_press = self .run_in_esp , style = Pack (padding = 2 )),
76
+ toga .Button ("Grabar archivo en ESP" , on_press = self .save_to_esp , style = Pack (padding = 2 )),
77
+ self .textfile ,
78
+ toga .Button ("Borrar archivo de ESP" , on_press = self .erase_from_esp , style = Pack (padding = 2 )),
79
+ toga .Button ("Obtener archivo de ESP" , on_press = self .get_file_esp , style = Pack (padding = 2 )),
80
+ self .textoutputs
66
81
])
67
82
]),
68
- toga .Box (style = box_style_verti , children = [
69
- toga .Button ("Flashear" ,on_press = self .flash ),
83
+ toga .Box (style = box_style_verti , children =
84
+ [ toga .Button ("Flashear" ,on_press = self .flash ),
70
85
toga .Button ("Borrar flash/firmware" ,on_press = self .eraseflash ),
71
- toga .Button ("Actualizar puertos" ,on_press = self .update_ports )
86
+ toga .Button ("Actualizar puertos" ,on_press = self .update_ports ),
87
+ self .textterminal
72
88
])
73
89
])
74
90
75
91
self .main_window .show ()
76
92
93
+ #metodos para la parte de ampy
94
+ def read_files (self ,button ):
95
+ from uPy_IDE .pyboard import Pyboard
96
+ from uPy_IDE import cli
97
+ from uPy_IDE import files
98
+
99
+ eboard = files .Files (Pyboard (self .portselect .value ))
100
+ filesesp = eboard .ls ()
101
+ print (filesesp )
102
+ lstext = ""
103
+ for f in filesesp :
104
+ lstext = lstext + f + "\n "
105
+ self .textoutputs .clear
106
+ self .textoutputs .value = lstext
107
+
108
+ def action_open_file_dialog (self , widget ):
109
+ try :
110
+ self .fname = self .main_window .open_file_dialog (
111
+ title = "Open file with Toga" ,
112
+ )
113
+ print (self .fname )
114
+ except ValueError :
115
+ print ("ha ocurrido un error" )
116
+ self .filelabel .text = "Archivo seleccionado: " + self .fname .split ("/" )[- 1 ]
117
+
118
+ def run_in_esp_thread (self , archiv , disp , terp ):
119
+ import uPy_IDE .pyboard as pyboard
120
+ self .textterminal .clear ()
121
+ pyboard .execfile (archiv , device = disp ,terminal = terp )
122
+
123
+ def run_in_esp (self ,button ):
124
+ import threading
125
+ runespthread = threading .Thread (target = self .run_in_esp_thread , args = (self .fname , self .portselect .value , self .textterminal ))
126
+ runespthread .start ()
77
127
78
128
def save_to_esp (self , button ):
79
129
from uPy_IDE .pyboard import Pyboard
80
130
from uPy_IDE import cli
81
131
eboard = Pyboard (self .portselect .value )
82
132
cli .put (self .fname ,board = eboard )
83
133
134
+ def erase_from_esp (self ,button ):
135
+ from uPy_IDE .pyboard import Pyboard
136
+ import uPy_IDE .files as files
137
+ eboard = files .Files (Pyboard (self .portselect .value ))
138
+ eboard .rm (self .textfile .value )
139
+
140
+ def get_file_esp (self ,button ):
141
+ from uPy_IDE .pyboard import Pyboard
142
+ import uPy_IDE .files as files
143
+ eboard = files .Files (Pyboard (self .portselect .value ))
144
+ fdata = eboard .get (self .textfile .value )
145
+ self .textterminal .clear ()
146
+ self .textterminal .value = fdata
84
147
148
+
149
+ #metodos para la parte de esptool
85
150
def flash (self ,button ):
86
151
port = self .portselect .value
87
152
chip = self .chipselect .value
@@ -90,7 +155,7 @@ def flash(self,button):
90
155
if chip == "ESP32" :
91
156
esptool .main (["--chip" ,"esp32" ,"--port" ,self .portselect .value ,"write_flash" ,"-z" ,"0x1000" ,"esp32/" + ver + '.bin' ])
92
157
elif chip == "ESP8266" :
93
- if self .switchdio .get_is_on :
158
+ if self .switchdio .is_on :
94
159
esptool .main (["--port" ,self .portselect .value ,"--baud" ,"460800" ,"write_flash" ,"--flash_size=detect" ,"0" ,"uPy_IDE/esp8266/" + ver + '.bin' ])
95
160
else :
96
161
esptool .main (["--port" ,self .portselect .value ,"--baud" ,"460800" ,"write_flash" ,"--flash_size=detect" ,"-fm" ,"dio" ,"0" ,"uPy_IDE/esp8266/" + ver + '.bin' ])
@@ -122,15 +187,5 @@ def eraseflash(self,button):
122
187
elif chip == 'ESP8266' :
123
188
esptool .main (["-p" ,self .portselect .value ,"erase_flash" ])
124
189
125
- def action_open_file_dialog (self , widget ):
126
- try :
127
- self .fname = self .main_window .open_file_dialog (
128
- title = "Open file with Toga" ,
129
- )
130
- print (self .fname )
131
- except ValueError :
132
- print ("ha ocurrido un error" )
133
- self .filelabel .text = "Archivo seleccionado: " + self .fname .split ("/" )[- 1 ]
134
-
135
190
def main ():
136
191
return uPyIDE ("uPyIDE" ,"org.funpython.upyide" )
0 commit comments