diff --git a/_sources/lectures/TWP52.rst b/_sources/lectures/TWP52.rst index 7e3e88b6ad..f5ec1d543d 100644 --- a/_sources/lectures/TWP52.rst +++ b/_sources/lectures/TWP52.rst @@ -27,50 +27,37 @@ HEAD-Ex Logística y Transporte HEAD-Ex Logística y Transporte ============================== +.. activecode:: ac_l52_1a + :nocodelens: + :language: python3 + :python3_interpreter: brython -.. code-block :: python + from browser import document, html - - def salvar_dados(): - fileD = open('encomendas.txt','a') - fileD.write('Destino: ') - fileD.write('%s\n' %destino.get()) - fileD.write('Descripcion: ') - fileD.write('%s\n' %descricao.get()) - fileD.write('Habla a: ') - fileD.write('%s\n' %endereco.get('1.0',END)) - destino.delete(0,END) - descricao.delete(0,END) - endereco.delete('1.0',END) + def guardar_datos(evento): + # Agrega tu lógica para guardar datos aquí + print(f"Destino: {destino.value}, Descripción: {descripcion.value}, Hablar a: {direccion.value}") + app = html.DIV() + app <= html.H2('HEAD-Ex Logística y Transporte') + app <= html.LABEL('Destino: ') + destino = html.INPUT() + app <= destino -HEAD-Ex Logística y Transporte -============================== - - -.. code-block :: python - - from tkinter import * - - app = Tk() - app.title('HEAD-Ex Logística y Transporte') - app.geometry("250x180+200+100") + app <= html.LABEL('Descripción: ') + descripcion = html.INPUT() + app <= descripcion - Label(app,text = "Destino: ").pack() - destino = Entry(app) - destino.pack() + app <= html.LABEL('Hablar a: ') + direccion = html.INPUT() + app <= direccion - Label(app,text = "Descripcion: ").pack() - descricao = Entry(app) - descricao.pack() + boton = html.BUTTON('Guardar') + boton.bind('click', guardar_datos) + app <= boton - Label(app,text = "Habla a: ").pack() - endereco = Entry(app) - endereco.pack() - - Button(app, text = "Salvar" , command = salvar_dados).pack() - app.mainloop() + document <= app HEAD-Ex Logística e Transporte @@ -154,14 +141,29 @@ HEAD-Ex Logística y Transporte + Vision es el botón de radio presentado + Control es el código tkinter que gestiona todo esto -.. code-block :: python +.. activecode:: ac_l52_1b + :nocodelens: + :language: python3 + :python3_interpreter: brython + + from browser import document, html + + def al_cambiar(evento): + print(f"Destino: {evento.target.value}") + + app = html.DIV() + + app <= html.LABEL('Destino: ') - Label(app, text = 'Destino: ').pack() - destino = StringVar() - destino.set(None) - Radiobutton(app, variable = destino , text = 'Cambridge , MA', value = 'Cambridge , MA').pack() - Radiobutton(app, variable = destino , text = 'Cambridge , UK', value = 'Cambridge , UK').pack() - Radiobutton(app, variable = destino , text = 'Seattle, WA', value = 'Seattle , WA').pack() + destinos = ['Cambridge, MA', 'Cambridge, UK', 'Seattle, WA'] + for destino in destinos: + radio = html.INPUT(Type="radio", name="destino", value=destino) + radio.bind('change', al_cambiar) + app <= radio + app <= html.LABEL(destino) + app <= html.BR() + + document <= app HEAD-Ex Logística e Transporte @@ -192,55 +194,91 @@ HEAD-Ex Logística e Transporte ============================== -.. code-block :: python +.. activecode:: ac_l52_1c + :nocodelens: + :language: python3 + :python3_interpreter: brython + + from browser import document, html, window - - def salvar_dados(): - fileD = open('encomendas.txt','a') - fileD.write('Destino: ') - fileD.write('%s\n' %destino.get()) - fileD.write('Descricao: ') - fileD.write('%s\n' %descricao.get()) - fileD.write('Endereco: ') - fileD.write('%s\n' %endereco.get('1.0',END)) - destino.delete(0,END) - descricao.delete(0,END) - endereco.delete('1.0',END) + def guardar_datos(evento): + window.localStorage['Destino'] = destino.value + window.localStorage['Descripción'] = descripcion.value + window.localStorage['Dirección'] = direccion.value + destino.value = '' + descripcion.value = '' + direccion.value = '' - def ler_destinos(archivo): + def leer_destinos(): destinos = [] - f = open(archivo) - for linha in f: - destinos.append(linha.rstrip()) + for clave in window.localStorage: + destinos.append(window.localStorage[clave]) return destinos + app = html.DIV() + + app <= html.LABEL('Destino: ') + destino = html.INPUT() + app <= destino + + app <= html.LABEL('Descripción: ') + descripcion = html.INPUT() + app <= descripcion + + app <= html.LABEL('Dirección: ') + direccion = html.TEXTAREA() + app <= direccion + + boton = html.BUTTON('Guardar') + boton.bind('click', guardar_datos) + app <= boton + + document <= app + HEAD-Ex Logística e Transporte ============================== -.. code-block :: python +.. activecode:: ac_l52_1d + :nocodelens: + :language: python3 + :python3_interpreter: brython + + from browser import document, html, window, console + + def guardar_datos(evento): + window.localStorage['Destino'] = destino.value + window.localStorage['Descripción'] = descripcion.value + window.localStorage['Dirección'] = direccion.value + console.log(f"Datos guardados: Destino - {destino.value}, Descripción - {descripcion.value}, Dirección - {direccion.value}") + destino.value = '' + descripcion.value = '' + direccion.value = '' + + app = html.DIV() + app <= html.H2('HEAD-Ex Logística y Transporte') - from tkinter import * + app <= html.LABEL('Destino: ') + destino = html.SELECT() + opciones = ["Opción 1", "Opción 2", "Opción 3"] # Reemplaza con tus opciones + for opcion in opciones: + destino <= html.OPTION(opcion) + app <= destino - app = Tk() - app.title('HEAD-Ex Logística e Transporte') - Label(app,text = "Destino: ").pack() - destino = StringVar() - destino.set(None) + app <= html.LABEL('Descripción: ') + descripcion = html.INPUT() + app <= descripcion - opcoes = ler_destinos("cidades.txt") - OptionMenu(app,destino,*opcoes).pack() + app <= html.LABEL('Hablar a: ') + direccion = html.INPUT() + app <= direccion - Label(app,text = "Descripcion: ").pack() - descricao = Entry(app) - descricao.pack() - Label(app,text = "Habla a: ").pack() - endereco = Entry(app) - endereco.pack() - Button(app, text = "Ahorrar" , command = salvar_dados).pack() - app.mainloop() + boton = html.BUTTON('Guardar') + boton.bind('click', guardar_datos) + app <= boton + document <= app HEAD-Ex Logística y Transporte diff --git a/_sources/lectures/TWP52_en.rst b/_sources/lectures/TWP52_en.rst index 372050b500..e19079513c 100644 --- a/_sources/lectures/TWP52_en.rst +++ b/_sources/lectures/TWP52_en.rst @@ -23,54 +23,40 @@ HEAD-Ex Logistics and Transportation :alt: - -HEAD-Ex Logistics and Transportation -==================================== - - -.. code-block :: python - - - def salvar_dados(): - fileD = open('encomendas.txt','a') - fileD.write('Destino: ') - fileD.write('%s\n' %destino.get()) - fileD.write('Descripcion: ') - fileD.write('%s\n' %descricao.get()) - fileD.write('Habla a: ') - fileD.write('%s\n' %endereco.get('1.0',END)) - destino.delete(0,END) - descricao.delete(0,END) - endereco.delete('1.0',END) - - - HEAD-Ex Logistics and Transportation ==================================== +.. activecode:: ac_l52_1a_en + :nocodelens: + :language: python3 + :python3_interpreter: brython -.. code-block :: python + from browser import document, html - from tkinter import * + def save_data(event): + # Add your save data logic here + print(f"Destination: {destination.value}, Description: {description.value}, Speak to: {address.value}") + + app = html.DIV() + app <= html.H2('HEAD-Ex Logistics and Transport') - app = Tk() - app.title('HEAD-Ex Logística y Transporte') - app.geometry("250x180+200+100") + app <= html.LABEL('Destination: ') + destination = html.INPUT() + app <= destination - Label(app,text = "Destino: ").pack() - destino = Entry(app) - destino.pack() + app <= html.LABEL('Description: ') + description = html.INPUT() + app <= description - Label(app,text = "Descripcion: ").pack() - descricao = Entry(app) - descricao.pack() + app <= html.LABEL('Speak to: ') + address = html.INPUT() + app <= address - Label(app,text = "Habla a: ").pack() - endereco = Entry(app) - endereco.pack() + button = html.BUTTON('Save') + button.bind('click', save_data) + app <= button - Button(app, text = "Salvar" , command = salvar_dados).pack() - app.mainloop() + document <= app HEAD-Ex Logistics and Transportation @@ -154,14 +140,29 @@ HEAD-Ex Logistics and Transportation + Vision is the featured radio button + Control is the tkinter code that manages all this -.. code-block :: python +.. activecode:: ac_l52_1b_en + :nocodelens: + :language: python3 + :python3_interpreter: brython + + from browser import document, html + + def on_change(event): + print(f"Destination: {event.target.value}") + + app = html.DIV() + + app <= html.LABEL('Destination: ') - Label(app, text = 'Destino: ').pack() - destino = StringVar() - destino.set(None) - Radiobutton(app, variable = destino , text = 'Cambridge , MA', value = 'Cambridge , MA').pack() - Radiobutton(app, variable = destino , text = 'Cambridge , UK', value = 'Cambridge , UK').pack() - Radiobutton(app, variable = destino , text = 'Seattle, WA', value = 'Seattle , WA').pack() + destinations = ['Cambridge, MA', 'Cambridge, UK', 'Seattle, WA'] + for destination in destinations: + radio = html.INPUT(Type="radio", name="destination", value=destination) + radio.bind('change', on_change) + app <= radio + app <= html.LABEL(destination) + app <= html.BR() + + document <= app HEAD-Ex Logistics and Transportation @@ -191,54 +192,92 @@ HEAD-Ex Logistics and Transportation ==================================== -.. code-block :: python +.. activecode:: ac_l52_1c_en + :nocodelens: + :language: python3 + :python3_interpreter: brython - def salvar_dados(): - fileD = open('encomendas.txt','a') - fileD.write('Destino: ') - fileD.write('%s\n' %destino.get()) - fileD.write('Descricao: ') - fileD.write('%s\n' %descricao.get()) - fileD.write('Endereco: ') - fileD.write('%s\n' %endereco.get('1.0',END)) - destino.delete(0,END) - descricao.delete(0,END) - endereco.delete('1.0',END) - - def ler_destinos(archivo): - destinos = [] - f = open(archivo) - for linha in f: - destinos.append(linha.rstrip()) - return destinos + from browser import document, html, window + + def save_data(event): + window.localStorage['Destination'] = destination.value + window.localStorage['Description'] = description.value + window.localStorage['Address'] = address.value + destination.value = '' + description.value = '' + address.value = '' + + def read_destinations(): + destinations = [] + for key in window.localStorage: + destinations.append(window.localStorage[key]) + return destinations + + app = html.DIV() + + app <= html.LABEL('Destination: ') + destination = html.INPUT() + app <= destination + + app <= html.LABEL('Description: ') + description = html.INPUT() + app <= description + + app <= html.LABEL('Address: ') + address = html.TEXTAREA() + app <= address + + button = html.BUTTON('Save') + button.bind('click', save_data) + app <= button + + document <= app HEAD-Ex Logistics and Transportation ==================================== -.. code-block :: python +.. activecode:: ac_l52_1d_en + :nocodelens: + :language: python3 + :python3_interpreter: brython + + from browser import document, html, window, console + + def save_data(event): + window.localStorage['Destination'] = destination.value + window.localStorage['Description'] = description.value + window.localStorage['Address'] = address.value + console.log(f"Saved data: Destination - {destination.value}, Description - {description.value}, Address - {address.value}") + destination.value = '' + description.value = '' + address.value = '' + + app = html.DIV() + app <= html.H2('HEAD-Ex Logistics and Transport') + + app <= html.LABEL('Destination: ') + destination = html.SELECT() + options = ["Option 1", "Option 2", "Option 3"] # Replace with your options + for option in options: + destination <= html.OPTION(option) + app <= destination - from tkinter import * + app <= html.LABEL('Description: ') + description = html.INPUT() + app <= description - app = Tk() - app.title('HEAD-Ex Logística e Transporte') - Label(app,text = "Destino: ").pack() - destino = StringVar() - destino.set(None) + app <= html.LABEL('Speak to: ') + address = html.INPUT() + app <= address - opcoes = ler_destinos("cidades.txt") - OptionMenu(app,destino,*opcoes).pack() + button = html.BUTTON('Save') + button.bind('click', save_data) + app <= button - Label(app,text = "Descripcion: ").pack() - descricao = Entry(app) - descricao.pack() - Label(app,text = "Habla a: ").pack() - endereco = Entry(app) - endereco.pack() - Button(app, text = "Ahorrar" , command = salvar_dados).pack() - app.mainloop() + document <= app @@ -253,7 +292,7 @@ HEAD-Ex Logistics and Transportation :alt: -review +Review ======