Skip to content

Commit 067d936

Browse files
committed
Preferred accent option
1 parent f9a877b commit 067d936

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

vocabsieve/config/general_tab.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
from bidict import bidict
33
from PyQt5.QtWidgets import QLabel, QComboBox, QLineEdit, QPushButton, QCheckBox, QFormLayout
44
from PyQt5.QtCore import pyqtSignal
5+
from PyQt5.QtGui import QRegExpValidator
6+
from PyQt5.QtCore import QRegExp
57
from .base_tab import BaseTab
68
from ..constants import langcodes
79
from .dictmanager import DictManager
@@ -23,6 +25,8 @@ def initWidgets(self):
2325
"\nfor frequency lists from Migaku. ")
2426
self.bold_word = QCheckBox("Bold selected word")
2527
self.audio_format = QComboBox()
28+
self.preferred_accent = QLineEdit()
29+
self.preferred_accent.setValidator(QRegExpValidator(QRegExp("[a-z]{2}")))
2630
self.freq_source = QComboBox()
2731
self.gtrans_lang = QComboBox()
2832
self.web_preset = QComboBox()
@@ -59,6 +63,9 @@ def setupLayout(self):
5963
layout.addRow(QLabel("Forvo audio format"), self.audio_format)
6064
layout.addRow(QLabel("<i>◊ Choose mp3 for playing on iOS, "
6165
"but ogg may save space</i>"))
66+
layout.addRow(QLabel("Forvo preferred accent"), self.preferred_accent)
67+
layout.addRow(QLabel("<i>Will prefer provided accent by sorting it to the top of the pronunciations list</i>"))
68+
layout.addRow(QLabel("<i>Pronunciations have an accent in brackets e.g. yelkoastur(es)/gracias</i>"))
6269
layout.addRow(QLabel("Frequency list"), self.freq_source)
6370
layout.addRow(self.lemfreq)
6471
layout.addRow(
@@ -105,6 +112,7 @@ def setupAutosave(self):
105112
'en',
106113
code_translate=True)
107114
self.register_config_handler(self.audio_format, 'audio_format', 'mp3')
115+
self.register_config_handler(self.preferred_accent, 'preferred_accent', '')
108116
self.register_config_handler(self.lemfreq, 'lemfreq', True)
109117

110118
self.register_config_handler(

vocabsieve/sources/forvo_audio_source.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,11 @@ class PronunciationList:
3535

3636

3737
class Forvo:
38-
def __init__(self, word, lang, accent=""):
38+
def __init__(self, word, lang):
3939
self.url = "https://forvo.com/word/" + quote(word)
4040
self.pronunciations = []
4141
self.session = requests.Session()
4242
self.language = lang
43-
self.accent = accent
4443

4544
def get_pronunciations(self):
4645
res = cached_get(self.url, forvo_headers=True)
@@ -64,11 +63,6 @@ def get_pronunciations(self):
6463
filter(
6564
lambda el: el.language == self.language,
6665
available_pronunciations_lists))
67-
if self.accent:
68-
available_pronunciations_lists = list(
69-
filter(
70-
lambda el: el.accent == self.accent,
71-
available_pronunciations_lists))
7266

7367
for l in available_pronunciations_lists:
7468
pronunciation_item = l.pronunciation_list
@@ -139,7 +133,7 @@ def get_pronunciations(self):
139133
)
140134

141135
self.pronunciations.append(pronunciation_object)
142-
self.pronunciations = sorted(self.pronunciations, key=lambda x: x.votes, reverse=True)
136+
self.pronunciations = sorted(self.pronunciations, key=lambda x: (x.accent != settings.value("preferred_accent", ""), -x.votes)) # Non-matching accents after, then sort by votes descending
143137
return self
144138

145139

0 commit comments

Comments
 (0)