Add double click and require people have books assigned before double click
This commit is contained in:
23
main.py
23
main.py
@@ -4,7 +4,7 @@ import re
|
|||||||
import sys
|
import sys
|
||||||
from typing import cast
|
from typing import cast
|
||||||
|
|
||||||
from PyQt6.QtCore import Qt, pyqtSlot
|
from PyQt6.QtCore import QModelIndex, Qt, pyqtSlot
|
||||||
from PyQt6.QtGui import (
|
from PyQt6.QtGui import (
|
||||||
QAction,
|
QAction,
|
||||||
QFont,
|
QFont,
|
||||||
@@ -19,8 +19,6 @@ from PyQt6.QtWidgets import QApplication, QFileDialog, QMainWindow
|
|||||||
from lib import *
|
from lib import *
|
||||||
from ui.MainWindow import Ui_MainWindow
|
from ui.MainWindow import Ui_MainWindow
|
||||||
|
|
||||||
# from ui.testWindow import Ui_MainWindow
|
|
||||||
|
|
||||||
|
|
||||||
def query_error(query: QSqlQuery) -> None:
|
def query_error(query: QSqlQuery) -> None:
|
||||||
print(
|
print(
|
||||||
@@ -34,17 +32,28 @@ def query_error(query: QSqlQuery) -> None:
|
|||||||
raise Exception("SQL Error")
|
raise Exception("SQL Error")
|
||||||
|
|
||||||
|
|
||||||
|
class ModelOverride(QSqlQueryModel):
|
||||||
|
def flags(self, index: QModelIndex) -> Qt.ItemFlag:
|
||||||
|
itemFlags = super(ModelOverride, self).flags(index)
|
||||||
|
value = index.siblingAtColumn(3).data()
|
||||||
|
if not value or value < 1:
|
||||||
|
itemFlags &= ~(Qt.ItemFlag.ItemIsSelectable | Qt.ItemFlag.ItemIsEnabled)
|
||||||
|
return itemFlags
|
||||||
|
|
||||||
|
|
||||||
class MainWindow(QMainWindow, Ui_MainWindow):
|
class MainWindow(QMainWindow, Ui_MainWindow):
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
super(MainWindow, self).__init__()
|
super(MainWindow, self).__init__()
|
||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
model = QSqlQueryModel()
|
# model = QSqlQueryModel()
|
||||||
|
model = ModelOverride()
|
||||||
query = QSqlQuery("SELECT * FROM people ORDER BY name")
|
query = QSqlQuery("SELECT * FROM people ORDER BY name")
|
||||||
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(self.readAction)
|
self.ReadButton.clicked.connect(self.readAction)
|
||||||
self.bookBtn.clicked.connect(self.bookAction)
|
self.bookBtn.clicked.connect(self.bookAction)
|
||||||
|
self.peopleView.doubleClicked.connect(self.readAction)
|
||||||
self.createActions()
|
self.createActions()
|
||||||
self.show()
|
self.show()
|
||||||
return
|
return
|
||||||
@@ -148,7 +157,11 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
|||||||
return
|
return
|
||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def readAction(self) -> None:
|
@pyqtSlot(QModelIndex)
|
||||||
|
def readAction(self, index: QModelIndex | None = None) -> None:
|
||||||
|
if index:
|
||||||
|
person_id = index.siblingAtColumn(0).data()
|
||||||
|
else:
|
||||||
indexes = self.peopleView.selectedIndexes()
|
indexes = self.peopleView.selectedIndexes()
|
||||||
if len(indexes) < 1:
|
if len(indexes) < 1:
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user