Setup LSP and clear all lint
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
from .utils import query_error
|
||||
from .books import Book
|
||||
from .person import PersonDialog
|
||||
from .read import ReadDialog
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import json
|
||||
import os
|
||||
|
||||
import xml.dom.minidom
|
||||
from typing import Dict, List, cast
|
||||
|
||||
from PyQt6.QtCore import QCoreApplication
|
||||
from PyQt6.QtSql import QSqlQuery
|
||||
|
||||
from main import query_error
|
||||
from lib import query_error
|
||||
|
||||
|
||||
class Book:
|
||||
@@ -130,7 +129,6 @@ class Book:
|
||||
query.bindValue(":content", section)
|
||||
if not query.exec():
|
||||
query_error(query)
|
||||
section_id = query.lastInsertId()
|
||||
return book_id
|
||||
|
||||
def parse_section(self, src: str, href: str) -> None:
|
||||
|
||||
@@ -2,7 +2,7 @@ import json
|
||||
import os
|
||||
import secrets
|
||||
import smtplib
|
||||
from datetime import datetime, timedelta
|
||||
from datetime import datetime
|
||||
from email import policy
|
||||
from email.message import EmailMessage
|
||||
from html.parser import HTMLParser
|
||||
@@ -10,13 +10,12 @@ from io import StringIO
|
||||
from typing import Any, List
|
||||
|
||||
import css_inline
|
||||
from PyQt6.QtCore import QResource, QSize, Qt, QUrl, pyqtSlot
|
||||
from lib import query_error
|
||||
from PyQt6.QtCore import QResource, Qt, QUrl, pyqtSlot
|
||||
from PyQt6.QtGui import QStandardItem, QStandardItemModel
|
||||
from PyQt6.QtMultimedia import QMediaDevices, QSoundEffect
|
||||
from PyQt6.QtSql import QSqlQuery, QSqlQueryModel
|
||||
from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QStyledItemDelegate
|
||||
|
||||
from main import query_error
|
||||
from PyQt6.QtWidgets import QDialog, QDialogButtonBox
|
||||
from ui.PersonDialog import Ui_PersonDialog
|
||||
|
||||
|
||||
@@ -51,7 +50,7 @@ class blockHandler(HTMLParser):
|
||||
return
|
||||
|
||||
def handle_starttag(self, tag: str, attrs: Any) -> None:
|
||||
if not tag in self.tags:
|
||||
if tag not in self.tags:
|
||||
return
|
||||
self.active += 1
|
||||
if tag in self.space:
|
||||
@@ -60,7 +59,7 @@ class blockHandler(HTMLParser):
|
||||
return
|
||||
|
||||
def handle_endtag(self, tag: str) -> None:
|
||||
if not tag in self.tags:
|
||||
if tag not in self.tags:
|
||||
return
|
||||
self.active -= 1
|
||||
self.text += f"</{tag}>"
|
||||
@@ -457,7 +456,6 @@ class PersonDialog(QDialog, Ui_PersonDialog):
|
||||
query.bindValue(":session_id", session_id)
|
||||
if not query.exec():
|
||||
query_error(query)
|
||||
first = True
|
||||
if not query.next():
|
||||
return ""
|
||||
html += "<h3>" + self.tr("Notes") + "</h3>\n"
|
||||
|
||||
39
lib/read.py
39
lib/read.py
@@ -1,42 +1,18 @@
|
||||
import json
|
||||
import re
|
||||
from typing import Any, Dict, List, Optional, cast
|
||||
|
||||
import requests
|
||||
from PyQt6.QtCore import (
|
||||
QFile,
|
||||
QIODeviceBase,
|
||||
QPoint,
|
||||
QRect,
|
||||
QResource,
|
||||
Qt,
|
||||
QTimer,
|
||||
QUrl,
|
||||
pyqtSignal,
|
||||
pyqtSlot,
|
||||
)
|
||||
from PyQt6.QtGui import (
|
||||
QBrush,
|
||||
QColor,
|
||||
QKeyEvent,
|
||||
QMouseEvent,
|
||||
QPainter,
|
||||
QPainterPath,
|
||||
QPaintEvent,
|
||||
QTextBlockFormat,
|
||||
QTextCharFormat,
|
||||
QTextCursor,
|
||||
QTextDocument,
|
||||
QTextListFormat,
|
||||
)
|
||||
from PyQt6.QtSql import QSqlDatabase, QSqlQuery, QSqlQueryModel
|
||||
from PyQt6.QtWidgets import QDialog, QPushButton, QTextEdit, QWidget
|
||||
from lib import query_error
|
||||
from PyQt6.QtCore import QPoint, QResource, Qt, QTimer, pyqtSignal, pyqtSlot
|
||||
from PyQt6.QtGui import (QBrush, QColor, QKeyEvent, QPainter, QPainterPath,
|
||||
QPaintEvent, QTextCharFormat, QTextCursor)
|
||||
from PyQt6.QtSql import QSqlQuery
|
||||
from PyQt6.QtWidgets import QDialog, QTextEdit, QWidget
|
||||
from ui.ReadDialog import Ui_ReadDialog
|
||||
|
||||
from lib.preferences import Preferences
|
||||
from lib.session import SessionDialog
|
||||
from lib.sounds import SoundOff
|
||||
from main import query_error
|
||||
from ui.ReadDialog import Ui_ReadDialog
|
||||
|
||||
|
||||
class ReadDialog(QDialog, Ui_ReadDialog):
|
||||
@@ -630,7 +606,6 @@ class ReadDialog(QDialog, Ui_ReadDialog):
|
||||
def scrollTo(self, position: int) -> None:
|
||||
cursor = self.paraEdit.textCursor()
|
||||
cursor.setPosition(position)
|
||||
rect = self.paraEdit.cursorRect(cursor)
|
||||
return
|
||||
|
||||
def savePosition(self) -> None:
|
||||
|
||||
@@ -1,20 +1,12 @@
|
||||
from datetime import datetime, timedelta
|
||||
from typing import Optional, cast
|
||||
from typing import cast
|
||||
|
||||
from PyQt6.QtCore import QModelIndex, Qt, QTime, QTimer, pyqtSignal, pyqtSlot
|
||||
from PyQt6.QtGui import (
|
||||
QBrush,
|
||||
QPalette,
|
||||
QStandardItem,
|
||||
QStandardItemModel,
|
||||
QTextBlockFormat,
|
||||
QTextCursor,
|
||||
QTextDocument,
|
||||
)
|
||||
from lib import query_error
|
||||
from PyQt6.QtCore import QModelIndex, Qt, QTimer, pyqtSlot
|
||||
from PyQt6.QtGui import (QStandardItem, QStandardItemModel, QTextBlockFormat,
|
||||
QTextCursor, QTextDocument)
|
||||
from PyQt6.QtSql import QSqlQuery
|
||||
from PyQt6.QtWidgets import QCheckBox, QDialog, QListView, QMessageBox
|
||||
|
||||
from main import query_error
|
||||
from PyQt6.QtWidgets import QDialog, QMessageBox
|
||||
from ui.SessionDialog import Ui_SessionDialog
|
||||
|
||||
|
||||
|
||||
21
lib/utils.py
Normal file
21
lib/utils.py
Normal file
@@ -0,0 +1,21 @@
|
||||
"""Utility Functions."""
|
||||
from typing import NoReturn
|
||||
|
||||
from PyQt6.QtCore import QCoreApplication
|
||||
from PyQt6.QtSql import QSqlQuery
|
||||
|
||||
translate = QCoreApplication.translate
|
||||
|
||||
|
||||
def query_error(query: QSqlQuery) -> NoReturn:
|
||||
"""Standarized query error reporter."""
|
||||
print(
|
||||
translate("MainWindow", "SQL Error:\n")
|
||||
+ "{}\n{}\n{}:{}".format(
|
||||
query.executedQuery(),
|
||||
query.boundValues(),
|
||||
query.lastError().type(),
|
||||
query.lastError().text(),
|
||||
)
|
||||
)
|
||||
raise Exception(translate("MainWindow", "SQL Error"))
|
||||
49
main.py
49
main.py
@@ -9,56 +9,22 @@
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
from datetime import datetime, timedelta
|
||||
from typing import Optional
|
||||
|
||||
from PyQt6.QtCore import (
|
||||
QCoreApplication,
|
||||
QEvent,
|
||||
QModelIndex,
|
||||
QResource,
|
||||
Qt,
|
||||
QTimer,
|
||||
pyqtSignal,
|
||||
pyqtSlot,
|
||||
)
|
||||
from PyQt6.QtGui import (
|
||||
QAction,
|
||||
QFont,
|
||||
QTextCharFormat,
|
||||
QTextCursor,
|
||||
QTextDocument,
|
||||
QTextListFormat,
|
||||
)
|
||||
from PyQt6.QtCore import (QCoreApplication, QEvent, QModelIndex, QResource,
|
||||
pyqtSignal, pyqtSlot)
|
||||
from PyQt6.QtSql import QSqlDatabase, QSqlQuery, QSqlQueryModel
|
||||
from PyQt6.QtWidgets import (
|
||||
QApplication,
|
||||
QFileDialog,
|
||||
QMainWindow,
|
||||
QMessageBox,
|
||||
QPushButton,
|
||||
)
|
||||
from PyQt6.QtWidgets import QApplication, QFileDialog, QMainWindow
|
||||
|
||||
|
||||
from lib import *
|
||||
from lib.preferences import Preferences
|
||||
from lib import PersonDialog, Book, SessionDialog, ReadDialog, query_error
|
||||
|
||||
from ui.MainWindow import Ui_MainWindow
|
||||
|
||||
translate = QCoreApplication.translate
|
||||
|
||||
|
||||
def query_error(query: QSqlQuery) -> None:
|
||||
print(
|
||||
translate("MainWindow", "SQL Error:\n")
|
||||
+ "{}\n{}\n{}:{}".format(
|
||||
query.executedQuery(),
|
||||
query.boundValues(),
|
||||
query.lastError().type(),
|
||||
query.lastError().text(),
|
||||
)
|
||||
)
|
||||
raise Exception(translate("MainWindow", "SQL Error"))
|
||||
|
||||
|
||||
class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
def __init__(self) -> None:
|
||||
super(MainWindow, self).__init__()
|
||||
@@ -97,7 +63,6 @@ class MainWindow(QMainWindow, Ui_MainWindow):
|
||||
|
||||
@pyqtSlot(QModelIndex)
|
||||
def selectedPerson(self, index: QModelIndex) -> None:
|
||||
person_id = index.siblingAtColumn(0).data()
|
||||
self.actionEditPerson.setEnabled(True)
|
||||
book_id = index.siblingAtColumn(3).data()
|
||||
if not book_id or book_id < 0:
|
||||
@@ -324,7 +289,7 @@ def main() -> int:
|
||||
)
|
||||
schema_update(db)
|
||||
Preferences()
|
||||
window: QMainWindow = MainWindow()
|
||||
window = MainWindow() # noqa: F841
|
||||
return app.exec()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user