Files
WeAreSyncing/scripts/smoke_test_rightclick_filemenu.py
T
ThePendulum 105dd5be88 LosslessCut-style layout: File menu, timeline above transport, centered controls, right-click play/pause
- Load File moved from a button into a new File menu.
- Timeline now sits directly under the video; the transport row
  (frame-step/play/frame-step, centered as a group; mute pinned right)
  moved below it, matching LosslessCut's layout instead of the previous
  buttons-then-timeline order.
- Right-click on the video toggles play/pause.

The right-click implementation took two tries, worth recording: mpv
embeds via wid as its own native child window, which receives raw X11
input directly -- a real mouse click never reaches this QWidget's
mousePressEvent at all, even though a unit-style test that called the
handler directly passed and looked fine. Caught this by testing with
an actual xdotool click against a live running window instead of
trusting the synthetic test, which is what this project's smoke tests
have been doing throughout and what caught the bug here too. Fixed by
binding MBTN_RIGHT through mpv's own on_key_press input API instead,
which does receive the real clicks -- verified the same way, with a
real click on a live window, position/button-text actually changing.

Also fixed a genuinely flaky smoke test in the process: QShortcut's
active-window check races with real desktop window-manager focus,
especially with another instance of this same app already open
elsewhere (happened during this session). Switched that test to set
Qt's active-window state directly rather than relying on WM-level
activation, and independently confirmed the real key bindings with
live xdotool keypresses (both directions, plus end-of-file clamping).
2026-07-26 02:19:54 +02:00

68 lines
2.4 KiB
Python

"""Verifies right-click-on-player toggles play/pause, and that Load File
moved from a button into a File menu action.
mpv owns its own native child window for the embedded video surface, so a
real mouse click there never reaches Qt's mousePressEvent at all -- the
right-click binding is registered through mpv's own input system instead
(see player_widget.py). To exercise that actual code path headlessly, this
drives mpv's own `keypress` command (which simulates input the same way a
real click would, through mpv's own dispatch) rather than posting a
QMouseEvent, since a QMouseEvent would only prove Qt-level dead code works,
not the real behavior -- that mistake produced a false pass earlier in this
session, worth not repeating.
"""
import sys
import time
from pathlib import Path
from PyQt6.QtWidgets import QApplication
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
import main as app_main
ROOT = Path(__file__).resolve().parent.parent
CLIP = str(ROOT / "test_media" / "sync_test_INSYNC.mp4")
def main():
qapp = QApplication(sys.argv)
win = app_main.MainWindow()
win.show()
qapp.processEvents()
win._load(CLIP)
qapp.processEvents()
time.sleep(0.2)
qapp.processEvents()
# -- File menu has Load File, no more load_button in the layout
menu_titles = [a.text() for a in win.menuBar().actions()]
assert "&File" in menu_titles, f"expected a File menu, got {menu_titles}"
assert not hasattr(win, "load_button"), "old Load File button should be gone"
print("PASS: Load File lives in the File menu")
# -- Right-click on the player toggles play/pause
assert win.player.mpv.pause is True, "should start paused"
win.player.mpv.command("keypress", "MBTN_RIGHT")
qapp.processEvents()
time.sleep(0.2)
qapp.processEvents()
assert win.player.mpv.pause is False, "right-click should have started playback"
assert win.play_button.text() == "Pause"
print("PASS: right-click on player started playback")
win.player.mpv.command("keypress", "MBTN_RIGHT")
qapp.processEvents()
time.sleep(0.2)
qapp.processEvents()
assert win.player.mpv.pause is True, "second right-click should pause again"
assert win.play_button.text() == "Play"
print("PASS: right-click on player paused again")
win.player.shutdown()
print("\nRIGHT-CLICK / FILE MENU SMOKE TEST PASSED")
if __name__ == "__main__":
main()