Skip to content

Commit

Permalink
Sort languages alphabetically (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
chidiwilliams authored Oct 2, 2022
1 parent 7ca8bf0 commit b49e754
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:

- run: poetry install
- name: Test
run: poetry run pytest
run: poetry run pytest --cov --cov-fail-under=73
- run: ${{ matrix.CMD_BUILD }}
- uses: actions/upload-artifact@v3
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ dist/
__pycache__/
build/
.pytest_cache/
.coverage
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ bundle_windows:
make buzz
tar -czf dist/buzz-${version}-windows.tar.gz dist/Buzz

test:
pytest --cov --cov-fail-under=73

bundle_mac:
make buzz
tar -czf dist/buzz-${version}-unix.tar.gz dist/Buzz
Expand Down
17 changes: 12 additions & 5 deletions gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,21 @@ class LanguagesComboBox(QComboBox):

def __init__(self, default_language: str, *args) -> None:
super().__init__(*args)
self.languages = {'': 'Detect language', **tokenizer.LANGUAGES}
self.addItems(map(lambda lang: lang.title(), self.languages.values()))

whisper_languages = sorted(
[(lang, tokenizer.LANGUAGES[lang].title())
for lang in tokenizer.LANGUAGES.keys()],
key=lambda lang: lang[1])
self.languages = [('', 'Detect Language')] + whisper_languages

self.addItems([lang[1] for lang in self.languages])
self.currentIndexChanged.connect(self.on_index_changed)
self.setCurrentText(self.languages.get(default_language, '').title())
default_language_index = next((i for i, lang in enumerate(self.languages)
if lang[0] == default_language), 0)
self.setCurrentIndex(default_language_index)

def on_index_changed(self, index: int):
key = list(self.languages.keys())[index]
self.languageChanged.emit(key)
self.languageChanged.emit(self.languages[index][0])


class TasksComboBox(QComboBox):
Expand Down
23 changes: 23 additions & 0 deletions gui_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from gui import Application, LanguagesComboBox


class TestApplication:
app = Application()

def test_should_show_window_title(self):
assert self.app.window.windowTitle() == 'Buzz'


class TestLanguagesComboBox:
languagesComboxBox = LanguagesComboBox('en')

def test_should_show_sorted_whisper_languages(self):
assert self.languagesComboxBox.itemText(0) == 'Detect Language'
assert self.languagesComboxBox.itemText(10) == 'Belarusian'
assert self.languagesComboxBox.itemText(20) == 'Dutch'
assert self.languagesComboxBox.itemText(30) == 'Gujarati'
assert self.languagesComboxBox.itemText(40) == 'Japanese'
assert self.languagesComboxBox.itemText(50) == 'Lithuanian'

def test_should_select_default_language(self):
assert self.languagesComboxBox.currentText() == 'English'
87 changes: 86 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ autopep8 = "^1.7.0"
pyinstaller = "^5.4.1"
six = "^1.16.0"
pytest = "^7.1.3"
pytest-cov = "^4.0.0"

[build-system]
requires = ["poetry-core"]
Expand Down
6 changes: 0 additions & 6 deletions test_gui.py

This file was deleted.

0 comments on commit b49e754

Please sign in to comment.