Add Sound Module
This commit is contained in:
@@ -29,6 +29,7 @@ class SessionDialog(QDialog, Ui_Dialog):
|
||||
sessionStart = None
|
||||
sessionEnd = None
|
||||
blocks = QStandardItemModel()
|
||||
session_id = -1
|
||||
|
||||
def __init__(self) -> None:
|
||||
super(SessionDialog, self).__init__()
|
||||
@@ -112,41 +113,14 @@ class SessionDialog(QDialog, Ui_Dialog):
|
||||
self.sessionEnd = datetime.now()
|
||||
query = QSqlQuery()
|
||||
query.prepare(
|
||||
"INSERT INTO sessions "
|
||||
"(person_id, start, stop, notes) "
|
||||
"VALUES (:person_id, :start, :stop, :notes)"
|
||||
"UPDATE sessions "
|
||||
"SET start=:start , SET stop=:stop, SET notes=:notes "
|
||||
"WHERE sesion_id = :session_id"
|
||||
)
|
||||
query.bindValue(":person_id", self.person_id)
|
||||
query.bindValue(":session_id", self.session_id)
|
||||
query.bindValue(":start", self.sessionStart.isoformat())
|
||||
query.bindValue(":stop", self.sessionEnd.isoformat())
|
||||
query.bindValue(":notes", self.textEdit.toPlainText())
|
||||
if not query.exec():
|
||||
query_error(query)
|
||||
session_id = query.lastInsertId()
|
||||
model = self.wordView.model()
|
||||
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 = (
|
||||
"INSERT INTO session_block (session_id, section_id, block) VALUES "
|
||||
)
|
||||
parameters = ["(?,?,?)" for x in range(self.blocks.rowCount())]
|
||||
sql += ",".join(parameters)
|
||||
query.prepare(sql)
|
||||
for row in range(self.blocks.rowCount()):
|
||||
query.addBindValue(session_id)
|
||||
item = self.blocks.item(row)
|
||||
query.addBindValue(item.data(SessionDialog.SectionIdRole))
|
||||
query.addBindValue(item.data(SessionDialog.BlockRole))
|
||||
if not query.exec():
|
||||
query_error(query)
|
||||
super().accept()
|
||||
@@ -157,6 +131,19 @@ class SessionDialog(QDialog, Ui_Dialog):
|
||||
if state:
|
||||
if not self.sessionStart:
|
||||
self.sessionStart = datetime.now()
|
||||
if self.session_id <= 0:
|
||||
query = QSqlQuery()
|
||||
query.prepare(
|
||||
"INSERT INTO sessions "
|
||||
"(person_id, start) "
|
||||
"VALUES (:person_id, :start)"
|
||||
)
|
||||
query.bindValue(":person_id", self.person_id)
|
||||
query.bindValue(":start", self.sessionStart.isoformat())
|
||||
if not query.exec():
|
||||
query_error(query)
|
||||
self.session_id = query.lastInsertId()
|
||||
|
||||
self.startTime = datetime.now()
|
||||
self.timer.start()
|
||||
else:
|
||||
@@ -197,13 +184,13 @@ class SessionDialog(QDialog, Ui_Dialog):
|
||||
raise Exception(f"Word_id({word_id}) not found in DB")
|
||||
word = QStandardItem()
|
||||
word.setData(query.value("word"), Qt.ItemDataRole.DisplayRole)
|
||||
word.setData(query.value("word_id"), SessionDialog.WordIdRole)
|
||||
word.setData(word_id, SessionDialog.WordIdRole)
|
||||
word.setData(0, SessionDialog.WordImportantRole)
|
||||
model = self.wordView.model()
|
||||
matches = model.match(
|
||||
model.createIndex(0, 0),
|
||||
SessionDialog.WordIdRole,
|
||||
query.value("word_id"),
|
||||
word_id,
|
||||
1,
|
||||
Qt.MatchFlag.MatchExactly,
|
||||
)
|
||||
@@ -211,6 +198,15 @@ class SessionDialog(QDialog, Ui_Dialog):
|
||||
return
|
||||
self.wordView.model().appendRow(word)
|
||||
self.wordView.model().sort(0)
|
||||
query.prepare(
|
||||
"INSERT INTO session_word "
|
||||
"(session_id, word_id, important) "
|
||||
"VALUES (:session_id, :word_id, 0)"
|
||||
)
|
||||
query.bindValue(":session_id", self.session_id)
|
||||
query.bindValue(":word_id", word_id)
|
||||
if not query.exec():
|
||||
query_error(query)
|
||||
else:
|
||||
print(f"Not active: {word_id}")
|
||||
return
|
||||
@@ -255,4 +251,14 @@ class SessionDialog(QDialog, Ui_Dialog):
|
||||
)
|
||||
self.textBrowser.textCursor().insertBlock()
|
||||
self.textBrowser.ensureCursorVisible()
|
||||
query.prepare(
|
||||
"INSERT INTO session_block "
|
||||
"(session_id, section_id, block) "
|
||||
"VALUES (:session_id, :section_id, :block)"
|
||||
)
|
||||
query.bindValue(":session_id", self.session_id)
|
||||
query.bindValue(":section_id", section_id)
|
||||
query.bindValue(":block", block)
|
||||
if not query.exec():
|
||||
query_error(query)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user