Initial commit

This commit is contained in:
2024-03-09 17:44:57 +02:00
parent 639c1e04bc
commit 146a7c89df
25 changed files with 1992 additions and 0 deletions
Binary file not shown.
+18
View File
@@ -0,0 +1,18 @@
import window_1 as w_1
import sys
from PyQt5 import QtWidgets
female_names = ["Діана", "Оксана", "Катерина", "Карина", "Антоніна"]
male_names = ["Андрій", "Сергій", "Микола", "Євгеній", "Олександр"]
app = QtWidgets.QApplication(sys.argv)
app.setStyleSheet(open("style.css").read())
window_1 = w_1.Window()
window_1.window_2.set_sets(female_names, male_names)
window_1.show()
sys.exit(app.exec_())
+26
View File
@@ -0,0 +1,26 @@
QWidget{
border-radius: 10px;
padding: 4px;
margin: 2px;
font-family: "Liberation Mono";
font-size: 14pt;
}
QPushButton{
background-color: blueviolet;
color: white;
}
QPushButton:hover{
background-color: #6f20b3;
}
QPushButton:pressed{
background-color: #8f58c9;
}
QListView{
border: 3px solid blueviolet;
}
QLabel{
border: 3px solid blueviolet;
}
QRadioButton{
border: 3px solid blueviolet;
}
+116
View File
@@ -0,0 +1,116 @@
from PyQt5 import QtCore, QtWidgets
from sys import exit
import window_2 as w_2, window_3 as w_3, window_4 as w_4
def open_window(window):
window.show()
class Window(QtWidgets.QMainWindow):
def __init__(self):
super(QtWidgets.QMainWindow, self).__init__()
self.window_2 = w_2.Window()
self.window_3 = w_3.Window()
self.window_4 = w_4.Window()
self.setWindowTitle("Вікно 1")
self.centralwidget = QtWidgets.QWidget(self)
self.gridLayout = QtWidgets.QGridLayout(self.centralwidget)
self.full_name = QtWidgets.QLabel(self.centralwidget)
self.full_name.setText("П. І. Б:")
self.full_name.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter)
self.gridLayout.addWidget(self.full_name, 0, 0, 1, 1)
self.full_name_answer = QtWidgets.QLabel(self.centralwidget)
self.full_name_answer.setText("Швед Андрій Дмитрович")
self.gridLayout.addWidget(self.full_name_answer, 0, 1, 1, 1)
self.group = QtWidgets.QLabel(self.centralwidget)
self.group.setText("Група:")
self.group.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter)
self.gridLayout.addWidget(self.group, 1, 0, 1, 1)
self.group_answer = QtWidgets.QLabel(self.centralwidget)
self.group_answer.setText("ІО-23")
self.gridLayout.addWidget(self.group_answer, 1, 1, 1, 1)
self.list_number = QtWidgets.QLabel(self.centralwidget)
self.list_number.setText("Номер в списку:")
self.list_number.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter)
self.gridLayout.addWidget(self.list_number, 2, 0, 1, 1)
self.list_number_answer = QtWidgets.QLabel(self.centralwidget)
self.list_number_answer.setText("30")
self.gridLayout.addWidget(self.list_number_answer, 2, 1, 1, 1)
self.task_number = QtWidgets.QLabel(self.centralwidget)
self.task_number.setText("Номер завдання:")
self.task_number.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignTrailing | QtCore.Qt.AlignVCenter)
self.gridLayout.addWidget(self.task_number, 3, 0, 1, 1)
self.task_number_answer = QtWidgets.QLabel(self.centralwidget)
self.task_number_answer.setText("24")
self.gridLayout.addWidget(self.task_number_answer, 3, 1, 1, 1)
self.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(self)
self.menubar.setGeometry(QtCore.QRect(0, 0, 362, 22))
self.menubar.setDefaultUp(False)
self.menu_Windows = QtWidgets.QMenu(self.menubar)
self.menu_Windows.setTitle("Вікна")
self.setMenuBar(self.menubar)
self.window_2_action = QtWidgets.QAction(self)
self.window_2_action.setText("Вікно 2")
self.menu_Windows.addAction(self.window_2_action)
self.window_3_action = QtWidgets.QAction(self)
self.window_3_action.setText("Вікно 3")
self.menu_Windows.addAction(self.window_3_action)
self.window_4_action = QtWidgets.QAction(self)
self.window_4_action.setText("Вікно 4")
self.menu_Windows.addAction(self.window_4_action)
self.menu_Windows.addSeparator()
self.exit_action = QtWidgets.QAction(self)
self.exit_action.setText("Вихід")
self.menu_Windows.addAction(self.exit_action)
self.menubar.addAction(self.menu_Windows.menuAction())
self.set_menu()
QtCore.QMetaObject.connectSlotsByName(self)
self.female_names = ["Діана", "Оксана", "Катерина", "Карина", "Антоніна"]
self.male_names = ["Андрій", "Сергій", "Микола", "Євгеній", "Олександр"]
def set_menu(self):
self.window_2_action.triggered.connect(lambda: open_window(self.window_2))
self.window_3_action.triggered.connect(lambda: self.open_window_3())
self.window_4_action.triggered.connect(lambda: self.open_window_4())
self.exit_action.triggered.connect(lambda: exit())
def open_window_3(self):
self.window_3.set_sets(self.window_2.get_set_A(), self.window_2.get_set_B(), self.female_names, self.male_names)
self.window_3.form_relations()
open_window(self.window_3)
def open_window_4(self):
self.window_4.set_sets(
self.window_3.get_granddaughter(), self.window_3.get_godmother(),
self.window_2.get_set_A(), self.window_2.get_set_B()
)
open_window(self.window_4)
+132
View File
@@ -0,0 +1,132 @@
from PyQt5 import QtCore, QtWidgets
def save_set(set_to_save, set_name):
import shelve
with shelve.open("dat/saved_sets") as f:
try:
f[set_name] = set_to_save
except:
pass
class Window(QtWidgets.QWidget):
def __init__(self):
super(QtWidgets.QWidget, self).__init__()
self.setWindowTitle("Вікно 2")
self.gridLayout_2 = QtWidgets.QGridLayout(self)
self.A = QtWidgets.QRadioButton(self)
self.A.setText("A")
self.A.setChecked(True)
self.gridLayout_2.addWidget(self.A, 0, 0, 1, 1)
self.B = QtWidgets.QRadioButton(self)
self.B.setText("B")
self.gridLayout_2.addWidget(self.B, 0, 1, 1, 1)
self.label_female = QtWidgets.QLabel(self)
self.label_female.setText("Жінки")
self.label_female.setAlignment(QtCore.Qt.AlignCenter)
self.gridLayout_2.addWidget(self.label_female, 1, 0, 1, 1)
self.label_male = QtWidgets.QLabel(self)
self.label_male.setText("Чоловіки")
self.label_male.setAlignment(QtCore.Qt.AlignCenter)
self.gridLayout_2.addWidget(self.label_male, 1, 1, 1, 1)
self.list_female = QtWidgets.QListWidget(self)
self.gridLayout_2.addWidget(self.list_female, 2, 0, 1, 1)
self.list_male = QtWidgets.QListWidget(self)
self.gridLayout_2.addWidget(self.list_male, 2, 1, 1, 1)
self.sets_label = QtWidgets.QLabel(self)
self.sets_label.setText("A: \nB: ")
self.gridLayout_2.addWidget(self.sets_label, 4, 0, 1, 2)
self.clear_A = QtWidgets.QPushButton(self)
self.clear_A.setText("Очистити А")
self.gridLayout_2.addWidget(self.clear_A, 5, 0, 1, 1)
self.clear_B = QtWidgets.QPushButton(self)
self.clear_B.setText("Очистити B")
self.gridLayout_2.addWidget(self.clear_B, 5, 1, 1, 1)
self.save_A = QtWidgets.QPushButton(self)
self.save_A.setText("Зберегти А")
self.gridLayout_2.addWidget(self.save_A, 8, 0, 1, 1)
self.save_B = QtWidgets.QPushButton(self)
self.save_B.setText("Зберегти B")
self.gridLayout_2.addWidget(self.save_B, 8, 1, 1, 1)
self.read_grid = QtWidgets.QGridLayout()
self.read_A = QtWidgets.QPushButton(self)
self.read_A.setText("Читати А")
self.read_grid.addWidget(self.read_A, 1, 0, 1, 1)
self.read_B = QtWidgets.QPushButton(self)
self.read_B.setText("Читати B")
self.read_grid.addWidget(self.read_B, 2, 0, 1, 1)
self.gridLayout_2.addLayout(self.read_grid, 12, 0, 1, 2)
QtCore.QMetaObject.connectSlotsByName(self)
self.set_functions()
self.set_A = set()
self.set_B = set()
def set_functions(self):
self.list_female.itemClicked.connect(self.add_to_set)
self.list_male.itemClicked.connect(self.add_to_set)
self.clear_A.clicked.connect(lambda: self.clear_set(self.set_A))
self.clear_B.clicked.connect(lambda: self.clear_set(self.set_B))
self.save_A.clicked.connect(lambda: save_set(self.set_A, "Set_A"))
self.save_B.clicked.connect(lambda: save_set(self.set_B, "Set_B"))
self.read_A.clicked.connect(lambda: self.read_set(self.set_A, "Set_A"))
self.read_B.clicked.connect(lambda: self.read_set(self.set_B, "Set_B"))
def add_to_set(self, item):
if self.A.isChecked():
self.set_A.add(item.text())
elif self.B.isChecked():
self.set_B.add(item.text())
self.set_set_label_text()
def set_set_label_text(self):
self.sets_label.setText(f"A: {self.set_A}\nB: {self.set_B}".replace("set()", ""))
def set_sets(self, names_f, names_m):
self.list_female.addItems(names_f)
self.list_male.addItems(names_m)
def clear_set(self, set_to_clear):
set_to_clear.clear()
self.set_set_label_text()
def read_set(self, set_to_read, set_name):
import shelve
with shelve.open("dat/saved_sets") as f:
try:
set_to_read.update(f[set_name])
except:
pass
self.set_set_label_text()
def get_set_A(self):
return self.set_A
def get_set_B(self):
return self.set_B
+124
View File
@@ -0,0 +1,124 @@
from PyQt5 import QtCore, QtWidgets
def form_table(relation, label):
from prettytable import PrettyTable
table = PrettyTable()
a = [i[0] for i in relation]
b = [i[1] for i in relation]
# print(f"A: {a}\nB: {b}")
matrix = [[0 for j in range(len(b))] for i in range(len(a))]
for i in relation:
m = a.index(i[0])
n = b.index(i[1])
matrix[m][n] = 1
table.field_names = [" "] + a
for i in range(len(matrix)):
table.add_row([b[i]] + matrix[i])
label.setText(table.get_string())
class Window(QtWidgets.QWidget):
def __init__(self):
super(QtWidgets.QWidget, self).__init__()
self.setWindowTitle("Вікно 3")
self.gridLayout = QtWidgets.QGridLayout(self)
self.label_A = QtWidgets.QLabel(self)
self.label_A.setText("A")
self.label_A.setAlignment(QtCore.Qt.AlignCenter)
self.gridLayout.addWidget(self.label_A, 0, 0, 1, 1)
self.label_B = QtWidgets.QLabel(self)
self.label_B.setText("B")
self.label_B.setAlignment(QtCore.Qt.AlignCenter)
self.gridLayout.addWidget(self.label_B, 0, 1, 1, 1)
self.list_A = QtWidgets.QLabel(self)
self.gridLayout.addWidget(self.list_A, 1, 0, 1, 1)
self.list_B = QtWidgets.QLabel(self)
self.gridLayout.addWidget(self.list_B, 1, 1, 1, 1)
self.label_grand_daughter = QtWidgets.QLabel(self)
self.label_grand_daughter.setText("Внучка")
self.label_grand_daughter.setAlignment(QtCore.Qt.AlignCenter)
self.gridLayout.addWidget(self.label_grand_daughter, 2, 0, 1, 2)
self.table_grand_daughter = QtWidgets.QLabel(self)
self.table_grand_daughter.setAlignment(QtCore.Qt.AlignCenter)
self.gridLayout.addWidget(self.table_grand_daughter, 3, 0, 1, 2)
self.label_godmother = QtWidgets.QLabel(self)
self.label_godmother.setText("Хрещена мати")
self.label_godmother.setAlignment(QtCore.Qt.AlignCenter)
self.gridLayout.addWidget(self.label_godmother, 4, 0, 1, 2)
self.table_godmother = QtWidgets.QLabel(self)
self.table_godmother.setAlignment(QtCore.Qt.AlignCenter)
self.gridLayout.addWidget(self.table_godmother, 5, 0, 1, 2)
QtCore.QMetaObject.connectSlotsByName(self)
self.set_A = set()
self.set_B = set()
self.female_names = set()
self.male_names = set()
self.grandparent_granddaughter_relation = set()
self.godmother_godchild_relation = set()
def set_sets(self, set_A, set_B, female_names, male_names):
self.set_A = set_A
self.set_B = set_B
self.female_names = female_names
self.male_names = male_names
self.list_A.setText("\n".join(set_A))
self.list_B.setText("\n".join(set_B))
def form_relations(self):
for grandparent in self.set_A:
for granddaughter in self.set_B:
if (
grandparent != granddaughter
and granddaughter in self.female_names
and (granddaughter, grandparent) not in self.grandparent_granddaughter_relation
and (grandparent, granddaughter) not in self.grandparent_granddaughter_relation
and not any(grandparent == i[0] for i in self.grandparent_granddaughter_relation)
and not any(granddaughter == i[1] for i in self.grandparent_granddaughter_relation)
):
self.grandparent_granddaughter_relation.add((grandparent, granddaughter))
for godmother in self.set_A:
for godchild in self.set_B:
if (
godmother in self.female_names
and godmother != godchild
and (godmother, godchild) not in self.grandparent_granddaughter_relation
and (godchild, godmother) not in self.grandparent_granddaughter_relation
and (godchild, godmother) not in self.godmother_godchild_relation
and (godmother, godchild) not in self.godmother_godchild_relation
and not any(godchild == i[1] for i in self.godmother_godchild_relation)
and not any(godmother == i[0] for i in self.godmother_godchild_relation)
):
self.godmother_godchild_relation.add((godmother, godchild))
form_table(self.grandparent_granddaughter_relation, self.table_grand_daughter)
form_table(self.godmother_godchild_relation, self.table_godmother)
def get_granddaughter(self):
return self.grandparent_granddaughter_relation
def get_godmother(self):
return self.godmother_godchild_relation
+141
View File
@@ -0,0 +1,141 @@
from PyQt5 import QtCore, QtWidgets
def unite(*a):
b = []
for i in a:
for j in i:
if j not in b:
b.append(j)
return b
def intersect(*a):
b = []
for i in a:
for j in i:
if all([j in k for k in a]):
b.append(j)
def difference(a, b):
c = []
for i in a:
if i not in b:
c.append(i)
return c
def universal_set(set_X, set_Y):
universal = []
for x in set_X:
for y in set_Y:
universal.append((x, y))
return universal
def reverse(relation):
res = []
for i in relation:
res.append(i[::-1])
return res
def form_table(relation, label):
from prettytable import PrettyTable
table = PrettyTable()
if relation:
a = [i[0] for i in relation]
b = [i[1] for i in relation]
matrix = [[0 for j in range(len(a))] for i in range(len(a))]
for i in relation:
m = a.index(i[0])
n = b.index(i[1])
matrix[m][n] = 1
if len(set([" "] + a)) < len([" "] + a):
table.field_names = [i for i in range(len(matrix) + 1)]
table.add_row([" "] + a)
else:
table.field_names = [" "] + a
for i in range(len(matrix)):
table.add_row([b[i]] + matrix[i])
else:
table.field_names = [" "]
label.setText(table.get_string())
class Window(QtWidgets.QWidget):
def __init__(self):
super(QtWidgets.QWidget, self).__init__()
self.setWindowTitle("Вікно 4")
self.gridLayout = QtWidgets.QGridLayout(self)
self.label = QtWidgets.QLabel(self)
self.label.setText("Оберіть операцію")
self.label.setAlignment(QtCore.Qt.AlignCenter)
self.gridLayout.addWidget(self.label, 0, 0, 1, 2)
self.button_union = QtWidgets.QPushButton(self)
self.button_union.setText("R S")
self.gridLayout.addWidget(self.button_union, 1, 0, 1, 1)
self.button_intersection = QtWidgets.QPushButton(self)
self.button_intersection.setText("R ∩ S")
self.gridLayout.addWidget(self.button_intersection, 2, 0, 1, 1)
self.button_difference = QtWidgets.QPushButton(self)
self.button_difference.setText("R \\ S")
self.gridLayout.addWidget(self.button_difference, 3, 0, 1, 1)
self.button_universal_difference = QtWidgets.QPushButton(self)
self.button_universal_difference.setText("U \\ R")
self.gridLayout.addWidget(self.button_universal_difference, 4, 0, 1, 1)
self.button_reverse = QtWidgets.QPushButton(self)
self.button_reverse.setText("S⁻¹")
self.gridLayout.addWidget(self.button_reverse, 5, 0, 1, 1)
self.tableView_relation = QtWidgets.QLabel(self)
self.tableView_relation.setAlignment(QtCore.Qt.AlignCenter)
self.gridLayout.addWidget(self.tableView_relation, 1, 1, 5, 1)
QtCore.QMetaObject.connectSlotsByName(self)
self.set_functions()
self.set_R = set()
self.set_S = set()
self.set_A = set()
self.set_B = set()
def set_functions(self):
self.button_union.clicked.connect(lambda: form_table(unite(self.set_R, self.set_S), self.tableView_relation))
self.button_intersection.clicked.connect(lambda: form_table(intersect(self.set_R, self.set_S),
self.tableView_relation))
self.button_difference.clicked.connect(lambda: form_table(difference(self.set_R, self.set_S),
self.tableView_relation))
self.button_universal_difference.clicked.connect(lambda: form_table(
difference(universal_set(self.set_A, self.set_B), self.set_R), self.tableView_relation)
)
self.button_reverse.clicked.connect(lambda: form_table(reverse(self.set_S), self.tableView_relation))
def set_sets(self, granddaughter, godmother, set_A, set_B):
self.set_R = granddaughter
self.set_S = godmother
self.set_A = set_A
self.set_B = set_B