Skip to content

Commit 380e419

Browse files
committed
tests: stabilize qtdragon ui-smoke preview and gcode scroll
The offscreen grab could catch qtdragon in different startup states between runs: the 3D preview at different zooms and the gcode view at different scroll positions. Two distinct causes: - The preview computes its zoom once, at file-load, from the live widget size (glnav.py set_view_p reads winfo_width/height) and never re-fits on resize (qt5_graphics.py resizeGL only resets the GL viewport). Under offscreen the file load can run before the layout settles, freezing a stale zoom from a transient size. - The gcode editor resets to the top on load, then scrolls to the running line on line-changed; which one the grab catches is timing. Before grabbing, normalize at the now-final widget size: re-issue the view fit (set_current_view) so the zoom is recomputed against the fixed layout, and pin the gcode scrollbar to the top. With this in place two consecutive runs are pixel-identical apart from the wall-clock field, so the reference.png is regenerated to the deterministic state.
1 parent dbf80a3 commit 380e419

2 files changed

Lines changed: 37 additions & 10 deletions

File tree

tests/ui-smoke/_lib/qtdragon-prepare.sh

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,22 +81,49 @@ sys.meta_path.insert(0, _BlockFinder())
8181
import os
8282
import signal
8383
84+
def _ui_smoke_find_main(app):
85+
target, best = None, -1
86+
for w in app.topLevelWidgets():
87+
if not w.isVisible():
88+
continue
89+
area = w.width() * w.height()
90+
if area > best:
91+
target, best = w, area
92+
return target
93+
94+
def _ui_smoke_normalize(target):
95+
# Pin qtdragon's startup nondeterminism before the grab: re-fit the
96+
# preview zoom at the now-final widget size and scroll the gcode view
97+
# to the top.
98+
from qtpy.QtWidgets import QWidget
99+
for w in target.findChildren(QWidget):
100+
try:
101+
if hasattr(w, 'set_current_view') and hasattr(w, 'current_view'):
102+
w.set_current_view()
103+
elif hasattr(w, 'ensureLineVisible') and hasattr(w, 'verticalScrollBar'):
104+
w.verticalScrollBar().setValue(0)
105+
except Exception:
106+
pass
107+
84108
def _ui_smoke_grab():
85109
try:
86110
from qtpy.QtWidgets import QApplication
111+
from qtpy.QtCore import QTimer
87112
app = QApplication.instance()
88113
if app is None:
89114
return
90-
target, best = None, -1
91-
for w in app.topLevelWidgets():
92-
if not w.isVisible():
93-
continue
94-
area = w.width() * w.height()
95-
if area > best:
96-
target, best = w, area
97-
if target is not None:
98-
out = os.environ.get('UI_SMOKE_QT_SHOT', 'ui-smoke-qt.png')
99-
target.grab().save(out)
115+
target = _ui_smoke_find_main(app)
116+
if target is None:
117+
return
118+
_ui_smoke_normalize(target)
119+
def _save():
120+
try:
121+
out = os.environ.get('UI_SMOKE_QT_SHOT', 'ui-smoke-qt.png')
122+
target.grab().save(out)
123+
except Exception:
124+
pass
125+
# let the re-fit repaint before grabbing
126+
QTimer.singleShot(250, _save)
100127
except Exception:
101128
pass
102129
6.03 KB
Loading

0 commit comments

Comments
 (0)