Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delay needed when loading a script #480

Open
willbelr opened this issue May 24, 2022 · 4 comments
Open

Delay needed when loading a script #480

willbelr opened this issue May 24, 2022 · 4 comments
Labels

Comments

@willbelr
Copy link
Contributor

willbelr commented May 24, 2022

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

Correct rendering

Current Behavior

Incorrect rendering

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
@yan12125
Copy link
Member

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

@yan12125 yan12125 added the bug label May 24, 2022
@tsujan
Copy link
Member

tsujan commented May 24, 2022

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.

@willbelr
Copy link
Contributor Author

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

@willbelr
Copy link
Contributor Author

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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants