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