75 lines
2.5 KiB
Python
75 lines
2.5 KiB
Python
#!/usr/bin/env python3
|
|
# Copyright (c) 2026 Storm Dragon
|
|
# Authors: Storm Dragon, Angus Kola
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
"""Private Qt provider matching Mumble's read-only Activity log."""
|
|
import ctypes
|
|
import os
|
|
import sys
|
|
|
|
from PySide6 import QtCore, QtGui, QtWidgets
|
|
|
|
if ctypes.CDLL(None).prctl(15, sys.argv[1].encode(), 0, 0, 0) != 0:
|
|
raise RuntimeError("Cannot set fixture process identity")
|
|
|
|
application = QtWidgets.QApplication([])
|
|
chat_window = QtWidgets.QMainWindow()
|
|
chat_window.setWindowTitle("Chat fixture")
|
|
chat_content = QtWidgets.QWidget()
|
|
chat_window.setCentralWidget(chat_content)
|
|
layout = QtWidgets.QVBoxLayout(chat_content)
|
|
transcript = QtWidgets.QTextBrowser()
|
|
transcript.setAccessibleName("Activity log")
|
|
layout.addWidget(transcript)
|
|
unrelated = QtWidgets.QTextBrowser()
|
|
unrelated.setAccessibleName("Other log")
|
|
layout.addWidget(unrelated)
|
|
chat_window.show()
|
|
|
|
foreground = QtWidgets.QMainWindow()
|
|
foreground.setWindowTitle("Foreground fixture")
|
|
foreground_content = QtWidgets.QWidget()
|
|
foreground.setCentralWidget(foreground_content)
|
|
foreground_layout = QtWidgets.QVBoxLayout(foreground_content)
|
|
editor = QtWidgets.QLineEdit()
|
|
# An editable field with the same name must never count as a transcript.
|
|
editor.setAccessibleName("Activity log")
|
|
foreground_layout.addWidget(editor)
|
|
foreground.show()
|
|
editor.setFocus()
|
|
pending_input = ""
|
|
|
|
|
|
def insert(widget, text):
|
|
cursor = widget.textCursor()
|
|
cursor.movePosition(QtGui.QTextCursor.MoveOperation.End)
|
|
cursor.insertText(text)
|
|
|
|
|
|
def receive_command(*_):
|
|
global pending_input
|
|
content = os.read(sys.stdin.fileno(), 4096)
|
|
if not content:
|
|
application.quit()
|
|
return
|
|
pending_input += content.decode()
|
|
while "\n" in pending_input:
|
|
command, pending_input = pending_input.split("\n", 1)
|
|
if command == "messages":
|
|
insert(transcript, "[12:34:56]")
|
|
insert(transcript, "[12:34:56] Username: hello\u2028world \ufdd0界\ufdef")
|
|
for _ in range(2):
|
|
insert(transcript, "[12:34:57] Repeated message")
|
|
insert(unrelated, "Unrelated log text")
|
|
editor.setText("Typed input")
|
|
elif command == "barrier":
|
|
editor.setText("Messaging barrier")
|
|
elif command == "quit":
|
|
application.quit()
|
|
|
|
|
|
notifier = QtCore.QSocketNotifier(sys.stdin.fileno(), QtCore.QSocketNotifier.Type.Read)
|
|
notifier.activated.connect(receive_command)
|
|
QtCore.QTimer.singleShot(0, lambda: print("ready", int(foreground.winId()), flush=True))
|
|
application.exec()
|