54 lines
1.4 KiB
Python
54 lines
1.4 KiB
Python
#!/usr/bin/env python3
|
|
import os
|
|
import sys
|
|
from typing import cast
|
|
|
|
from PyQt6.QtCore import QResource
|
|
from PyQt6.QtGui import QFontDatabase
|
|
from PyQt6.QtSql import QSqlDatabase, QSqlQuery
|
|
from PyQt6.QtWidgets import QApplication
|
|
|
|
from lib import DefinitionArea, Word
|
|
from lib.sounds import SoundOff
|
|
from lib.utils import query_error
|
|
from lib.words import Definition
|
|
|
|
|
|
def main() -> int:
|
|
db = QSqlDatabase()
|
|
db = db.addDatabase("QSQLITE")
|
|
db.setDatabaseName("test.db")
|
|
if not db.open():
|
|
raise Exception(db.lastError())
|
|
app = QApplication(sys.argv)
|
|
#
|
|
# Setup resources
|
|
#
|
|
if not QResource.registerResource(
|
|
os.path.join(os.path.dirname(__file__), "ui/resources.rcc"), "/"
|
|
):
|
|
raise Exception("Unable to register resources.rcc")
|
|
QFontDatabase.addApplicationFont(
|
|
":/fonts/opendyslexic/OpenDyslexic-Regular.otf"
|
|
)
|
|
query = QSqlQuery()
|
|
if not query.exec(
|
|
"CREATE TABLE IF NOT EXISTS words "
|
|
"(word_id INTEGER PRIMARY KEY AUTOINCREMENT, "
|
|
"word TEXT, source TEXT, definition TEXT)"
|
|
):
|
|
query_error(query)
|
|
|
|
word = Word("boat")
|
|
snd = SoundOff()
|
|
widget = DefinitionArea(word) # xnoqa: F841
|
|
d = cast(Definition,widget.widget())
|
|
assert d is not None
|
|
d.pronounce.connect(snd.playSound)
|
|
widget.show()
|
|
return app.exec()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|