Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernizes MVC #322

Merged
merged 4 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ sphinx_settings.json
venv/
env/
.gitignore
.venv


# Byte-compiled / optimized / DLL files
Expand Down
192 changes: 115 additions & 77 deletions _sources/lectures/TWP52.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading
Loading