Use main-window menus, cache maps, and handle settled sweep events

This commit is contained in:
AttilaNet
2026-11-08 11:10:07 +08:00
parent 2498f1f98f
commit dba667f21d
13 changed files with 578 additions and 33 deletions
+40
View File
@@ -3,6 +3,27 @@ from PySide6 import QtCore as C, QtGui as G, QtWidgets as W
import time
class FocusWheelMixin:
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# StrongFocus permits click/keyboard focus, but never wheel focus.
self.setFocusPolicy(C.Qt.FocusPolicy.StrongFocus)
def wheelEvent(self, event):
if not self.hasFocus():
event.ignore()
return
super().wheelEvent(event)
class SpinBox(FocusWheelMixin, W.QSpinBox):
pass
class DoubleSpinBox(FocusWheelMixin, W.QDoubleSpinBox):
pass
class ComboBox(W.QComboBox):
"""Size popups for their text, independently of narrow table columns."""
def __init__(self, parent=None):
@@ -129,6 +150,8 @@ class IntegerInput(W.QLineEdit):
def __init__(self):
super().__init__()
self._value, self._minimum, self._maximum = 0, 0, 2147483647
self._wheel_delta = 0
self.setFocusPolicy(C.Qt.FocusPolicy.StrongFocus)
self.setValidator(G.QIntValidator(self._minimum, self._maximum, self))
self.setText("0")
self.setMinimumWidth(76)
@@ -165,6 +188,23 @@ class IntegerInput(W.QLineEdit):
def finish_number(self):
self.setValue(self._value)
def wheelEvent(self, event):
if not self.hasFocus() or not event.angleDelta().y():
event.ignore()
return
self._wheel_delta += event.angleDelta().y()
steps = int(self._wheel_delta / 120)
self._wheel_delta -= steps * 120
if steps:
if event.modifiers() & C.Qt.KeyboardModifier.ControlModifier:
steps *= 10
self.setValue(self.value() + steps)
event.accept()
def focusOutEvent(self, event):
self._wheel_delta = 0
super().focusOutEvent(event)
class NativeScrollStyle(W.QProxyStyle):
def pixelMetric(self, metric, option=None, widget=None):