Skip to content

Commit

Permalink
added infimum/supremum to GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
ptgm committed Jun 16, 2024
1 parent 5f9deb5 commit 30e1a41
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 35 deletions.
Binary file added img/pyfunctionhood.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
113 changes: 78 additions & 35 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from tkinter import Tk, Label, Entry, Text, Button, Spinbox, StringVar, IntVar
import tkinter as tk
from hassediagram import *
import sys

Expand Down Expand Up @@ -41,50 +41,90 @@ def default_values():
outputText.delete(1.0, "end") # Clear previous output
outputText.insert(1.0, '')

def set_infimum():
try:
idim = int(varDimension.get())
hd = HasseDiagram(idim)
f = hd.get_infimum()
varFunction.set(str(f))
except ValueError as e:
output = "ERROR! " + str(e)

def set_supremum():
try:
idim = int(varDimension.get())
hd = HasseDiagram(idim)
f = hd.get_supremum()
varFunction.set(str(f))
except ValueError as e:
output = "ERROR! " + str(e)

def close_window():
"""
Close the main window (exits the interface).
"""
root.destroy()

# Create the main window
root = Tk()
root = tk.Tk()
root.title("pyFunctionHood GUI")

root.grid_columnconfigure(0, minsize=1, weight=0)
root.grid_columnconfigure(1, minsize=1, weight=1)
root.grid_columnconfigure(2, minsize=1, weight=1)

row = 0
# Entry field for user function
labelFunction = Label(root, text="Function:")
labelFunction.grid(row=row, column=0, sticky="W") # Align left
varFunction = StringVar(value='{{1,2,3},{1,3,4},{2,3,4}}')
entryFunction = Entry(root, textvariable=varFunction)
entryFunction.grid(row=row, column=1)
labelDimension = tk.Label(root, text="Dimension")
labelDimension.grid(row=row, column=0, sticky='w')
labelFunction = tk.Label(root, text="Monotone Boolean Function")
labelFunction.grid(row=row, column=1, columnspan=2)

row += 1
# Spinbox with Dimension
labelDimension = Label(root, text="Dimension:")
labelDimension.grid(row=row, column=0, sticky="W") # Align left
varDimension = IntVar(value=4) # default dimension
spinboxDimension = Spinbox(root, from_=2, to=20, textvariable=varDimension)
spinboxDimension.grid(row=row, column=1)
varDimension = tk.IntVar(value=4) # default dimension
spinboxDimension = tk.Spinbox(root, from_=2, to=14, textvariable=varDimension, width=6)
spinboxDimension.grid(row=row, column=0, sticky='w')
varFunction = tk.StringVar(value='{{1,2,3},{1,3,4},{2,3,4}}')
entryFunction = tk.Entry(root, textvariable=varFunction, width=48)
entryFunction.grid(row=row, column=1, columnspan=2)

row +=1
row += 1
bottomFrame = tk.Frame(root, padx=5, pady=5)
bottomFrame.grid(row=row, columnspan=2)

row = 0
# Buttons for Infimum/Supremum
buttonInfimum = tk.Button(bottomFrame, text="Set Infimum", command=set_infimum)
buttonInfimum.grid(row=row, column=0)
buttonSupremum = tk.Button(bottomFrame, text="Set Supremum", command=set_supremum)
buttonSupremum.grid(row=row, column=1)

row += 1
canvas = tk.Canvas(bottomFrame, height=2, bg="darkgray") # Adjust height and color
canvas.grid(row=row, columnspan=3, sticky="ew", pady=10)

row += 1
# Buttons to call parents/children methods
buttonParents = Button(root, text="Parents", command=get_parents)
buttonParents = tk.Button(bottomFrame, text="Generate Parents", command=get_parents)
buttonParents.grid(row=row, column=0)
buttonChildren = Button(root, text="Children", command=get_children)
buttonChildren = tk.Button(bottomFrame, text="Generate Children", command=get_children)
buttonChildren.grid(row=row, column=1)

row += 1
# Text area with grid placement and set state to disabled
outputText = Text(root, width=50, height=10)#, state="disabled")
outputText = tk.Text(bottomFrame, width=60, height=10)#, state="disabled")
outputText.grid(row=row, columnspan=2) # Span across two columns
# scrollbar = tk.Scrollbar(bottomFrame)
# outputText.config(yscrollcommand=scrollbar.set)
# scrollbar.config(command=outputText.yview)

row += 1
# Reset default values
buttonDefault = Button(root, text="Reset", command=default_values)
# Default values
buttonDefault = tk.Button(bottomFrame, text="Default values", command=default_values)
buttonDefault.grid(row=row, column=0)
# Close button
buttonClose = Button(root, text="Close", command=close_window)
buttonClose = tk.Button(bottomFrame, text="Close", command=close_window)
buttonClose.grid(row=row, column=1)

# Run the main loop
Expand All @@ -93,34 +133,37 @@ def close_window():
#--------------------------------------------------------------------

def usage():
print('\nFor graphical mode, run without arguments: python', sys.argv[0])
print('\nFor command line mode, use the following arguments:')
print('Usage example: python', sys.argv[0], '<type>', '<dimension>', '<function>')
print(' <type>: [p]arents or [c]hildren')
print(' <dimension>: 4')
print(' <function>: "{{1,2,3},{1,3,4},{2,3,4}}"')
sys.exit(1)

def command_line_mode():
if len(sys.argv) != 4:
print('ERROR: invalid number of arguments!')
usage()
elif sys.argv[1] not in ('p','parents','c','children'):
if sys.argv[1] not in ('p','parents','c','children'):
print('ERROR: invalid <type>')
usage()

ndim = int(sys.argv[2])
hd = HasseDiagram(ndim)
f = Function.fromString(ndim, sys.argv[3])
if sys.argv[1] in ('p','parents'):
s1Parents, s2Parents, s3Parents = hd.get_f_parents(f)
lParents = ['R1 ' + str(f) for f in s1Parents]\
+ ['R2 ' + str(f) for f in s2Parents]\
+ ['R3 ' + str(f) for f in s3Parents]
print('\n'.join(lParents))
else:
ndim = int(sys.argv[2])
hd = HasseDiagram(ndim)
f = Function.fromString(ndim, sys.argv[3])
if sys.argv[1] in ('p','parents'):
s1Parents, s2Parents, s3Parents = hd.get_f_parents(f)
lParents = ['R1 ' + str(f) for f in s1Parents]\
+ ['R2 ' + str(f) for f in s2Parents]\
+ ['R3 ' + str(f) for f in s3Parents]
print('\n'.join(lParents))
else:
s1Children, s2Children, s3Children = hd.get_f_children(f)
lChildren = ['R1 ' + str(f) for f in s1Children]\
+ ['R2 ' + str(f) for f in s2Children]\
+ ['R3 ' + str(f) for f in s3Children]
print('\n'.join(lChildren))
s1Children, s2Children, s3Children = hd.get_f_children(f)
lChildren = ['R1 ' + str(f) for f in s1Children]\
+ ['R2 ' + str(f) for f in s2Children]\
+ ['R3 ' + str(f) for f in s3Children]
print('\n'.join(lChildren))



Expand Down

0 comments on commit 30e1a41

Please sign in to comment.