Formatting addition
This commit is contained in:
51
lib/read.py
51
lib/read.py
@@ -37,10 +37,6 @@ class EditDialog(QDialog, Ui_Dialog):
|
||||
font.setFamily("OpenDyslexic")
|
||||
font.setPointSize(14)
|
||||
self.paraEdit.setFont(font)
|
||||
self.nextParaBtn = QPushButton(parent=self.widget)
|
||||
self.nextParaBtn.setObjectName("nextParaBtn")
|
||||
self.verticalLayout.addWidget(self.nextParaBtn)
|
||||
self.nextParaBtn.setText("Next Paragraph")
|
||||
#
|
||||
# End overrides
|
||||
#
|
||||
@@ -52,18 +48,26 @@ class EditDialog(QDialog, Ui_Dialog):
|
||||
self.block = blockNumber
|
||||
self.savePosition()
|
||||
self.stackedWidget.setCurrentIndex(0)
|
||||
self.defineBtn.clicked.connect(self.defineAction)
|
||||
self.addBtn.clicked.connect(self.defineAction)
|
||||
self.showBtn.clicked.connect(self.showAction)
|
||||
self.nextBtn.clicked.connect(self.nextAction)
|
||||
self.prevBtn.clicked.connect(self.prevAction)
|
||||
self.nextParaBtn.clicked.connect(self.nextParaAction)
|
||||
self.wordsBtn.clicked.connect(self.wordAction)
|
||||
# self.prevParaBtn.clicked.connect(self.prevParaAction)
|
||||
self.paraEdit.verticalScrollBar().valueChanged.connect(self.scrollSlot)
|
||||
self.scrollBtn.clicked.connect(self.scrollAction)
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
def wordAction(self) -> None:
|
||||
pos = self.paraEdit.mapTo(self, self.paraEdit.cursorRect().topLeft())
|
||||
def scrollAction(self) -> None:
|
||||
position = (
|
||||
self.paraEdit.document().findBlockByNumber(self.block).position()
|
||||
)
|
||||
cursor = self.paraEdit.textCursor()
|
||||
cursor.setPosition(position)
|
||||
pos = self.paraEdit.mapTo(
|
||||
self, self.paraEdit.cursorRect(cursor).topLeft()
|
||||
)
|
||||
top = self.paraEdit.mapTo(self, QPoint(0, 0))
|
||||
value = self.paraEdit.verticalScrollBar().value()
|
||||
#
|
||||
@@ -130,15 +134,21 @@ class EditDialog(QDialog, Ui_Dialog):
|
||||
self.section_map = {}
|
||||
self.sequence_map = {}
|
||||
query.prepare(
|
||||
"SELECT * FROM sections " "WHERE book_id = :book_id " "ORDER BY sequence"
|
||||
"SELECT * FROM sections "
|
||||
"WHERE book_id = :book_id "
|
||||
"ORDER BY sequence"
|
||||
)
|
||||
query.bindValue(":book_id", self.book_id)
|
||||
if not query.exec():
|
||||
query_error(query)
|
||||
while query.next():
|
||||
self.sections.append(query.value("content"))
|
||||
self.section_map[query.value("section_id")] = query.value("sequence")
|
||||
self.sequence_map[query.value("sequence")] = query.value("section_id")
|
||||
self.section_map[query.value("section_id")] = query.value(
|
||||
"sequence"
|
||||
)
|
||||
self.sequence_map[query.value("sequence")] = query.value(
|
||||
"section_id"
|
||||
)
|
||||
return
|
||||
|
||||
def show_section(self, section_id: int, start: bool = True) -> None:
|
||||
@@ -162,7 +172,9 @@ class EditDialog(QDialog, Ui_Dialog):
|
||||
def_format.setFontUnderline(True)
|
||||
cursor = QTextCursor(self.paraEdit.document())
|
||||
query = QSqlQuery()
|
||||
query.prepare("SELECT * FROM word_block " "WHERE section_id = :section_id")
|
||||
query.prepare(
|
||||
"SELECT * FROM word_block " "WHERE section_id = :section_id"
|
||||
)
|
||||
query.bindValue(":section_id", section_id)
|
||||
if not query.exec():
|
||||
query_error(query)
|
||||
@@ -189,7 +201,9 @@ class EditDialog(QDialog, Ui_Dialog):
|
||||
return
|
||||
|
||||
def paintEvent(self, e: QPaintEvent | None) -> None:
|
||||
position = self.paraEdit.document().findBlockByNumber(self.block).position()
|
||||
position = (
|
||||
self.paraEdit.document().findBlockByNumber(self.block).position()
|
||||
)
|
||||
cursor = self.paraEdit.textCursor()
|
||||
cursor.setPosition(position)
|
||||
#
|
||||
@@ -259,7 +273,8 @@ class EditDialog(QDialog, Ui_Dialog):
|
||||
definitions = json.loads(response.content.decode("utf-8"))
|
||||
definition = definitions[0]
|
||||
query.prepare(
|
||||
"INSERT INTO words (word, definition) " "VALUES (:word, :definition)"
|
||||
"INSERT INTO words (word, definition) "
|
||||
"VALUES (:word, :definition)"
|
||||
)
|
||||
query.bindValue(":word", word)
|
||||
query.bindValue(":definition", json.dumps(definition))
|
||||
@@ -270,7 +285,9 @@ class EditDialog(QDialog, Ui_Dialog):
|
||||
self.defined(query.lastInsertId(), blockNum, start, end)
|
||||
return
|
||||
|
||||
def defined(self, word_id: int, blockNum: int, start: int, end: int) -> None:
|
||||
def defined(
|
||||
self, word_id: int, blockNum: int, start: int, end: int
|
||||
) -> None:
|
||||
query = QSqlQuery()
|
||||
query.prepare(
|
||||
"SELECT * FROM word_block "
|
||||
@@ -306,7 +323,9 @@ class EditDialog(QDialog, Ui_Dialog):
|
||||
cursor.setPosition(
|
||||
start + textBlock.position(), QTextCursor.MoveMode.MoveAnchor
|
||||
)
|
||||
cursor.setPosition(end + textBlock.position(), QTextCursor.MoveMode.KeepAnchor)
|
||||
cursor.setPosition(
|
||||
end + textBlock.position(), QTextCursor.MoveMode.KeepAnchor
|
||||
)
|
||||
cursor.setCharFormat(def_format)
|
||||
return
|
||||
|
||||
|
||||
Reference in New Issue
Block a user