Skip to content

Commit c4a41be

Browse files
committed
Preferred accent option
1 parent f9a877b commit c4a41be

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

vocabsieve/config/general_tab.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import json
22
from bidict import bidict
33
from PyQt5.QtWidgets import QLabel, QComboBox, QLineEdit, QPushButton, QCheckBox, QFormLayout
4-
from PyQt5.QtCore import pyqtSignal
4+
from PyQt5.QtCore import pyqtSignal, QRegExp
5+
from PyQt5.QtGui import QRegExpValidator
56
from .base_tab import BaseTab
67
from ..constants import langcodes
78
from .dictmanager import DictManager
@@ -23,6 +24,8 @@ def initWidgets(self):
2324
"\nfor frequency lists from Migaku. ")
2425
self.bold_word = QCheckBox("Bold selected word")
2526
self.audio_format = QComboBox()
27+
self.preferred_accent = QLineEdit()
28+
self.preferred_accent.setValidator(QRegExpValidator(QRegExp("[a-z]{2}")))
2629
self.freq_source = QComboBox()
2730
self.gtrans_lang = QComboBox()
2831
self.web_preset = QComboBox()
@@ -59,6 +62,9 @@ def setupLayout(self):
5962
layout.addRow(QLabel("Forvo audio format"), self.audio_format)
6063
layout.addRow(QLabel("<i>◊ Choose mp3 for playing on iOS, "
6164
"but ogg may save space</i>"))
65+
layout.addRow(QLabel("Forvo preferred accent"), self.preferred_accent)
66+
layout.addRow(QLabel("<i>Will prefer provided accent by sorting it to the top of the pronunciations list</i>"))
67+
layout.addRow(QLabel("<i>Pronunciations have an accent in brackets e.g. yelkoastur(es)/gracias</i>"))
6268
layout.addRow(QLabel("Frequency list"), self.freq_source)
6369
layout.addRow(self.lemfreq)
6470
layout.addRow(
@@ -105,6 +111,7 @@ def setupAutosave(self):
105111
'en',
106112
code_translate=True)
107113
self.register_config_handler(self.audio_format, 'audio_format', 'mp3')
114+
self.register_config_handler(self.preferred_accent, 'preferred_accent', '')
108115
self.register_config_handler(self.lemfreq, 'lemfreq', True)
109116

110117
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)