Merge pull request #31 from seyitgkc/fix/settings-window-height

Keep the settings window inside the screen

Co-authored-by: Seyit Gokce <[email protected]>
This commit is contained in:
Yusuf İpek
2026-08-16 12:53:03 +03:00
committed by GitHub
co-authored by Seyit Gokce
2 changed files with 183 additions and 30 deletions
+75
View File
@@ -11,6 +11,8 @@ import unittest
from typing import ClassVar
from unittest import mock
from PyQt6.QtCore import QPoint, QPointF, Qt
from PyQt6.QtGui import QWheelEvent
from PyQt6.QtWidgets import QApplication, QMessageBox
import cleanup
@@ -116,6 +118,10 @@ class Settings(DikteTest):
"_load_models"))
self.enterContext(mock.patch.object(settings_ui.SettingsWindow,
"_load_transcribe_models"))
# The local model boxes fetch their own list the moment they are shown,
# from a thread, which is nobody's test failing but a real request.
self.enterContext(mock.patch.object(settings_ui.LocalModelBox,
"_fetch_models"))
self.enterContext(mock.patch.object(settings_ui.hotkey, "APPLICATIONS_DIR",
self.path("applications")))
self.enterContext(mock.patch.object(settings_ui.hotkey, "SHORTCUTS_FILE",
@@ -127,12 +133,81 @@ class Settings(DikteTest):
self.addCleanup(window.close)
return window
@staticmethod
def wheel():
"""One notch of a mouse wheel, rolled downwards."""
return QWheelEvent(QPointF(5, 5), QPointF(5, 5), QPoint(0, 0),
QPoint(0, -120), Qt.MouseButton.NoButton,
Qt.KeyboardModifier.NoModifier,
Qt.ScrollPhase.NoScrollPhase, False)
def test_the_window_opens_with_every_tab_on_it(self):
window = self.window(cfg.Config())
tabs = window.findChildren(settings_ui.QTabWidget)[0]
self.assertEqual(tabs.count(), 9)
self.assertEqual(window.windowTitle(), "Dikte Settings")
def test_no_tab_can_stretch_the_window_past_a_small_screen(self):
# A tab that keeps its full height hands that height to the window as a
# minimum, and a tall one then carries Save off the bottom of a laptop
# screen with no way to drag it back. Each tab scrolls instead.
window = self.window(cfg.Config())
for index in range(window.tabs.count()):
window.tabs.setCurrentIndex(index)
self.assertLess(window.minimumSizeHint().height(), 500,
window.tabs.tabText(index))
def test_the_window_cannot_be_dragged_down_to_a_stub(self):
# A tab that scrolls asks for no height of its own, which leaves nothing
# to stop the window being pulled down to a tab bar and half a button.
window = self.window(cfg.Config())
window.resize(1, 1)
self.assertGreaterEqual(window.width(), 500)
self.assertGreaterEqual(window.height(), 360)
def test_the_wheel_passes_over_a_box_it_was_not_aimed_at(self):
# Every tab scrolls now, and a combo box reads the wheel as a change of
# value: rolling down the page with the pointer over the language box
# would pick another language on the way past, and Save would write it
# down. The box takes the wheel once it has been clicked into.
window = self.window(cfg.Config())
# Shown and activated, because a box in a window nobody is looking at
# can be given the focus but never has it.
window.show()
window.activateWindow()
QApplication.processEvents()
box = window.ui_language
# Not the wheel focus a combo box has by default: Qt hands the focus
# over before it delivers the wheel, which would make "has the focus"
# true for the very roll being refused.
self.assertEqual(box.focusPolicy(), Qt.FocusPolicy.StrongFocus)
before = box.currentIndex()
rolled = self.wheel()
QApplication.sendEvent(box, rolled)
self.assertEqual(box.currentIndex(), before)
# Refused, not swallowed. An unaccepted wheel event is the one Qt
# carries on up to the scroll area, so the page moves instead.
self.assertFalse(rolled.isAccepted())
box.setFocus()
QApplication.sendEvent(box, self.wheel())
self.assertNotEqual(box.currentIndex(), before)
def test_a_wrapped_label_keeps_the_room_its_lines_need(self):
# The program path shares a row with a button, and a row is measured
# before its width is known: the label has to claim the second line back
# itself, and give it up again when the window is widened.
label = settings_ui.WrappedLabel()
# Shown, because a hidden widget is told about its new size only once
# somebody looks at it, and the height is worked out from that size.
label.show()
self.addCleanup(label.deleteLater)
line = label.fontMetrics().height()
label.resize(120, line)
label.setText("Installed on the system: /opt/homebrew/bin/whisper-server")
self.assertGreater(label.minimumHeight(), line)
label.resize(2000, line)
self.assertLessEqual(label.minimumHeight(), line)
def test_saving_without_touching_anything_changes_nothing(self):
"""Every widget has to load what is stored, or Save writes its default
over it. This says so for the whole table at once."""