From 952e8fd7b53a53bf6c657c2ab4ce91ac4ae27fe8 Mon Sep 17 00:00:00 2001 From: Azure <66933053+DualFennecFox@users.noreply.github.com> Date: Tue, 16 Jul 2024 23:56:33 -0400 Subject: [PATCH] Revert "gafo" This reverts commit 085715e22fc5e160611a6097a0c325be60133b90. --- main.py | 167 ++++++++++++-------------------------------------------- 1 file changed, 34 insertions(+), 133 deletions(-) diff --git a/main.py b/main.py index f8124a6..3aee8c7 100644 --- a/main.py +++ b/main.py @@ -1,7 +1,7 @@ import tkinter from tkinter import * from tkinter import ttk -import math + import sv_ttk entry_a = 0 @@ -13,132 +13,8 @@ Lista_a = 0 Lista_b = 0 matriz_binaria_R = [] -ListaTuplasLista = [] - - -W = 820 -H = 650 -scaled = 300 - -def scale(nodes): - - negated_nodes = [(x, -y) for x, y in nodes] - scaled_nodes = [(x * scaled, y * scaled) for x, y in negated_nodes] - centered_nodes = [(x + W / 2, y + H / 2) for x, y in scaled_nodes] - - return centered_nodes - - -def grafo(): - for widget in frame2.winfo_children(): - widget.destroy() - - if len(ListaTuplasLista) == 0: - - label2 = ttk.Label(frame2, text="Primero debe crear conjuntos para ver esta ventana.") - label2.place(relx=0.5, rely=0.5, anchor=tkinter.CENTER) - return - - canvas = Canvas(frame2, width=W, height=H, bg="#1C1C1C") - - nver = 0 - points = [] - - tuplas = Lista_a - for i in range(len(Lista_b)): - tuplas.append(Lista_b[i]) - - tuplas = list(set(tuplas)) - - reldict = {} - items = [] - - for i in range(len(tuplas)): - - if tuplas[i] in reldict: - continue - nver = nver + 1 - reldict.update({tuplas[i]: (0, 0)}) - items.append(tuplas[i]) - - for i in range(nver): - ra = 360/nver - angle = math.radians(i * ra) - - # Calcular las coordenadas del vértice - x = 1 * math.cos(angle) - y = 1 * math.sin(angle) - - # Dibujar el vértice (puedes personalizar su apariencia) - - given_nodes = ( - (x, y), - (x, y) - ) - nodes = scale(given_nodes) - points.append(nodes[0]) - - radius = 20 - for i in range(nver): - x, y = points[i] - - if i+1 != len(points): - x2, y2 = points[i+1] - - else: - x2, y2 = points[0] - - #given_nodes = ( - # (x, y), - # (W/2, H/2), - # (x2, y2), - #) - - canvas.create_oval(x - radius, y - radius, x + radius, y + radius, outline="white") - - - #canvas.create_polygon(given_nodes, fill="blue", outline="white") - #canvas.create_line(x, y, x2, y2, fill="white") - reldict.update({tuplas[i]: (x, y)}) - - - #renderoutsides(canvas) - - for i in range(len(ListaTuplasLista)): - - a, b = ListaTuplasLista[i] - xa, ya = reldict[a] - xb, yb = reldict[b] - - color = "blue" - offset = -5 - operand = -1 - if xa > xb: - color = "red" - offset = -offset - operand = 1 - - if a == b: - canvas.create_oval(xa - radius, ya - radius, xa + radius, ya + radius, outline="green", width=2) - else: - canvas.create_line( - xa - offset, - ya - offset, - xb - offset, - yb - offset, - fill=color, arrow="last", width= 2) - - - - for i in range(len(items)): - x, y = points[i] - canvas.create_text(x, y, fill="white", text=items[i], font="Times 15 bold") - - canvas.pack(expand=True, fill="both") - - -def RepresentarMatriz(Lista_a, Lista_b): +def RepresentarMatriz(Lista_a, Lista_b, ListasString_Union, RelacionStringFormat): if Lista_a == 0 and Lista_b == 0: ErrorNR = Toplevel() ErrorNR.geometry("380x160") @@ -176,13 +52,18 @@ def RepresentarMatriz(Lista_a, Lista_b): print(matriz_binaria_R[j][i], end=' | ') print()#Salto de linea - print()#Salto de linea - MatrizPlantilla = ttk.Label(frame2, text=MatrizString(Lista_a, Lista_b, matriz_binaria_R)) + print()#Salto de linea + A_B_Label = ttk.Label(frame2, text=ListasString_Union, foreground="white", font=("Ariel", 13, "bold")) + RelacionLabel = ttk.Label(frame2, text=RelacionStringFormat, foreground="white", font=("Ariel", 13, "bold")) + A_B_Label.place(relx=0.5, rely=0.05, anchor="center") + RelacionLabel.place(relx=0.5, rely=0.1, anchor="center") + MatrizPlantilla = ttk.Label(frame2, text=MatrizString(Lista_a, Lista_b, matriz_binaria_R), font=("Consolas", 16, "bold")) MatrizPlantilla.place(relx=0.5, rely=0.5, anchor="center") def PropiedadesRel(RelacionR, Lista_a, Lista_b): - + global RelacionStringFormat + global ListasString_Union if Lista_a == 0 and Lista_b == 0: ErrorNR = Toplevel() ErrorNR.geometry("380x160") @@ -202,6 +83,17 @@ def PropiedadesRel(RelacionR, Lista_a, Lista_b): simetria_R_Label = ttk.Label(frame2, text="Simetria: False", foreground="gray", font=("Ariel", 25)) asimetria_R_Label = ttk.Label(frame2, text="Asimetria: False", foreground="gray", font=("Ariel", 25)) antisimetria_R_Label = ttk.Label(frame2, text="Antisimetria: False", foreground="gray", font=("Ariel", 25)) + ListasString_A = ",".join(Lista_a) + ListasString_B = ",".join(Lista_b) + RelacionSring = str(RelacionR).strip('[]').replace("'", "") + my_string_var = StringVar() + RelacionStringFormat = "R = {" + RelacionSring + "}" + ListasString_Union = "A = {" + ListasString_A + "}" + " " + " B = {" + ListasString_B + "}" + print("test: ", ListasString_Union) + A_B_Label = ttk.Label(frame2, text=ListasString_Union, foreground="white", font=("Ariel", 16, "bold")) + RelacionLabel = ttk.Label(frame2, text=RelacionStringFormat, foreground="white", font=("Ariel", 16, "bold")) + A_B_Label.place(relx=0.5, rely=0.05, anchor="center") + RelacionLabel.place(relx=0.5, rely=0.1, anchor="center") reflexividad_R_Label.place(relx=0.5, rely=0.7, anchor="center") irreflexivilidad_R_Label.place(relx=0.5, rely=0.6, anchor="center") transitividad_R_Label.place(relx=0.5, rely=0.5, anchor="center") @@ -367,6 +259,14 @@ def MatrizString(Lista_a, Lista_b, matriz_binaria_R): def GenerarArreglo(ListaSeleccion_f, titulo_relaciones): global RelacionR + global RelacionStringFormat + global ListasString_Union + ListasString_A = ",".join(Lista_a) + ListasString_B = ",".join(Lista_b) + RelacionSring = str(RelacionR).strip('[]').replace("'", "") + my_string_var = StringVar() + RelacionStringFormat = "R = {" + RelacionSring + "}" + ListasString_Union = "A = {" + ListasString_A + "}" + " " + " B = {" + ListasString_B + "}" RelacionR = list(ListaSeleccion_f.get(0, "end")) for i in range(len(RelacionR)): @@ -417,7 +317,6 @@ def EnviarTodos(ListaTuplas, ListaSeleccion_f): def relacionesLista(entry_a, entry_b, ListaTuplas): global Lista_a global Lista_b - global ListaTuplasLista Lista_a = entry_a.get().split(",") Lista_b = entry_b.get().split(",") valor_a = entry_a.get() @@ -459,6 +358,8 @@ def click_boton(): # VENTANA RELACIONES def relaciones(): + global RelacionStringFormat + global ListasString_Union # se remueve el texto de bienvenida for widget in frame2.winfo_children(): widget.destroy() @@ -547,7 +448,7 @@ def relaciones(): # ventana principal root = Tk() root.title("Hecho por: Jonathan Salazar") -root.minsize(820, 650) +root.minsize(1280, 720) root.maxsize(1280, 720) root.resizable(False, False) @@ -571,11 +472,11 @@ def relaciones(): rep_lab.grid(row=3, column=0, padx=10, pady=10) # el resto de los botones -button = ttk.Button(frame1, text="Matriz", style="Button.TButton", command=lambda: RepresentarMatriz(Lista_a, Lista_b)) +button = ttk.Button(frame1, text="Matriz", style="Button.TButton", command=lambda: RepresentarMatriz(Lista_a, Lista_b, RelacionStringFormat, ListasString_Union)) button.grid(row=4, column=0, padx=10, pady=10, sticky="ew") button = ttk.Button(frame1, text="Sagital", style="Button.TButton", command=click_boton) button.grid(row=5, column=0, padx=10, pady=10, sticky="ew") -button = ttk.Button(frame1, text="Grafo", style="Button.TButton", command=grafo) +button = ttk.Button(frame1, text="Grafo", style="Button.TButton", command=click_boton) button.grid(row=6, column=0, padx=10, pady=10, sticky="ew") # segundo frame