Delay needed when loading a script
willbelr opened this issue · 4 comments
A rendering problem affects 'graphics' terminal programs such as top
and htop
when they are launched using a script. A workaround consists in adding a short delay at the head of the script.
Expected Behavior
Current Behavior
Possible Solution
Not sure how it is handled in C++, but in PyQt sometimes this type of problem is caused by a premature function call somewhere, which can be delayed until next loop with QtCore.QTimer.singleShot(0, function)
Steps to Reproduce
Exemple code below. As shown, by adding sleep 0.1 &&
the problem is fixed.
#!/usr/bin/python3
import sys
from PyQt5 import QtWidgets
from QTermWidget import QTermWidget
with open("/tmp/test.sh", "w") as f:
# f.write("sleep 0.1 && htop") # good
f.write("htop") # bad
app = QtWidgets.QApplication(sys.argv)
term = QTermWidget(0)
term.setColorScheme("DarkPastels")
term.setShellProgram("/bin/bash")
term.setArgs(["/tmp/test.sh"])
term.startShellProgram()
term.show()
app.exec()
System Information
- Distribution & Version: Arch
- Kernel: 5.15.32-1-lts SMP Mon, 28 Mar 2022 08:54:31 +0000 x86_64 GNU/Linux
- Qt Version: 5.15.3
- lxqt-build-tools Version: 0.10.0-1
- Package version: 1.0.0-2
There are other reports where sleep
can workaround the issue. I cannot reproduce those issues reliably and I don't understand why it's broken, though. lxqt/qterminal#899, lxqt/qterminal#778
this type of problem is caused by a premature function call somewhere
I wasn't able to reproduce the issue but, IMHO, this can be true. I've seen examples of it in Qt itself, although they weren't related to the current problem.
Try launching the script from a desktop file. On my system, I can toggle the bug by setting terminal=true (good) or false (bad).
[Desktop Entry]
Exec=python /home/user/.local/share/scripts/primenote/primenote/__init__.py
Terminal=false
Also I noticed the bug happen when launching the script from xterm.desktop, but not urxvt.desktop. Sounds like it could stem from the environment, but I could not find a relevant variable yet. Might be somewhat related to #447
I found the bug is caused by the LINES
and COLUMNS
environment variables, which are set by xterm (bad) but not rxvt (good). I use xterm to launch my scripts, hence the faulty variables of xterm were passed to QTermWidget. The problem is solved by unsetting those two before calling startShellProgram()
;
setEnvironment(["TERM=xterm", "LINES=", "COLUMNS="])
#!/usr/bin/python3
import sys
from PyQt5 import QtWidgets
from QTermWidget import QTermWidget
with open("/tmp/test.sh", "w") as f:
# f.write("sleep 0.1 && htop") # workaround 1
# f.write("unset LINES && unset COLUMNS && htop") # workaround 2
f.write("htop")
app = QtWidgets.QApplication(sys.argv)
term = QTermWidget(0)
term.setColorScheme("DarkPastels")
term.setEnvironment(["TERM=xterm", "LINES=", "COLUMNS="]) # solution
term.setShellProgram("/bin/bash")
term.setArgs(["/tmp/test.sh"])
term.startShellProgram()
term.show()
app.exec()