feat(settings): prevent spinbox wheel changes
This commit is contained in:
+83
-2
@@ -29,8 +29,8 @@ from app import (
|
||||
if gui.QT_IMPORT_ERROR is not None:
|
||||
raise unittest.SkipTest("PySide6 未安装")
|
||||
|
||||
from PySide6.QtCore import QItemSelectionModel, QModelIndex, QRect, QSize, QTimer, Qt
|
||||
from PySide6.QtGui import QImage, QKeyEvent, QTextCursor
|
||||
from PySide6.QtCore import QItemSelectionModel, QModelIndex, QPoint, QPointF, QRect, QSize, QTimer, Qt
|
||||
from PySide6.QtGui import QImage, QKeyEvent, QTextCursor, QWheelEvent
|
||||
from PySide6.QtTest import QTest
|
||||
from PySide6.QtWidgets import (
|
||||
QAbstractItemView,
|
||||
@@ -43,6 +43,7 @@ from PySide6.QtWidgets import (
|
||||
QProgressBar,
|
||||
QPushButton,
|
||||
QRadioButton,
|
||||
QSpinBox,
|
||||
QTableView,
|
||||
)
|
||||
|
||||
@@ -74,6 +75,7 @@ from app.gui import file_manager
|
||||
import app.gui.workers as gui_workers
|
||||
from app.gui.tabs.collect import _format_collect_elapsed
|
||||
from app.gui.tabs.generate import CoverGalleryDialog, OriginalImageDialog
|
||||
from app.gui.tabs.settings import SettingsSpinBox
|
||||
from app.gui.main_window import _fit_and_center_window
|
||||
|
||||
|
||||
@@ -3189,6 +3191,85 @@ class GuiTests(TempDirMixin, unittest.TestCase):
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
def test_settings_spin_boxes_forward_wheel_to_page_scroll(self):
|
||||
with self.make_temp_dir() as temp_dir:
|
||||
cfg = self.make_config(temp_dir)
|
||||
cfg["ai"] = appconfig.default_config()["ai"]
|
||||
tab = SettingsTab(
|
||||
config=cfg,
|
||||
config_path=cfg["config_path"],
|
||||
ai_models_path=cfg["ai_models_path"],
|
||||
)
|
||||
self.addCleanup(tab.close)
|
||||
tab.resize(900, 360)
|
||||
tab.show()
|
||||
self.app.processEvents()
|
||||
|
||||
spin_boxes = (
|
||||
tab.cmhub_connect_timeout_spin,
|
||||
tab.connect_timeout_spin,
|
||||
tab.title_concurrency_spin,
|
||||
tab.image_concurrency_spin,
|
||||
tab.retry_spin,
|
||||
tab.default_debug_port_spin,
|
||||
tab.debug_port_start_spin,
|
||||
tab.debug_port_end_spin,
|
||||
tab.cdp_ready_timeout_spin,
|
||||
tab.max_items_per_run_spin,
|
||||
tab.max_parallel_accounts_spin,
|
||||
)
|
||||
self.assertEqual(set(spin_boxes), set(tab.findChildren(QSpinBox)))
|
||||
self.assertTrue(all(isinstance(spin, SettingsSpinBox) for spin in spin_boxes))
|
||||
values = {spin: spin.value() for spin in spin_boxes}
|
||||
tab._set_dirty(False)
|
||||
|
||||
for spin in spin_boxes:
|
||||
local_position = spin.rect().center()
|
||||
global_position = spin.mapToGlobal(local_position)
|
||||
event = QWheelEvent(
|
||||
QPointF(local_position),
|
||||
QPointF(global_position),
|
||||
QPoint(),
|
||||
QPoint(0, -120),
|
||||
Qt.NoButton,
|
||||
Qt.NoModifier,
|
||||
Qt.ScrollUpdate,
|
||||
False,
|
||||
)
|
||||
QApplication.sendEvent(spin, event)
|
||||
self.assertEqual(values[spin], spin.value())
|
||||
|
||||
self.assertFalse(tab.is_dirty())
|
||||
scroll_bar = tab.settings_scroll_area.verticalScrollBar()
|
||||
self.assertGreater(scroll_bar.maximum(), 0)
|
||||
scroll_bar.setValue(0)
|
||||
spin = tab.title_concurrency_spin
|
||||
local_position = spin.rect().center()
|
||||
global_position = spin.mapToGlobal(local_position)
|
||||
QApplication.sendEvent(
|
||||
spin,
|
||||
QWheelEvent(
|
||||
QPointF(local_position),
|
||||
QPointF(global_position),
|
||||
QPoint(),
|
||||
QPoint(0, -120),
|
||||
Qt.NoButton,
|
||||
Qt.NoModifier,
|
||||
Qt.ScrollUpdate,
|
||||
False,
|
||||
),
|
||||
)
|
||||
self.app.processEvents()
|
||||
self.assertGreater(scroll_bar.value(), 0)
|
||||
|
||||
before = tab.title_concurrency_spin.value()
|
||||
tab.title_concurrency_spin.setFocus()
|
||||
QTest.keyClick(tab.title_concurrency_spin, Qt.Key_Up)
|
||||
self.assertEqual(before + 1, tab.title_concurrency_spin.value())
|
||||
self.assertTrue(tab.is_dirty())
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
def test_settings_tab_cmhub_alias_refresh_filters_unpriced_and_keeps_saved(self):
|
||||
with self.make_temp_dir() as temp_dir:
|
||||
cfg = self.make_config(temp_dir)
|
||||
|
||||
Reference in New Issue
Block a user