checkpoint prior to class
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from PyQt6.QtCore import Qt, QTime, QTimer, pyqtSignal, pyqtSlot
|
||||
from PyQt6.QtCore import QModelIndex, Qt, QTime, QTimer, pyqtSignal, pyqtSlot
|
||||
from PyQt6.QtGui import (
|
||||
QBrush,
|
||||
QPalette,
|
||||
QStandardItem,
|
||||
QStandardItemModel,
|
||||
QTextBlockFormat,
|
||||
@@ -19,6 +21,7 @@ class SessionDialog(QDialog, Ui_Dialog):
|
||||
WordIdRole = Qt.ItemDataRole.UserRole
|
||||
SectionIdRole = Qt.ItemDataRole.UserRole + 1
|
||||
BlockRole = Qt.ItemDataRole.UserRole + 2
|
||||
WordImportantRole = Qt.ItemDataRole.UserRole + 3
|
||||
|
||||
timer = QTimer()
|
||||
startTime = datetime.now()
|
||||
@@ -37,6 +40,22 @@ class SessionDialog(QDialog, Ui_Dialog):
|
||||
#
|
||||
self.timer.timeout.connect(self.tickAction)
|
||||
self.activeBox.stateChanged.connect(self.activeAction)
|
||||
self.wordView.doubleClicked.connect(self.wordSelected)
|
||||
return
|
||||
|
||||
@pyqtSlot(QModelIndex)
|
||||
def wordSelected(self, index: QModelIndex) -> None:
|
||||
flag = index.data(SessionDialog.WordImportantRole)
|
||||
flag = 1 - flag
|
||||
model = index.model()
|
||||
model.setData(index, flag, SessionDialog.WordImportantRole)
|
||||
item = model.itemFromIndex(index)
|
||||
if flag:
|
||||
item.setForeground(Qt.GlobalColor.red)
|
||||
else:
|
||||
item.setForeground(
|
||||
self.wordView.palette().color(self.wordView.foregroundRole())
|
||||
)
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
@@ -63,6 +82,26 @@ class SessionDialog(QDialog, Ui_Dialog):
|
||||
self.wordView.model().clear()
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
def rejected(self) -> None:
|
||||
msg = QMessageBox()
|
||||
msg.setText("There is unsaved data.")
|
||||
msg.setInformativeText("Do you want to save the session?")
|
||||
msg.setStandardButtons(
|
||||
QMessageBox.StandardButton.Save
|
||||
| QMessageBox.StandardButton.Discard
|
||||
| QMessageBox.StandardButton.Cancel
|
||||
)
|
||||
ret = msg.exec()
|
||||
if ret == QMessageBox.StandardButton.Cancel:
|
||||
return
|
||||
if ret == QMessageBox.StandardButton.Discard:
|
||||
super().reject()
|
||||
return
|
||||
self.accept()
|
||||
self.done()
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
def accept(self) -> None:
|
||||
if not self.sessionStart:
|
||||
@@ -85,13 +124,16 @@ class SessionDialog(QDialog, Ui_Dialog):
|
||||
query_error(query)
|
||||
session_id = query.lastInsertId()
|
||||
model = self.wordView.model()
|
||||
sql = "INSERT INTO session_word (session_id,word_id) VALUES "
|
||||
parameters = ["(?,?)" for x in range(model.rowCount())]
|
||||
sql = "INSERT INTO session_word (session_id,word_id, important) VALUES "
|
||||
parameters = ["(?,?,?)" for x in range(model.rowCount())]
|
||||
sql += ", ".join(parameters)
|
||||
query.prepare(sql)
|
||||
for row in range(model.rowCount()):
|
||||
query.addBindValue(session_id)
|
||||
query.addBindValue(model.item(row).data(SessionDialog.WordIdRole))
|
||||
query.addBindValue(
|
||||
model.item(row).data(SessionDialog.WordImportantRole)
|
||||
)
|
||||
if not query.exec():
|
||||
query_error(query)
|
||||
sql = (
|
||||
@@ -156,6 +198,7 @@ class SessionDialog(QDialog, Ui_Dialog):
|
||||
word = QStandardItem()
|
||||
word.setData(query.value("word"), Qt.ItemDataRole.DisplayRole)
|
||||
word.setData(query.value("word_id"), SessionDialog.WordIdRole)
|
||||
word.setData(0, SessionDialog.WordImportantRole)
|
||||
model = self.wordView.model()
|
||||
matches = model.match(
|
||||
model.createIndex(0, 0),
|
||||
|
||||
Reference in New Issue
Block a user