I18N Code Work done.
This commit is contained in:
69
main.py
69
main.py
@@ -2,15 +2,9 @@
|
||||
#
|
||||
# TODO:
|
||||
#
|
||||
# Add definition to definition
|
||||
# Add book import dialog
|
||||
# Reading scroll with speed control
|
||||
# Move controls out of reading window.
|
||||
# Ability to edit text with updates to word-section links
|
||||
# Need to be able to place a visible cursor in text.
|
||||
# Scroll to cursor
|
||||
# XXX:
|
||||
# Scrolling is messed up. Need a way of marking current line.
|
||||
#
|
||||
import os
|
||||
import re
|
||||
@@ -19,6 +13,8 @@ from datetime import datetime, timedelta
|
||||
from typing import Optional
|
||||
|
||||
from PyQt6.QtCore import (
|
||||
QCoreApplication,
|
||||
QEvent,
|
||||
QModelIndex,
|
||||
QResource,
|
||||
Qt,
|
||||
@@ -47,30 +43,26 @@ from lib import *
|
||||
from lib.preferences import Preferences
|
||||
from ui.MainWindow import Ui_MainWindow
|
||||
|
||||
translate = QCoreApplication.translate
|
||||
|
||||
|
||||
def query_error(query: QSqlQuery) -> None:
|
||||
print(
|
||||
"SQL Error:\n{}\n{}\n{}:{}".format(
|
||||
translate("MainWindow", "SQL Error:\n")
|
||||
+ "{}\n{}\n{}:{}".format(
|
||||
query.executedQuery(),
|
||||
query.boundValues(),
|
||||
query.lastError().type(),
|
||||
query.lastError().text(),
|
||||
)
|
||||
)
|
||||
raise Exception("SQL Error")
|
||||
raise Exception(translate("MainWindow", "SQL Error"))
|
||||
|
||||
|
||||
class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
def __init__(self) -> None:
|
||||
super(MainWindow, self).__init__()
|
||||
self.setupUi(self)
|
||||
#
|
||||
# Setup resources
|
||||
#
|
||||
if not QResource.registerResource(
|
||||
os.path.join(os.path.dirname(__file__), "ui/resources.rcc"), "/"
|
||||
):
|
||||
raise Exception("Unable to register resources.rcc")
|
||||
|
||||
model = QSqlQueryModel()
|
||||
query = QSqlQuery("SELECT * FROM people ORDER BY name")
|
||||
@@ -153,7 +145,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
|
||||
@pyqtSlot()
|
||||
def editBook(self) -> None:
|
||||
print("Edit Book")
|
||||
print(self.tr("Edit Book"))
|
||||
return
|
||||
|
||||
session = None
|
||||
@@ -176,6 +168,15 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
self.dlg.raise_()
|
||||
return
|
||||
|
||||
#
|
||||
# Events
|
||||
#
|
||||
def changeEvent(self, event: Optional[QEvent]) -> None:
|
||||
assert event is not None
|
||||
if event.type() == QEvent.Type.LanguageChange:
|
||||
self.retranslateUi(self)
|
||||
return
|
||||
|
||||
|
||||
SQL_CMDS = [
|
||||
"PRAGMA foreign_keys=ON",
|
||||
@@ -266,7 +267,7 @@ def schema_update(db: QSqlDatabase) -> None:
|
||||
continue
|
||||
print(old.lower())
|
||||
print(create_cmd.lower())
|
||||
print(f"Updating: {table_name}")
|
||||
print(translate("MainWindow", "Updating: ") + f"{table_name}")
|
||||
|
||||
# Step 1 turn off foreign key constraints
|
||||
if not query.exec("PRAGMA foreign_keys=OFF"):
|
||||
@@ -312,30 +313,24 @@ def main() -> int:
|
||||
db.setDatabaseName("twel.db")
|
||||
db.open()
|
||||
app = QApplication(sys.argv)
|
||||
#
|
||||
# Setup resources
|
||||
#
|
||||
if not QResource.registerResource(
|
||||
os.path.join(os.path.dirname(__file__), "ui/resources.rcc"), "/"
|
||||
):
|
||||
raise Exception(
|
||||
translate("MainWindow", "Unable to register resources.rcc")
|
||||
)
|
||||
schema_update(db)
|
||||
Preferences()
|
||||
window: QMainWindow = MainWindow()
|
||||
return app.exec()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
outOfDate = []
|
||||
for fileName in os.listdir("ui"):
|
||||
if not fileName.endswith(".py"):
|
||||
continue
|
||||
uiName = "ui/" + fileName[:-3] + ".ui"
|
||||
rccName = "ui/" + fileName[:-3] + ".qrc"
|
||||
if not os.path.isfile(uiName) and not os.path.isfile(rccName):
|
||||
outOfDate.append(fileName)
|
||||
continue
|
||||
if os.path.isfile(uiName) and os.path.getmtime(
|
||||
uiName
|
||||
) > os.path.getmtime("ui/" + fileName):
|
||||
outOfDate.append(fileName)
|
||||
if os.path.isfile(rccName) and os.path.getmtime(
|
||||
rccName
|
||||
) > os.path.getmtime("ui/" + fileName):
|
||||
outOfDate.append(fileName)
|
||||
if len(outOfDate) > 0:
|
||||
print(f"UI out of date: {', '.join(outOfDate)}")
|
||||
sys.exit(1)
|
||||
#
|
||||
# XXX - Update the Makefile so that we can run a `make -q` will
|
||||
# report back if make needs to be run.
|
||||
#
|
||||
sys.exit(main())
|
||||
|
||||
Reference in New Issue
Block a user