New Dialogs
This commit is contained in:
@@ -1,2 +1,4 @@
|
||||
from .books import Book
|
||||
from .read import EditDialog
|
||||
from .session import SessionDialog
|
||||
from .person import PersonDialog
|
||||
|
||||
12
lib/person.py
Normal file
12
lib/person.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from main import query_error
|
||||
from ui.PeopleDialog import Ui_Dialog
|
||||
from PyQt6.QtCore import Qt, pyqtSlot
|
||||
from PyQt6.QtSql import QSqlQuery
|
||||
from PyQt6.QtWidgets import QDialog
|
||||
|
||||
class PersonDialog(QDialog, Ui_Dialog):
|
||||
def __init__(self,*args, **kwargs):
|
||||
super(PersonDialog, self).__init__(*args, **kwargs)
|
||||
self.setupUi(self)
|
||||
self.show()
|
||||
return
|
||||
102
lib/session.py
Normal file
102
lib/session.py
Normal file
@@ -0,0 +1,102 @@
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from PyQt6.QtCore import Qt, QTime, QTimer, pyqtSignal, pyqtSlot
|
||||
from PyQt6.QtGui import QStandardItem, QStandardItemModel, QTextCursor
|
||||
from PyQt6.QtSql import QSqlQuery
|
||||
from PyQt6.QtWidgets import QDialog
|
||||
|
||||
from main import query_error
|
||||
from ui.SessionDialog import Ui_Dialog
|
||||
|
||||
|
||||
class SessionDialog(QDialog, Ui_Dialog):
|
||||
timer = QTimer()
|
||||
startTime = datetime.now()
|
||||
totalTime = 0 # seconds
|
||||
|
||||
def __init__(self) -> None:
|
||||
super(SessionDialog, self).__init__()
|
||||
self.setupUi(self)
|
||||
self.wordView.setModel(QStandardItemModel())
|
||||
self.wordView.setWrapping(True)
|
||||
#
|
||||
# Connections
|
||||
#
|
||||
self.timer.timeout.connect(self.tickAction)
|
||||
self.activeBox.stateChanged.connect(self.activeAction)
|
||||
return
|
||||
|
||||
@pyqtSlot(int)
|
||||
def setPerson(self, person_id) -> None:
|
||||
query = QSqlQuery()
|
||||
query.prepare("SELECT * FROM people " "WHERE person_id = :person_id")
|
||||
query.bindValue(":person_id", person_id)
|
||||
if not query.exec():
|
||||
query_error(query)
|
||||
if not query.next():
|
||||
raise Exception(f"Bad person_id: {person_id}")
|
||||
self.nameLbl.setText(query.value("name"))
|
||||
self.totalTime = timedelta()
|
||||
return
|
||||
|
||||
@pyqtSlot(int)
|
||||
def activeAction(self, state: int) -> None:
|
||||
if state:
|
||||
self.startTime = datetime.now()
|
||||
self.timer.start()
|
||||
else:
|
||||
self.totalTime = self.totalTime + (datetime.now() - self.startTime)
|
||||
self.timer.stop()
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
def timerAction(self) -> None:
|
||||
if self.activeBox.isChecked(): # we are stopping
|
||||
self.activeBox.setChecked(False)
|
||||
self.sender().setText("Start")
|
||||
return
|
||||
self.timer.setInterval(1000)
|
||||
self.sender().setText("Stop")
|
||||
self.activeBox.setChecked(True)
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
def tickAction(self) -> None:
|
||||
delta = self.totalTime + (datetime.now() - self.startTime)
|
||||
seconds = delta.seconds % 60
|
||||
minutes = int(delta.seconds / 60) % 60
|
||||
hours = int(delta.seconds / 3600)
|
||||
self.timerLbl.setText(f"{hours:02d}:{minutes:02d}:{seconds:02d}")
|
||||
return
|
||||
|
||||
@pyqtSlot(int)
|
||||
def addWord(self, word_id: int) -> None:
|
||||
if self.activeBox.isChecked():
|
||||
query = QSqlQuery()
|
||||
query.prepare("SELECT * FROM words " "WHERE word_id = :word_id")
|
||||
query.bindValue(":word_id", word_id)
|
||||
if not query.exec():
|
||||
query_error(query)
|
||||
if not query.next():
|
||||
raise Exception(f"Word_id({word_id}) not found in DB")
|
||||
word = QStandardItem()
|
||||
word.setData(query.value("word"), Qt.ItemDataRole.DisplayRole)
|
||||
word_id = QStandardItem()
|
||||
word_id.setData(
|
||||
query.value("word_id"), Qt.ItemDataRole.UserRole + 1
|
||||
)
|
||||
model = self.wordView.model()
|
||||
matches = model.match(
|
||||
model.createIndex(0, 1),
|
||||
Qt.ItemDataRole.UserRole + 1,
|
||||
query.value("word_id"),
|
||||
1,
|
||||
Qt.MatchFlag.MatchExactly,
|
||||
)
|
||||
if len(matches) > 0:
|
||||
return
|
||||
self.wordView.model().appendRow([word, word_id])
|
||||
self.wordView.model().sort(0)
|
||||
else:
|
||||
print(f"Not active: {word_id}")
|
||||
return
|
||||
59
ui/PeopleDialog.py
Normal file
59
ui/PeopleDialog.py
Normal file
@@ -0,0 +1,59 @@
|
||||
# Form implementation generated from reading ui file 'ui/PeopleDialog.ui'
|
||||
#
|
||||
# Created by: PyQt6 UI code generator 6.6.0
|
||||
#
|
||||
# WARNING: Any manual changes made to this file will be lost when pyuic6 is
|
||||
# run again. Do not edit this file unless you know what you are doing.
|
||||
|
||||
|
||||
from PyQt6 import QtCore, QtGui, QtWidgets
|
||||
|
||||
|
||||
class Ui_Dialog(object):
|
||||
def setupUi(self, Dialog):
|
||||
Dialog.setObjectName("Dialog")
|
||||
Dialog.resize(542, 219)
|
||||
self.formLayout = QtWidgets.QFormLayout(Dialog)
|
||||
self.formLayout.setObjectName("formLayout")
|
||||
self.label = QtWidgets.QLabel(parent=Dialog)
|
||||
self.label.setObjectName("label")
|
||||
self.formLayout.setWidget(0, QtWidgets.QFormLayout.ItemRole.LabelRole, self.label)
|
||||
self.nameEdit = QtWidgets.QLineEdit(parent=Dialog)
|
||||
self.nameEdit.setObjectName("nameEdit")
|
||||
self.formLayout.setWidget(0, QtWidgets.QFormLayout.ItemRole.FieldRole, self.nameEdit)
|
||||
self.label_2 = QtWidgets.QLabel(parent=Dialog)
|
||||
self.label_2.setObjectName("label_2")
|
||||
self.formLayout.setWidget(1, QtWidgets.QFormLayout.ItemRole.LabelRole, self.label_2)
|
||||
self.orgEdit = QtWidgets.QLineEdit(parent=Dialog)
|
||||
self.orgEdit.setObjectName("orgEdit")
|
||||
self.formLayout.setWidget(1, QtWidgets.QFormLayout.ItemRole.FieldRole, self.orgEdit)
|
||||
self.label_3 = QtWidgets.QLabel(parent=Dialog)
|
||||
self.label_3.setObjectName("label_3")
|
||||
self.formLayout.setWidget(2, QtWidgets.QFormLayout.ItemRole.LabelRole, self.label_3)
|
||||
self.bookCombo = QtWidgets.QComboBox(parent=Dialog)
|
||||
self.bookCombo.setObjectName("bookCombo")
|
||||
self.formLayout.setWidget(2, QtWidgets.QFormLayout.ItemRole.FieldRole, self.bookCombo)
|
||||
self.label_4 = QtWidgets.QLabel(parent=Dialog)
|
||||
self.label_4.setObjectName("label_4")
|
||||
self.formLayout.setWidget(3, QtWidgets.QFormLayout.ItemRole.LabelRole, self.label_4)
|
||||
self.sectionCombo = QtWidgets.QComboBox(parent=Dialog)
|
||||
self.sectionCombo.setObjectName("sectionCombo")
|
||||
self.formLayout.setWidget(3, QtWidgets.QFormLayout.ItemRole.FieldRole, self.sectionCombo)
|
||||
self.buttonBox = QtWidgets.QDialogButtonBox(parent=Dialog)
|
||||
self.buttonBox.setOrientation(QtCore.Qt.Orientation.Horizontal)
|
||||
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.StandardButton.Cancel|QtWidgets.QDialogButtonBox.StandardButton.Ok)
|
||||
self.buttonBox.setObjectName("buttonBox")
|
||||
self.formLayout.setWidget(4, QtWidgets.QFormLayout.ItemRole.SpanningRole, self.buttonBox)
|
||||
|
||||
self.retranslateUi(Dialog)
|
||||
self.buttonBox.accepted.connect(Dialog.accept) # type: ignore
|
||||
self.buttonBox.rejected.connect(Dialog.reject) # type: ignore
|
||||
QtCore.QMetaObject.connectSlotsByName(Dialog)
|
||||
|
||||
def retranslateUi(self, Dialog):
|
||||
_translate = QtCore.QCoreApplication.translate
|
||||
Dialog.setWindowTitle(_translate("Dialog", "People"))
|
||||
self.label.setText(_translate("Dialog", "Name"))
|
||||
self.label_2.setText(_translate("Dialog", "Organization"))
|
||||
self.label_3.setText(_translate("Dialog", "Book"))
|
||||
self.label_4.setText(_translate("Dialog", "Section"))
|
||||
104
ui/PeopleDialog.ui
Normal file
104
ui/PeopleDialog.ui
Normal file
@@ -0,0 +1,104 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Dialog</class>
|
||||
<widget class="QDialog" name="Dialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>542</width>
|
||||
<height>219</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>People</string>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="nameEdit"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Organization</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="orgEdit"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Book</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QComboBox" name="bookCombo"/>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Section</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QComboBox" name="sectionCombo"/>
|
||||
</item>
|
||||
<item row="4" column="0" colspan="2">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>Dialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>Dialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
73
ui/SessionDialog.py
Normal file
73
ui/SessionDialog.py
Normal file
@@ -0,0 +1,73 @@
|
||||
# Form implementation generated from reading ui file 'ui/SessionDialog.ui'
|
||||
#
|
||||
# Created by: PyQt6 UI code generator 6.6.0
|
||||
#
|
||||
# WARNING: Any manual changes made to this file will be lost when pyuic6 is
|
||||
# run again. Do not edit this file unless you know what you are doing.
|
||||
|
||||
|
||||
from PyQt6 import QtCore, QtGui, QtWidgets
|
||||
|
||||
|
||||
class Ui_Dialog(object):
|
||||
def setupUi(self, Dialog):
|
||||
Dialog.setObjectName("Dialog")
|
||||
Dialog.resize(621, 569)
|
||||
self.verticalLayout_3 = QtWidgets.QVBoxLayout(Dialog)
|
||||
self.verticalLayout_3.setObjectName("verticalLayout_3")
|
||||
self.nameLbl = QtWidgets.QLabel(parent=Dialog)
|
||||
self.nameLbl.setObjectName("nameLbl")
|
||||
self.verticalLayout_3.addWidget(self.nameLbl)
|
||||
self.horizontalLayout = QtWidgets.QHBoxLayout()
|
||||
self.horizontalLayout.setObjectName("horizontalLayout")
|
||||
self.label_2 = QtWidgets.QLabel(parent=Dialog)
|
||||
self.label_2.setObjectName("label_2")
|
||||
self.horizontalLayout.addWidget(self.label_2)
|
||||
self.timerLbl = QtWidgets.QLabel(parent=Dialog)
|
||||
self.timerLbl.setObjectName("timerLbl")
|
||||
self.horizontalLayout.addWidget(self.timerLbl)
|
||||
spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Minimum)
|
||||
self.horizontalLayout.addItem(spacerItem)
|
||||
self.activeBox = QtWidgets.QCheckBox(parent=Dialog)
|
||||
self.activeBox.setEnabled(True)
|
||||
self.activeBox.setObjectName("activeBox")
|
||||
self.horizontalLayout.addWidget(self.activeBox)
|
||||
self.verticalLayout_3.addLayout(self.horizontalLayout)
|
||||
self.verticalLayout = QtWidgets.QVBoxLayout()
|
||||
self.verticalLayout.setObjectName("verticalLayout")
|
||||
self.label = QtWidgets.QLabel(parent=Dialog)
|
||||
self.label.setObjectName("label")
|
||||
self.verticalLayout.addWidget(self.label)
|
||||
self.wordView = QtWidgets.QListView(parent=Dialog)
|
||||
self.wordView.setObjectName("wordView")
|
||||
self.verticalLayout.addWidget(self.wordView)
|
||||
self.verticalLayout_3.addLayout(self.verticalLayout)
|
||||
self.verticalLayout_2 = QtWidgets.QVBoxLayout()
|
||||
self.verticalLayout_2.setObjectName("verticalLayout_2")
|
||||
self.label_4 = QtWidgets.QLabel(parent=Dialog)
|
||||
self.label_4.setObjectName("label_4")
|
||||
self.verticalLayout_2.addWidget(self.label_4)
|
||||
self.textEdit = QtWidgets.QTextEdit(parent=Dialog)
|
||||
self.textEdit.setObjectName("textEdit")
|
||||
self.verticalLayout_2.addWidget(self.textEdit)
|
||||
self.verticalLayout_3.addLayout(self.verticalLayout_2)
|
||||
self.buttonBox = QtWidgets.QDialogButtonBox(parent=Dialog)
|
||||
self.buttonBox.setOrientation(QtCore.Qt.Orientation.Horizontal)
|
||||
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.StandardButton.Cancel|QtWidgets.QDialogButtonBox.StandardButton.Ok)
|
||||
self.buttonBox.setObjectName("buttonBox")
|
||||
self.verticalLayout_3.addWidget(self.buttonBox)
|
||||
|
||||
self.retranslateUi(Dialog)
|
||||
self.buttonBox.accepted.connect(Dialog.accept) # type: ignore
|
||||
self.buttonBox.rejected.connect(Dialog.reject) # type: ignore
|
||||
QtCore.QMetaObject.connectSlotsByName(Dialog)
|
||||
|
||||
def retranslateUi(self, Dialog):
|
||||
_translate = QtCore.QCoreApplication.translate
|
||||
Dialog.setWindowTitle(_translate("Dialog", "Session"))
|
||||
self.nameLbl.setText(_translate("Dialog", "nameLbl"))
|
||||
self.label_2.setText(_translate("Dialog", "Session Timer"))
|
||||
self.timerLbl.setText(_translate("Dialog", "00:00:00"))
|
||||
self.activeBox.setText(_translate("Dialog", "Active"))
|
||||
self.label.setText(_translate("Dialog", "Words"))
|
||||
self.label_4.setText(_translate("Dialog", "Notes"))
|
||||
140
ui/SessionDialog.ui
Normal file
140
ui/SessionDialog.ui
Normal file
@@ -0,0 +1,140 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Dialog</class>
|
||||
<widget class="QDialog" name="Dialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>621</width>
|
||||
<height>569</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Session</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="QLabel" name="nameLbl">
|
||||
<property name="text">
|
||||
<string>nameLbl</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Session Timer</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="timerLbl">
|
||||
<property name="text">
|
||||
<string>00:00:00</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="activeBox">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Active</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Words</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QListView" name="wordView"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Notes</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTextEdit" name="textEdit"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>Dialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>Dialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user