Checkpoint, not working
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
from trycast import trycast
|
||||
import json
|
||||
import re
|
||||
from typing import Any, NamedTuple, TypedDict, cast
|
||||
from typing import Any, Literal, NamedTuple, NotRequired, TypedDict, cast
|
||||
|
||||
from PyQt6.QtCore import QEventLoop, QUrl, Qt
|
||||
from PyQt6.QtGui import QColor, QFont
|
||||
@@ -129,14 +129,26 @@ class Definition(TypedDict):
|
||||
sseq: list[SenseSequence]
|
||||
vd: str
|
||||
|
||||
class Entry(TypedDict):
|
||||
class EntryX(TypedDict):
|
||||
meta: Meta
|
||||
hom: str
|
||||
hom: NotRequired[str]
|
||||
hwi: HeadWordInfo
|
||||
ahws: list[HeadWord]
|
||||
vrs: list[Variant]
|
||||
ahws: NotRequired[list[HeadWord]]
|
||||
vrs: NotRequired[list[Variant]]
|
||||
fl: str
|
||||
def_: list[Definition]
|
||||
Entry = TypedDict(
|
||||
'Entry',
|
||||
{
|
||||
'meta': Meta,
|
||||
'hom': NotRequired[str],
|
||||
'hwi': HeadWordInfo,
|
||||
'ahws': NotRequired[list[HeadWord]],
|
||||
'vrs': NotRequired[list[Variant]],
|
||||
'fl': NotRequired[str],
|
||||
'def': list[Definition],
|
||||
}
|
||||
)
|
||||
|
||||
def fetch(word:str) -> dict[str, Any]:
|
||||
request = QNetworkRequest()
|
||||
@@ -213,30 +225,55 @@ def do_prs(prs: list[Pronunciation]) -> list[Fragment]:
|
||||
|
||||
def getDef(definition: list[Entry]) -> list[Line]:
|
||||
lines = []
|
||||
#
|
||||
# Pull the fonts for ease of use
|
||||
#
|
||||
headerFont = trycast(QFont, Word._resources['fonts']['header'])
|
||||
assert headerFont is not None
|
||||
textFont = trycast(QFont, Word._resources['fonts']['text'])
|
||||
assert textFont is not None
|
||||
labelFont = trycast(QFont, Word._resources['fonts']['label'])
|
||||
assert labelFont is not None
|
||||
|
||||
#
|
||||
# Pull the colors for ease of use
|
||||
#
|
||||
baseColor = trycast(QColor, Word._resources['colors']['base'])
|
||||
assert baseColor is not None
|
||||
linkColor = trycast(QColor, Word._resources['colors']['link'])
|
||||
assert linkColor is not None
|
||||
subduedColor = trycast(QColor, Word._resources['colors']['subdued'])
|
||||
assert subduedColor is not None
|
||||
entries = len(definition)
|
||||
|
||||
#
|
||||
# No need to figure it out each time it is used
|
||||
#
|
||||
entries = 0
|
||||
id = definition[0]['meta']['id']
|
||||
id = ':'.split(id)[0].lower()
|
||||
for entry in definition:
|
||||
if entry['meta']['id'].lower() == id:
|
||||
entries += 1
|
||||
for count, entry in enumerate(definition):
|
||||
if entry['meta']['id'].lower() != id:
|
||||
continue
|
||||
#
|
||||
# Create the First line from the hwi and fl
|
||||
# Create the First line from the hwi, [ahws] and fl
|
||||
#
|
||||
line = Line()
|
||||
hwi = trycast(HeadWordInfo, entry['hwi'])
|
||||
assert hwi is not None
|
||||
hw = re.sub(r'\*', '', hwi['hw'])
|
||||
line.addFragment(Fragment(hw + ' ', headerFont, color=baseColor))
|
||||
frag = Fragment(f"{count} of {entries} ", textFont, color=linkColor)
|
||||
line.addFragment(Fragment(hw, headerFont, color=baseColor))
|
||||
if 'ahws' in entry:
|
||||
ahws = trycast(list[HeadWord], entry['ahws'])
|
||||
assert ahws is not None
|
||||
for ahw in ahws:
|
||||
hw = re.sub(r'\*', '', ahw['hw'])
|
||||
line.addFragment(Fragment(', ' + hw, headerFont, color=baseColor))
|
||||
if 'hom' in entry:
|
||||
|
||||
if 'fl' in entry:
|
||||
frag = Fragment(f"{count} of {entries} ", textFont, color=
|
||||
frag.setBackground(QColor(Qt.GlobalColor.gray))
|
||||
line.addFragment(frag)
|
||||
line.addFragment(Fragment(entry['fl'], labelFont, color=baseColor))
|
||||
@@ -244,10 +281,14 @@ def getDef(definition: list[Entry]) -> list[Line]:
|
||||
|
||||
#
|
||||
# Next is the pronunciation.
|
||||
# While 'prs' is optional, the headword is not. This gets us what we want.
|
||||
#
|
||||
line = Line()
|
||||
hw = re.sub(r'\*', '\u00b7', hwi['hw'])
|
||||
line.addFragment(Fragment(hw + ' ', textFont, color=subduedColor))
|
||||
for frag in do_prs(hwi['prs']):
|
||||
line.addFragment(frag)
|
||||
|
||||
#
|
||||
# Try for
|
||||
return [Line()]
|
||||
|
||||
Reference in New Issue
Block a user