From 5a896ae00afc8f381977bf274f6e2fca4d9c3e89 Mon Sep 17 00:00:00 2001 From: Egor Deev <67710823+IGlek@users.noreply.github.com> Date: Tue, 30 Nov 2021 16:04:34 +0700 Subject: [PATCH] v. 2 --- main.py | 216 +++++++-- rasp.ui | 1310 ++++++++++++++++++++++++++++++------------------------ table.db | Bin 24576 -> 24576 bytes 3 files changed, 911 insertions(+), 615 deletions(-) diff --git a/main.py b/main.py index 5828935..6453fc6 100644 --- a/main.py +++ b/main.py @@ -1,9 +1,10 @@ +import datetime as dt import sqlite3 import sys -from PyQt5.QtWidgets import QApplication, QMessageBox, QWidget -from PyQt5.QtWidgets import QMainWindow, QTableWidgetItem, QTableWidget from PyQt5 import QtCore, QtWidgets, QtGui, uic +from PyQt5.QtWidgets import QApplication, QMessageBox, QMainWindow, QTableWidgetItem +from PyQt5.QtWidgets import QWidget, QTableView, QTableWidget, QComboBox if hasattr(QtCore.Qt, 'AA_EnableHighDpiScaling'): QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling, True) @@ -18,59 +19,192 @@ class MyWidget(QMainWindow): # Ui_MainWindow uic.loadUi('rasp.ui', self) # self.setupUi(self) self.connection = sqlite3.connect("table.db") self.cursor = self.connection.cursor() - # По умолчанию будем выводить все данные из таблицы + + # РАСПИСАНИЕ + self.add_but.clicked.connect(self.add) # ДОБАВЛЕНИЕ ПРЕДМЕТОВ + self.upd_but.clicked.connect(self.upd) # ИЗМЕНЕНИЕ ПРЕДМЕТОВ + self.clear_but.clicked.connect(self.clear) # УБИРАНИЕ ПРЕДМЕТОВ + self.del_but.clicked.connect(self.delete) # УДАЛЕНИЕ ПРЕДМЕТОВ + + # ДАННЫЕ ТАБЛИЦЫ self.table() def table(self): try: # РАСПИСАНИЕ - print(1) with self.connection: all_day = self.cursor.execute("SELECT * FROM timetable").fetchall() - # Заполним размеры таблицы tables = [self.Mon_school, self.Tue_school, self.Wed_school, self.Thu_school, self.Fri_school, self.Sat_school] - print(2) - for day in tables: - day = day.QTableWidget.QTableView - day.setSpan(8, 1) - print(3) - # Заполняем таблицу элементами - i, row = enumerate(all_day[tables.index(day)]) - print(i, row) - for j, elem in enumerate(row): - self.tableWidget_2.setItem( - i, j, QTableWidgetItem(str(elem))) - """ - # ВСЕ ФИЛЬМЫ - with self.connection: - res = self.cursor.execute("SELECT * FROM films").fetchall() - # Заполним размеры таблицы - self.tableWidget.setColumnCount(5) - self.tableWidget.setRowCount(0) - # Заполняем таблицу элементами - self.tableWidget.setHorizontalHeaderLabels(["ИД", "Название фильм", "Год выпуска", - "Жанр", "Продолжительность"]) - for i, row in enumerate(res): - self.tableWidget.setRowCount( - self.tableWidget.rowCount() + 1) - for j, elem in enumerate(row): - if j == 3: - for n, name in gnr: - if n == elem: - self.tableWidget.setItem( - i, j, QTableWidgetItem(str(name))) - break + for day in tables: + weekday, subjects = all_day[tables.index(day)], [] + for i in range(10): + if i > 1: + if weekday[i]: + obj = self.cursor.execute(f"SELECT name FROM " + f"lessons WHERE `id` = {weekday[i]}").fetchone()[0] + else: + obj = "" + subjects.append((obj, )) + day.setColumnCount(1) + day.setHorizontalHeaderLabels(["Предмет"]) + day.setRowCount(0) + + for i, row in enumerate(subjects): + day.setRowCount(day.rowCount() + 1) + for j, elem in enumerate(row): + day.setItem(i, j, QTableWidgetItem(str(elem))) + day.horizontalHeader().setStretchLastSection(True) + + # ЗАПОЛНЕНИЕ ВЫПАДАЮЩИХ СПИСКОВ ADD / UPD / DEL + try: + with self.connection: + lessons = self.cursor.execute('SELECT `name` FROM `lessons`').fetchall() + lessons = [i[0] for i in lessons] + for choose_obj in [self.choose_obj1, self.choose_obj2, self.choose_obj3]: + choose_obj.clear() + if choose_obj == self.choose_obj1: + choose_obj.insertItem(0, "Новый предмет") + choose_obj.insertItems(1, lessons) else: - self.tableWidget.setItem( - i, j, QTableWidgetItem(str(elem))) - """ + choose_obj.insertItems(0, lessons) + except Exception: + pass + + # ВСЕ ЗАМЕТКИ + with self.connection: + note = self.cursor.execute("SELECT `date`, `note` FROM notes").fetchall() + maintable = self.maintable + maintable.setColumnCount(2) + maintable.setRowCount(0) + maintable.setHorizontalHeaderLabels(["Дата", "Заметка"]) + + for i, row in enumerate(note): + maintable.setRowCount(maintable.rowCount() + 1) + for j, elem in enumerate(row): + maintable.setItem(i, j, QTableWidgetItem(str(elem))) + maintable.horizontalHeader().setStretchLastSection(True) + + # ЗАМЕТКИ ПОД РАСПИСАНИЕМ + with self.connection: + note = self.cursor.execute("SELECT `date`, `note` FROM notes").fetchall() + notes = [self.Mon_note, self.Tue_note, self.Wed_note, self.Thu_note, self.Fri_note, self.Sat_note] + + week = {0: [], 1: [], 2: [], 3: [], 4: [], 5: []} + for i in note: + weekday = dt.datetime.weekday(i[0]) + if weekday != 6: + week[weekday].append(i) + + for write in notes: + write.setColumnCount(2) + write.setRowCount(0) + write.setHorizontalHeaderLabels(["Дата", "Заметка"]) + + for i, row in enumerate(week[notes.index(write)]): + write.setRowCount(write.rowCount() + 1) + for j, elem in enumerate(row): + write.setItem(i, j, QTableWidgetItem(str(elem))) + write.horizontalHeader().setStretchLastSection(True) + except Exception: QMessageBox.about(self, 'Ошибка!', "Таблица данных не найдена!") + def add(self): + day = self.weekday1.currentIndex() + obj = self.object1.currentIndex() + txt1 = self.add_line.text() + txt2 = self.choose_obj1.currentText() + if txt1 or txt2 != "Новый предмет": + with self.connection: + lessons = self.cursor.execute('SELECT `name` FROM `lessons`').fetchall() + lessons = [i[0] for i in lessons] + if txt1: + if txt1 not in lessons: + with self.connection: + self.cursor.execute(f"INSERT INTO `lessons` (`name`) VALUES(?)", (txt1,)) + lessons = self.cursor.execute('SELECT `name` FROM `lessons`').fetchall() + lessons = [i[0] for i in lessons] + with self.connection: + index = self.cursor.execute("SELECT `id` FROM `lessons` WHERE `name` = ?", (txt1,)).fetchone()[0] + else: + with self.connection: + index = self.cursor.execute("SELECT `id` FROM `lessons` WHERE `name` = ?", (txt2,)).fetchone()[0] + with self.connection: + less = self.cursor.execute("SELECT * FROM `timetable` WHERE `id` = ?", (day + 1,)).fetchone() + less = list(less)[2:] + if None in less: + if obj == 0: + k = 0 + for les in reversed(less): + if les is not None: + obj = len(less) - k + 1 + break + else: + k += 1 + if k == len(less): + obj = 1 + with self.connection: + self.cursor.execute(f"UPDATE `timetable` SET `less_{obj}` = ? WHERE `id` = ?", (index, day + 1)) + for choose_obj in [self.choose_obj1, self.choose_obj2]: + choose_obj.clear() + choose_obj.insertItem(0, "Новый предмет") + self.add_line.clear() + self.table() + else: + for choose_obj in [self.choose_obj1, self.choose_obj2]: + choose_obj.clear() + choose_obj.insertItem(0, "Новый предмет") + choose_obj.insertItems(1, lessons) + QMessageBox.about(self, 'Ошибка!', "В этом дне уже расписание всё занято!") + else: + QMessageBox.about(self, 'Ошибка!', "Введите предмет, который желаете добавить!") + + def upd(self): + obj = self.choose_obj2.currentText() + txt = self.upd_line.text() + if txt != "": + with self.connection: + self.cursor.execute(f"UPDATE `lessons` SET `name` = ? WHERE `name` = ?", (txt, obj)) + self.upd_line.clear() + self.table() + else: + QMessageBox.about(self, 'Ошибка!', "Вы не ввели новое название!") + + def clear(self): + day = self.weekday3.currentIndex() + obj = self.object3.currentIndex() + + for wkd in range(1, 7): + if day == 0 or day == wkd: + for less in range(1, 9): + if obj == 0 or obj == less: + with self.connection: + self.cursor.execute(f"UPDATE `timetable` SET `less_{less}` = ? WHERE `id` = ?", (None, wkd)) + self.table() + + def delete(self): + index = self.choose_obj3.currentText() + with self.connection: + ids = self.cursor.execute("SELECT `id` FROM `lessons` WHERE `name` = ?", (index, )).fetchone()[0] + self.cursor.execute("DELETE FROM `lessons` WHERE `id` = ?", (ids, )) + + for day in range(1, 7): + with self.connection: + lessons = self.cursor.execute("SELECT * FROM `timetable` WHERE `id` = ?", (day,)).fetchone() + lessons = list(lessons)[2:] + if ids in lessons: + for less in range(1, 9): + if ids == lessons[less - 1]: + with self.connection: + self.cursor.execute(f"UPDATE `timetable` SET `less_{less}` = ? WHERE `id` = ?", (None, day)) + self.table() + + def notes(self): + pass + def closeEvent(self, event): - # При закрытии формы закроем и наше соединение с базой данных self.connection.close() @@ -78,4 +212,4 @@ if __name__ == '__main__': app = QApplication(sys.argv) ex = MyWidget() ex.show() - sys.exit(app.exec_()) \ No newline at end of file + sys.exit(app.exec_()) diff --git a/rasp.ui b/rasp.ui index 1145929..80d6fa3 100644 --- a/rasp.ui +++ b/rasp.ui @@ -6,8 +6,8 @@ 0 0 - 1042 - 754 + 1002 + 817 @@ -28,48 +28,14 @@ Расписание - - - - - - - - 14 - - - - QLable { font-size: 14px; } - - - Понедельник - - - - - - - - - - - 16777215 - 80 - - - - - 0 - 0 - - - - - - - + + + 240 + 370 + + @@ -102,8 +68,60 @@ + + + + + 240 + 370 + + + + + + + + 14 + + + + QLable { font-size: 14px; } + + + Понедельник + + + + + + + + + + + 16777215 + 80 + + + + + 0 + 0 + + + + + + + + + + 240 + 370 + + @@ -136,11 +154,112 @@ + + + + + 240 + 370 + + + + + + + + 14 + + + + QLable { font-size: 14px; } + + + Четверг + + + + + + + + + + + 16777215 + 80 + + + + + + + + + + + + 240 + 370 + + + + + + + + 14 + + + + QLable { font-size: 14px; } + + + Суббота + + + + + + + + + + + 16777215 + 80 + + + + + + + + + + 190 + 0 + + + + + 190 + 16777215 + + + + + + + + 16777215 + 170 + + 10 @@ -159,7 +278,7 @@ - 0 + 152 30 @@ -186,8 +305,8 @@ - 0 - 30 + 72 + 25 @@ -220,19 +339,14 @@ Сб - - - Вс - - - 0 - 30 + 71 + 25 @@ -290,7 +404,17 @@ 0 - 30 + 25 + + + + + + + + + 0 + 25 @@ -300,14 +424,12 @@ 0 - 30 + 37 -1 - 50 - false @@ -317,21 +439,39 @@ font-size: 18px; border-radius: 10px; border: 1px solid #3873d9; - background-color: white; } + background-color: white; + box-shadow: 0 0 10px rgb(0, 0, 0);\n + transition: all 1s; +} + +QPushButton:hover{ + background-color: rgb(171, 211, 247); + effect = QtWidgets.QGraphicsDropShadowEffect(QPushButton) + effect.setOffset(0, 0) + effect.setBlurRadius(20) + effect.setColor(QColor(57, 219, 255)) + QPushButton.setGraphicsEffect(effect) +} - Добавить + Обновить - combo1 - add_line - add_but + + + + + + 16777215 + 170 + + 10 @@ -347,128 +487,13 @@ - + 0 - 30 + 25 - - - 9 - - - QLayout::SetFixedSize - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 0 - 30 - - - - - Пн - - - - - Вт - - - - - Ср - - - - - Чт - - - - - Пт - - - - - Сб - - - - - Вс - - - - - - - - - 0 - 30 - - - - - 1 - - - - - 2 - - - - - 3 - - - - - 4 - - - - - 5 - - - - - 6 - - - - - 7 - - - - - 8 - - - - - @@ -476,7 +501,7 @@ 0 - 30 + 25 @@ -486,7 +511,13 @@ 0 - 30 + 35 + + + + + 16777215 + 37 @@ -501,10 +532,19 @@ font-size: 18px; border-radius: 10px; border: 1px solid #3873d9; - background-color: white; } + background-color: white; } + +QPushButton:hover{ + background-color: rgb(171, 211, 247); + effect = QtWidgets.QGraphicsDropShadowEffect(QPushButton) + effect.setOffset(0, 0) + effect.setBlurRadius(20) + effect.setColor(QColor(57, 219, 255)) + QPushButton.setGraphicsEffect(effect) +} - Обновить + Изменить @@ -514,42 +554,14 @@ - - - - - - - - 14 - - - - QLable { font-size: 14px; } - - - Четверг - - - - - - - - - - - 16777215 - 80 - - - - - - - - + + + + 240 + 370 + + @@ -582,45 +594,32 @@ - - - + + + + + 190 + 0 + + + - - - - 14 - - - - QLable { font-size: 14px; } - - - Суббота - - + - - - - + + + + 0 + 0 + + 16777215 - 80 + 170 - - - - - - - - - - 10 @@ -629,7 +628,7 @@ - Удалить предмет + Убрать предмет Qt::AlignCenter @@ -693,11 +692,6 @@ Сб - - - Вс - - @@ -710,7 +704,7 @@ - Любой + Все @@ -756,7 +750,92 @@ - + + + + 0 + 40 + + + + + -1 + + + + QPushButton { + padding:10px; + color: #fffff; + font-size: 18px; + border-radius: 10px; + border: 1px solid #3873d9; + background-color: white; } + +QPushButton:hover{ + background-color: rgb(171, 211, 247); + effect = QtWidgets.QGraphicsDropShadowEffect(QPushButton) + effect.setOffset(0, 0) + effect.setBlurRadius(20) + effect.setColor(QColor(57, 219, 255)) + QPushButton.setGraphicsEffect(effect) +} + + + Убрать + + + + + + + + + + + + + + 0 + 0 + + + + + 16777215 + 170 + + + + + 10 + 75 + true + + + + Удалить предмет + + + Qt::AlignCenter + + + + 6 + + + 9 + + + 9 + + + 9 + + + 9 + + + 0 @@ -770,14 +849,12 @@ 0 - 30 + 40 -1 - 50 - false @@ -787,7 +864,16 @@ font-size: 18px; border-radius: 10px; border: 1px solid #3873d9; - background-color: white; } + background-color: white; } + +QPushButton:hover{ + background-color: rgb(171, 211, 247); + effect = QtWidgets.QGraphicsDropShadowEffect(QPushButton) + effect.setOffset(0, 0) + effect.setBlurRadius(20) + effect.setColor(QColor(57, 219, 255)) + QPushButton.setGraphicsEffect(effect) +} Удалить @@ -797,27 +883,10 @@ - - - - QPushButton { - padding:10px; - color: #fffff; - font-size: 18px; - border-radius: 10px; - border: 1px solid #3873d9; - background-color: white; } - - - Обнуление - - - - Del_Space Add_Upd Saturday Friday @@ -825,321 +894,414 @@ Wednesday Tuesday Monday + Clear_Del - + Заметки - - - - - 10 - 430 - 681 - 251 - - - - - 10 - - - - 2 - - - - Сделать - - - - - - - - 10 - 10 - 211 - 51 - - - - QPushButton { - padding:10px; - color: #fffff; - font-size: 18px; - border-radius: 10px; - border: 1px solid #3873d9; - background-color: white; } - - - Выполнено - - - - - - 10 - 70 - 211 - 51 - - - - - 12 - - - - - - - 240 - 10 - 411 - 51 - - - - - - - - - - Добавить - - - - - - - - 230 - 10 - 411 - 111 - - - - - - - 10 - 10 - 211 - 51 - - - - QPushButton { - padding:10px; - color: #fffff; - font-size: 18px; - border-radius: 10px; - border: 1px solid #3873d9; - background-color: white; } - - - Добавить - - - - - - 10 - 70 - 211 - 51 - - - - - 12 - - - - - - - - - - Редактрировать - - - - - - - - 10 - 10 - 211 - 51 - - - - QPushButton { - padding:10px; - color: #fffff; - font-size: 18px; - border-radius: 10px; - border: 1px solid #3873d9; - background-color: white; } - - - Обновить - - - - - - 10 - 70 - 211 - 51 - - - - - 12 - - - - - - - 10 - 130 - 211 - 51 - - - - - - - 240 - 10 - 411 - 171 - - - - - - - - - - - - 710 - 430 - 261 - 251 - - - - - 10 - 75 - true - - - - Просмотр заметки - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - 10 - 20 - 241 - 221 - - - - - - 10 - 10 - 221 - 31 - + + + + 16777215 + 16777215 + + + + + + + + + 960 + 260 + + + + + 16777215 + 280 + + + + + + + + 675 + 0 + - - - За всё время - - - - - За месяц - - - - - За неделю - - - - - На опред. дату - - - - - На опред. время - - - - - - - 10 - 170 - 221 - 41 - + + + 16777215 + 250 + - -1 + 10 - - QPushButton { + + 2 + + + + Сделать + + + + + + + + 10 + 10 + 211 + 51 + + + + QPushButton { padding:10px; color: #fffff; font-size: 18px; border-radius: 10px; border: 1px solid #3873d9; - background-color: white; } - - - Показать - + background-color: white; } + +QPushButton:hover{ + background-color: rgb(171, 211, 247); + effect = QtWidgets.QGraphicsDropShadowEffect(QPushButton) + effect.setOffset(0, 0) + effect.setBlurRadius(20) + effect.setColor(QColor(57, 219, 255)) + QPushButton.setGraphicsEffect(effect) +} + + + Выполнено + + + + + + 10 + 70 + 211 + 51 + + + + + 12 + + + + + + + 240 + 10 + 411 + 51 + + + + + + + + + + Добавить + + + + + + + 233 + 0 + + + + + + 10 + 10 + 211 + 51 + + + + QPushButton { + padding:10px; + color: #fffff; + font-size: 18px; + border-radius: 10px; + border: 1px solid #3873d9; + background-color: white; } + +QPushButton:hover{ + background-color: rgb(171, 211, 247); + effect = QtWidgets.QGraphicsDropShadowEffect(QPushButton) + effect.setOffset(0, 0) + effect.setBlurRadius(20) + effect.setColor(QColor(57, 219, 255)) + QPushButton.setGraphicsEffect(effect) +} + + + Добавить + + + + + + 10 + 70 + 211 + 51 + + + + + 12 + + + + + + + + + + + + + Редактрировать + + + + + + + 233 + 0 + + + + + + 10 + 10 + 211 + 51 + + + + QPushButton { + padding:10px; + color: #fffff; + font-size: 18px; + border-radius: 10px; + border: 1px solid #3873d9; + background-color: white; } + +QPushButton:hover{ + background-color: rgb(171, 211, 247); + effect = QtWidgets.QGraphicsDropShadowEffect(QPushButton) + effect.setOffset(0, 0) + effect.setBlurRadius(20) + effect.setColor(QColor(57, 219, 255)) + QPushButton.setGraphicsEffect(effect) +} + + + Обновить + + + + + + 10 + 70 + 211 + 51 + + + + + 12 + + + + + + + 10 + 130 + 211 + 51 + + + + + + + + + + - - - - - - 10 - 10 - 961 - 401 - - - + + + + + + 260 + 250 + + + + + 260 + 250 + + + + + 10 + 75 + true + + + + Просмотр заметки + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + 10 + 20 + 241 + 221 + + + + QPushButton { + padding:10px; + color: #fffff; + font-size: 18px; + border-radius: 10px; + border: 1px solid #3873d9; + background-color: white; } + +QPushButton:before { + content:''; + position: absolute; + top: 0; + left: 0; + width: 0; + height: 42px; + background: rgba(255,255,255,0.3); + border-radius: 5px; + transition: all 2s ease; +} + +QPushButton:hover:before { + width: 100%; +} + + + + + 10 + 10 + 221 + 31 + + + + + 10 + 75 + true + + + + + За всё время + + + + + За месяц + + + + + За неделю + + + + + На опред. дату + + + + + На опред. время + + + + + + + 10 + 170 + 221 + 41 + + + + + -1 + + + + QPushButton { + padding:10px; + color: #fffff; + font-size: 18px; + border-radius: 10px; + border: 1px solid #3873d9; + background-color: white; } + +QPushButton:hover{ + background-color: rgb(171, 211, 247); + effect = QtWidgets.QGraphicsDropShadowEffect(QPushButton) + effect.setOffset(0, 0) + effect.setBlurRadius(20) + effect.setColor(QColor(57, 219, 255)) + QPushButton.setGraphicsEffect(effect) +} + + + Показать + + + + + + diff --git a/table.db b/table.db index dd0332a88ec060175da3358a888e7ee36875082a..77524f9c6a0a1d752098c6ebf95b7e0b46853758 100644 GIT binary patch delta 938 zcmZ`%O=uHA6n@)nqFK$nB-&4!ooCLX{6{ElUOg(qml8kG<4A?4chBrTE!!}PQYL&t*f0fbn``C1iqv3Rvb7YGPLj|exE;cgvIMqqCRrA%Mj!*vm|0gVMvBBU$&?PUNUC` z9vRN@1=7h=k|KX&&hV001LizmH}CQiK2(Fk$ZNvujG!izUQp;djS|nbI%GJ-SIjx` z_OC|Ps|edqc+Q;V1+pSmivF9k~1o%B_P9zs(8tq;~VBZs&|eKbAG=J zeN^14d50G)&KlWTrvh>`ioD?UiBykChEfRzF;$D|q+~K~H{dpY!=1dl_X9rIKC(aF z>1>q!QfByCBBNivn%D!d*Cu-%W8;}b+KEB1vvLnQ*dO)ybT{+{C>t0OhIqyc z-tdkoKJh(T-hRYMfpOY6PrN{;p>SIBlE4cJTy}%7UJrx1P&uu-?o})_38F?b6}kkS zn^Q*!2`;Z&zAz+6&u&8#U!-6{m|!|$l~+7Wc1wGPsq!t>Zd~|n$BleJL?t8glcX6Z zCdQE?^$Y&*TU4&a{Qpx qu=E_SI&I9z{@<^rv8CkZwbYloe{*y0AZ-`bmhb#vWLIYBSBk#|7)r1J