mirror of
https://github.com/chidiwilliams/buzz.git
synced 2024-06-29 05:00:21 +02:00
Fix Windows styling and layout (#285)
This commit is contained in:
parent
9ea5341d01
commit
611e623a3a
11
.gitignore
vendored
11
.gitignore
vendored
|
@ -6,9 +6,12 @@ build/
|
|||
!.coveragerc
|
||||
.env
|
||||
htmlcov/
|
||||
libwhisper.*
|
||||
whisper_cpp
|
||||
whisper.dll
|
||||
whisper_cpp.py
|
||||
coverage.xml
|
||||
.idea/
|
||||
|
||||
# whisper_cpp
|
||||
libwhisper.*
|
||||
whisper_cpp
|
||||
whisper_cpp.exe
|
||||
whisper.dll
|
||||
whisper_cpp.py
|
||||
|
|
|
@ -24,8 +24,7 @@ datas += [('whisper.dll' if platform.system() ==
|
|||
'Windows' else 'libwhisper.*', '.')]
|
||||
datas += [(shutil.which('whisper_cpp') if platform.system()
|
||||
== 'Windows' else 'whisper_cpp', '.')]
|
||||
datas += [('assets/buzz.ico', 'assets')]
|
||||
datas += [('assets/buzz-icon-1024.png', 'assets')]
|
||||
datas += [('assets/*', 'assets')]
|
||||
datas += [(shutil.which('ffmpeg'), '.')]
|
||||
|
||||
|
||||
|
|
18
buzz/gui.py
18
buzz/gui.py
|
@ -787,6 +787,8 @@ class MainWindowToolbar(QToolBar):
|
|||
new_transcription_action_triggered: pyqtSignal
|
||||
open_transcript_action_triggered: pyqtSignal
|
||||
clear_history_action_triggered: pyqtSignal
|
||||
ICON_LIGHT_THEME_BACKGROUND = '#555'
|
||||
ICON_DARK_THEME_BACKGROUND = '#888'
|
||||
|
||||
def __init__(self, parent: Optional[QWidget]):
|
||||
super().__init__(parent)
|
||||
|
@ -814,7 +816,7 @@ class MainWindowToolbar(QToolBar):
|
|||
self.addAction(self.clear_history_action)
|
||||
self.setMovable(False)
|
||||
self.setIconSize(QSize(16, 16))
|
||||
self.setContentsMargins(0, 2, 0, 2)
|
||||
self.setStyleSheet('QToolButton{margin: 6px 4px;}')
|
||||
|
||||
for action in self.actions():
|
||||
widget = self.widgetForAction(action)
|
||||
|
@ -827,8 +829,8 @@ class MainWindowToolbar(QToolBar):
|
|||
'QToolButton { margin-left: 9px; margin-right: 1px; }')
|
||||
|
||||
def load_icon(self, file_path: str):
|
||||
is_dark_background = self.palette().window().color().black() > 127
|
||||
return self.load_icon_with_color(file_path, '#888' if is_dark_background else '#444')
|
||||
is_dark_theme = self.palette().window().color().black() > 127
|
||||
return self.load_icon_with_color(file_path, self.ICON_DARK_THEME_BACKGROUND if is_dark_theme else self.ICON_LIGHT_THEME_BACKGROUND)
|
||||
|
||||
@staticmethod
|
||||
def load_icon_with_color(file_path: str, color: str):
|
||||
|
@ -1006,7 +1008,7 @@ class HuggingFaceSearchLineEdit(LineEdit):
|
|||
model_selected = pyqtSignal(str)
|
||||
popup: QListWidget
|
||||
|
||||
def __init__(self, parent: Optional[QWidget] = None):
|
||||
def __init__(self, network_access_manager: Optional[QNetworkAccessManager] = None, parent: Optional[QWidget] = None):
|
||||
super().__init__('', parent)
|
||||
|
||||
self.setMinimumWidth(150)
|
||||
|
@ -1021,7 +1023,10 @@ class HuggingFaceSearchLineEdit(LineEdit):
|
|||
self.textEdited.connect(self.timer.start)
|
||||
self.textEdited.connect(self.on_text_edited)
|
||||
|
||||
self.network_manager = QNetworkAccessManager(self)
|
||||
if network_access_manager is None:
|
||||
network_access_manager = QNetworkAccessManager(self)
|
||||
|
||||
self.network_manager = network_access_manager
|
||||
self.network_manager.finished.connect(self.on_request_response)
|
||||
|
||||
self.popup = QListWidget()
|
||||
|
@ -1100,7 +1105,8 @@ class HuggingFaceSearchLineEdit(LineEdit):
|
|||
if isinstance(event, QKeyEvent):
|
||||
key = event.key()
|
||||
if key in [Qt.Key.Key_Enter, Qt.Key.Key_Return]:
|
||||
self.on_select_item()
|
||||
if self.popup.currentItem() is not None:
|
||||
self.on_select_item()
|
||||
return True
|
||||
|
||||
if key == Qt.Key.Key_Escape:
|
||||
|
|
2
poetry.lock
generated
2
poetry.lock
generated
|
@ -818,7 +818,7 @@ dev = ["pytest"]
|
|||
type = "git"
|
||||
url = "https://github.com/openai/whisper.git"
|
||||
reference = "HEAD"
|
||||
resolved_reference = "0b5dcfdef7ec04250b76e13f1630e32b0935ce76"
|
||||
resolved_reference = "28769fcfe50755a817ab922a7bc83483159600a9"
|
||||
|
||||
[[package]]
|
||||
name = "wrapt"
|
||||
|
|
|
@ -5,11 +5,12 @@ from unittest.mock import Mock, patch
|
|||
|
||||
import pytest
|
||||
import sounddevice
|
||||
from PyQt6.QtCore import QSize, Qt
|
||||
from PyQt6.QtCore import QSize, Qt, QByteArray, QObject
|
||||
from PyQt6.QtGui import QValidator, QKeyEvent
|
||||
from PyQt6.QtWidgets import QPushButton, QToolBar, QTableWidget, QApplication
|
||||
from pytestqt.qtbot import QtBot
|
||||
|
||||
from .mock_qt import MockNetworkAccessManager, MockNetworkReply
|
||||
from buzz.cache import TasksCache
|
||||
from buzz.gui import (AboutDialog, AdvancedSettingsDialog, AudioDevicesComboBox, DownloadModelProgressDialog,
|
||||
FileTranscriberWidget, LanguagesComboBox, MainWindow,
|
||||
|
@ -346,7 +347,7 @@ class TestRecordingTranscriberWidget:
|
|||
|
||||
class TestHuggingFaceSearchLineEdit:
|
||||
def test_should_update_selected_model_on_type(self, qtbot: QtBot):
|
||||
widget = HuggingFaceSearchLineEdit()
|
||||
widget = HuggingFaceSearchLineEdit(network_access_manager=self.network_access_manager())
|
||||
qtbot.add_widget(widget)
|
||||
|
||||
mock_model_selected = Mock()
|
||||
|
@ -356,7 +357,7 @@ class TestHuggingFaceSearchLineEdit:
|
|||
mock_model_selected.assert_called_with('openai/whisper-tiny')
|
||||
|
||||
def test_should_show_list_of_models(self, qtbot: QtBot):
|
||||
widget = HuggingFaceSearchLineEdit()
|
||||
widget = HuggingFaceSearchLineEdit(network_access_manager=self.network_access_manager())
|
||||
qtbot.add_widget(widget)
|
||||
|
||||
self._set_text_and_wait_response(qtbot, widget)
|
||||
|
@ -365,7 +366,7 @@ class TestHuggingFaceSearchLineEdit:
|
|||
assert 'openai/whisper-tiny' in widget.popup.item(0).text()
|
||||
|
||||
def test_should_select_model_from_list(self, qtbot: QtBot):
|
||||
widget = HuggingFaceSearchLineEdit()
|
||||
widget = HuggingFaceSearchLineEdit(network_access_manager=self.network_access_manager())
|
||||
qtbot.add_widget(widget)
|
||||
|
||||
mock_model_selected = Mock()
|
||||
|
@ -381,9 +382,14 @@ class TestHuggingFaceSearchLineEdit:
|
|||
|
||||
mock_model_selected.assert_called_with('openai/whisper-tiny.en')
|
||||
|
||||
@staticmethod
|
||||
def network_access_manager():
|
||||
reply = MockNetworkReply(data=[{'id': 'openai/whisper-tiny'}, {'id': 'openai/whisper-tiny.en'}])
|
||||
return MockNetworkAccessManager(reply=reply)
|
||||
|
||||
@staticmethod
|
||||
def _set_text_and_wait_response(qtbot: QtBot, widget: HuggingFaceSearchLineEdit):
|
||||
with qtbot.wait_signal(widget.network_manager.finished, timeout=30 * 1000):
|
||||
with qtbot.wait_signal(widget.network_manager.finished):
|
||||
widget.setText('openai/whisper-tiny')
|
||||
widget.textEdited.emit('openai/whisper-tiny')
|
||||
|
||||
|
|
30
tests/mock_qt.py
Normal file
30
tests/mock_qt.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
|
||||
import json
|
||||
from typing import Optional
|
||||
|
||||
from PyQt6.QtCore import QByteArray, QObject, QSize, Qt, pyqtSignal
|
||||
from PyQt6.QtNetwork import QNetworkAccessManager, QNetworkReply
|
||||
|
||||
|
||||
class MockNetworkReply(QNetworkReply):
|
||||
def __init__(self, data: object, _: Optional[QObject] = None) -> None:
|
||||
self.data = data
|
||||
|
||||
def readAll(self) -> 'QByteArray':
|
||||
return QByteArray(json.dumps(self.data).encode('utf-8'))
|
||||
|
||||
def error(self) -> 'QNetworkReply.NetworkError':
|
||||
return QNetworkReply.NetworkError.NoError
|
||||
|
||||
|
||||
class MockNetworkAccessManager(QNetworkAccessManager):
|
||||
finished = pyqtSignal(object)
|
||||
reply: MockNetworkReply
|
||||
|
||||
def __init__(self, reply: MockNetworkReply, parent: Optional[QObject] = None) -> None:
|
||||
super().__init__(parent)
|
||||
self.reply = reply
|
||||
|
||||
def get(self, _: 'QNetworkRequest') -> 'QNetworkReply':
|
||||
self.finished.emit(self.reply)
|
||||
return self.reply
|
Loading…
Reference in a new issue