fix: fit main window within screen on startup

This commit is contained in:
chengma
2026-07-07 12:06:17 +08:00
parent 05a85c6d6a
commit caa04a9aa7
7 changed files with 166 additions and 5 deletions
+38 -1
View File
@@ -17,7 +17,7 @@ from app import accounts, ai, appconfig, db, prompts
if gui.QT_IMPORT_ERROR is not None:
raise unittest.SkipTest("PySide6 未安装")
from PySide6.QtCore import QItemSelectionModel
from PySide6.QtCore import QItemSelectionModel, QRect
from PySide6.QtGui import QTextCursor
from PySide6.QtWidgets import QApplication, QCheckBox, QLineEdit, QPlainTextEdit, QProgressBar, QTableView
@@ -39,6 +39,7 @@ from app.gui import (
TAB_TITLES,
WriteBackWorker,
)
from app.gui.main_window import _fit_and_center_window
class GuiTests(TempDirMixin, unittest.TestCase):
@@ -182,6 +183,42 @@ class GuiTests(TempDirMixin, unittest.TestCase):
self.assert_removed(temp_dir)
def test_main_window_initial_fit_limits_size_on_small_screen(self):
class FakeWindow:
def __init__(self):
self.size = None
self.position = None
def resize(self, width, height):
self.size = (width, height)
def move(self, x, y):
self.position = (x, y)
window = FakeWindow()
_fit_and_center_window(window, available_geometry=QRect(0, 0, 900, 700))
self.assertEqual((820, 620), window.size)
self.assertEqual((40, 40), window.position)
def test_main_window_initial_fit_centers_preferred_size_on_large_screen(self):
class FakeWindow:
def __init__(self):
self.size = None
self.position = None
def resize(self, width, height):
self.size = (width, height)
def move(self, x, y):
self.position = (x, y)
window = FakeWindow()
_fit_and_center_window(window, available_geometry=QRect(100, 50, 1600, 900))
self.assertEqual((1180, 760), window.size)
self.assertEqual((310, 120), window.position)
def test_collect_tab_shows_empty_state_without_accounts(self):
with self.make_temp_dir() as temp_dir:
cfg = self.make_config(temp_dir)