From ba8d8fa3f16585df17604890c25aab44b775b7e4 Mon Sep 17 00:00:00 2001 From: "Christopher T. Johnson" Date: Fri, 17 Nov 2023 11:04:38 -0500 Subject: [PATCH] clean up new UI layouts --- main.py | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index 0b9c227..7297a54 100755 --- a/main.py +++ b/main.py @@ -14,7 +14,13 @@ from PyQt6.QtGui import ( QTextListFormat, ) from PyQt6.QtSql import QSqlDatabase, QSqlQuery, QSqlQueryModel -from PyQt6.QtWidgets import QApplication, QFileDialog, QMainWindow, QMessageBox +from PyQt6.QtWidgets import ( + QApplication, + QFileDialog, + QMainWindow, + QMessageBox, + QPushButton, +) from lib import * from ui.MainWindow import Ui_MainWindow @@ -41,12 +47,19 @@ class ModelOverride(QSqlQueryModel): return itemFlags value = index.siblingAtColumn(3).data() if not value or value < 1: - itemFlags &= ~(Qt.ItemFlag.ItemIsSelectable | Qt.ItemFlag.ItemIsEnabled) + itemFlags &= ~( + Qt.ItemFlag.ItemIsSelectable | Qt.ItemFlag.ItemIsEnabled + ) return itemFlags @pyqtSlot() def toggle(self) -> None: self.enableFlag = not self.enableFlag + sender = cast(QPushButton, self.sender()) + if self.enableFlag: + sender.setText("Disable") + else: + sender.setText("Enable") return @@ -59,7 +72,7 @@ class MainWindow(QMainWindow, Ui_MainWindow): model.setQuery(query) self.peopleView.setModel(model) self.peopleView.setModelColumn(1) - self.ReadButton.clicked.connect(model.toggle) + self.toggleBtn.clicked.connect(model.toggle) self.bookBtn.clicked.connect(self.bookAction) self.peopleView.doubleClicked.connect(self.readAction) self.actionQuit.triggered.connect(self.close) @@ -99,7 +112,8 @@ class MainWindow(QMainWindow, Ui_MainWindow): query_error(query) if not query.next(): query.prepare( - "SELECT * FROM sections WHERE sequence = 0 " "AND book_id = :book_id" + "SELECT * FROM sections WHERE sequence = 0 " + "AND book_id = :book_id" ) query.bindValue(":book_id", book_id) if not query.exec(): @@ -117,7 +131,8 @@ class MainWindow(QMainWindow, Ui_MainWindow): if not query.exec(): query_error(query) query.prepare( - "UPDATE people SET book_id = :book_id " "WHERE person_id = :person_id" + "UPDATE people SET book_id = :book_id " + "WHERE person_id = :person_id" ) query.bindValue(":book_id", book_id) query.bindValue(":person_id", person_id) @@ -247,7 +262,11 @@ def schema_update(db: QSqlDatabase) -> None: if matches: table_name = matches.group(2) create_cmd = ( - matches.group(1) + '"' + matches.group(2) + '"' + matches.group(3) + matches.group(1) + + '"' + + matches.group(2) + + '"' + + matches.group(3) ) else: raise AttributeError(f"No match found: {create_cmd}") @@ -291,7 +310,9 @@ def schema_update(db: QSqlDatabase) -> None: if not query.exec("DROP TABLE " + table_name): query_error(query) # step 6 rename new table to old table - if not query.exec("ALTER TABLE " + new_table_name + " RENAME TO " + table_name): + if not query.exec( + "ALTER TABLE " + new_table_name + " RENAME TO " + table_name + ): query_error(query) # step 8 create indexes, triggers, and views @@ -321,7 +342,9 @@ if __name__ == "__main__": if not fileName.endswith(".py"): continue uiName = fileName[:-3] + ".ui" - if os.path.getmtime("ui/" + uiName) > os.path.getmtime("ui/" + fileName): + if os.path.getmtime("ui/" + uiName) > os.path.getmtime( + "ui/" + fileName + ): outOfDate.append(fileName) if len(outOfDate) > 0: print(f"UI out of date: {', '.join(outOfDate)}")