clean up new UI layouts

This commit is contained in:
Christopher T. Johnson
2023-11-17 11:04:38 -05:00
parent 82f7604166
commit ba8d8fa3f1

39
main.py
View File

@@ -14,7 +14,13 @@ from PyQt6.QtGui import (
QTextListFormat, QTextListFormat,
) )
from PyQt6.QtSql import QSqlDatabase, QSqlQuery, QSqlQueryModel 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 lib import *
from ui.MainWindow import Ui_MainWindow from ui.MainWindow import Ui_MainWindow
@@ -41,12 +47,19 @@ class ModelOverride(QSqlQueryModel):
return itemFlags return itemFlags
value = index.siblingAtColumn(3).data() value = index.siblingAtColumn(3).data()
if not value or value < 1: if not value or value < 1:
itemFlags &= ~(Qt.ItemFlag.ItemIsSelectable | Qt.ItemFlag.ItemIsEnabled) itemFlags &= ~(
Qt.ItemFlag.ItemIsSelectable | Qt.ItemFlag.ItemIsEnabled
)
return itemFlags return itemFlags
@pyqtSlot() @pyqtSlot()
def toggle(self) -> None: def toggle(self) -> None:
self.enableFlag = not self.enableFlag self.enableFlag = not self.enableFlag
sender = cast(QPushButton, self.sender())
if self.enableFlag:
sender.setText("Disable")
else:
sender.setText("Enable")
return return
@@ -59,7 +72,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
model.setQuery(query) model.setQuery(query)
self.peopleView.setModel(model) self.peopleView.setModel(model)
self.peopleView.setModelColumn(1) self.peopleView.setModelColumn(1)
self.ReadButton.clicked.connect(model.toggle) self.toggleBtn.clicked.connect(model.toggle)
self.bookBtn.clicked.connect(self.bookAction) self.bookBtn.clicked.connect(self.bookAction)
self.peopleView.doubleClicked.connect(self.readAction) self.peopleView.doubleClicked.connect(self.readAction)
self.actionQuit.triggered.connect(self.close) self.actionQuit.triggered.connect(self.close)
@@ -99,7 +112,8 @@ class MainWindow(QMainWindow, Ui_MainWindow):
query_error(query) query_error(query)
if not query.next(): if not query.next():
query.prepare( 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) query.bindValue(":book_id", book_id)
if not query.exec(): if not query.exec():
@@ -117,7 +131,8 @@ class MainWindow(QMainWindow, Ui_MainWindow):
if not query.exec(): if not query.exec():
query_error(query) query_error(query)
query.prepare( 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(":book_id", book_id)
query.bindValue(":person_id", person_id) query.bindValue(":person_id", person_id)
@@ -247,7 +262,11 @@ def schema_update(db: QSqlDatabase) -> None:
if matches: if matches:
table_name = matches.group(2) table_name = matches.group(2)
create_cmd = ( create_cmd = (
matches.group(1) + '"' + matches.group(2) + '"' + matches.group(3) matches.group(1)
+ '"'
+ matches.group(2)
+ '"'
+ matches.group(3)
) )
else: else:
raise AttributeError(f"No match found: {create_cmd}") 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): if not query.exec("DROP TABLE " + table_name):
query_error(query) query_error(query)
# step 6 rename new table to old table # 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) query_error(query)
# step 8 create indexes, triggers, and views # step 8 create indexes, triggers, and views
@@ -321,7 +342,9 @@ if __name__ == "__main__":
if not fileName.endswith(".py"): if not fileName.endswith(".py"):
continue continue
uiName = fileName[:-3] + ".ui" 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) outOfDate.append(fileName)
if len(outOfDate) > 0: if len(outOfDate) > 0:
print(f"UI out of date: {', '.join(outOfDate)}") print(f"UI out of date: {', '.join(outOfDate)}")