More progress on all entites in MW data load
This commit is contained in:
@@ -521,8 +521,10 @@ class Definition(QWidget):
|
||||
self.pronounce.emit(url)
|
||||
elif url.scheme() == 'word':
|
||||
self.newWord.emit(url.path())
|
||||
elif url.scheme() == 'sense':
|
||||
self.newWord.emit(url.path())
|
||||
else:
|
||||
print(f"{clk['fmt'].anchorHref()}: {url.scheme()}")
|
||||
print(f"{clk['fmt'].anchorHref()}")
|
||||
self.alert.emit()
|
||||
self._downClickable = None
|
||||
return
|
||||
|
||||
23
lib/read.py
23
lib/read.py
@@ -1,12 +1,9 @@
|
||||
import json
|
||||
from typing import Any, Dict, List, Optional, cast
|
||||
from typing import Dict, List, Optional, cast
|
||||
|
||||
import requests
|
||||
from PyQt6.QtCore import QPoint, QResource, Qt, QTimer, pyqtSignal, pyqtSlot
|
||||
from PyQt6.QtGui import (
|
||||
QBrush,
|
||||
QColor,
|
||||
QCursor,
|
||||
QKeyEvent,
|
||||
QPainter,
|
||||
QPainterPath,
|
||||
@@ -15,7 +12,7 @@ from PyQt6.QtGui import (
|
||||
QTextCursor,
|
||||
)
|
||||
from PyQt6.QtSql import QSqlQuery
|
||||
from PyQt6.QtWidgets import QDialog, QTextEdit, QWidget
|
||||
from PyQt6.QtWidgets import QDialog, QWidget
|
||||
|
||||
from lib import query_error
|
||||
from lib.preferences import Preferences
|
||||
@@ -89,6 +86,7 @@ class ReadDialog(QDialog, Ui_ReadDialog):
|
||||
self.playSound.connect(self.sound.playSound)
|
||||
self.playAlert.connect(self.sound.alert)
|
||||
self.definition.pronounce.connect(self.sound.playSound)
|
||||
self.definition.newWord.connect(self.newWord)
|
||||
return
|
||||
|
||||
#
|
||||
@@ -98,6 +96,15 @@ class ReadDialog(QDialog, Ui_ReadDialog):
|
||||
#
|
||||
# slots
|
||||
#
|
||||
@pyqtSlot(str)
|
||||
def newWord(self, word: str) -> None:
|
||||
w = Word(word)
|
||||
if not w.isValid():
|
||||
self.playAlert.emit()
|
||||
return
|
||||
self.definition.setWord(w)
|
||||
return
|
||||
|
||||
@pyqtSlot()
|
||||
def timerAction(self) -> None:
|
||||
if self.session.isActive(): # We are stopping
|
||||
@@ -127,6 +134,9 @@ class ReadDialog(QDialog, Ui_ReadDialog):
|
||||
cursor.select(QTextCursor.SelectionType.WordUnderCursor)
|
||||
text = cursor.selectedText().strip()
|
||||
word = Word(text)
|
||||
if not word.isValid():
|
||||
self.playAlert.emit()
|
||||
return
|
||||
word.playPRS()
|
||||
return
|
||||
|
||||
@@ -221,6 +231,9 @@ class ReadDialog(QDialog, Ui_ReadDialog):
|
||||
cursor.select(cursor.SelectionType.WordUnderCursor)
|
||||
text = cursor.selectedText().strip()
|
||||
word = Word(text)
|
||||
if not word.isValid():
|
||||
self.playAlert.emit()
|
||||
return
|
||||
self.definition.setWord(word)
|
||||
self.showDefinition()
|
||||
return
|
||||
|
||||
11
lib/words.py
11
lib/words.py
@@ -40,6 +40,7 @@ class Word:
|
||||
"""All processing of a dictionary word."""
|
||||
|
||||
_words: dict[str, WordType] = {}
|
||||
_valid = False
|
||||
|
||||
def __init__(self, word: str) -> None:
|
||||
#
|
||||
@@ -62,14 +63,18 @@ class Word:
|
||||
"definition": json.loads(query.value("definition")),
|
||||
}
|
||||
self.current = Word._words[word]
|
||||
self._valid = True
|
||||
return
|
||||
#
|
||||
# The code should look at our settings to see if we have an API
|
||||
# key for MW to decide on the source to use.
|
||||
#
|
||||
source = "mw"
|
||||
|
||||
|
||||
self._words[word] = discovered_plugins[source].fetch(word)
|
||||
if self._words[word] is None:
|
||||
self._valid = False
|
||||
return
|
||||
self.current = Word._words[word]
|
||||
query.prepare(
|
||||
"INSERT INTO words "
|
||||
@@ -81,8 +86,12 @@ class Word:
|
||||
query.bindValue(":definition", json.dumps(self.current["definition"]))
|
||||
if not query.exec():
|
||||
query_error(query)
|
||||
self._valid = True
|
||||
return
|
||||
|
||||
def isValid(self) -> bool:
|
||||
return self._valid
|
||||
|
||||
@pyqtSlot()
|
||||
def playSound(self) -> None:
|
||||
url = discovered_plugins[self.current["source"]].getFirstSound(
|
||||
|
||||
Reference in New Issue
Block a user