[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    regression in inputhook support from pyqt5 to pyqt6
From:       Thomas Caswell <tcaswell () gmail ! com>
Date:       2021-11-28 1:49:03
Message-ID: CAA48SF_KwU5boaFYRGabwahdCtLfxnm4XU+BMub9q9i-t1_Dgw () mail ! gmail ! com
[Download RAW message or body]

Folks,

There seems to have been a change in the behavior of the inputhook.
Previously, if a widget was shown, the input hook installed by pyqt would
keep it alive and interactive while waiting for user input (either via
`input` or via the python shell).  A minimal example is:

```python
from PyQt6 import QtWidgets
# from PyQt5 import QtWidgets


app = QtWidgets.QApplication(["bob"])
b = QtWidgets.QPushButton("bob")
b.clicked.connect(lambda: print("clicked"))
b.show()
print(input("type and hit enter > "))
print(input("The window should still be open > "))
```

This works as expected with PyQt5, but with PyQt6 the widget is closed as
soon as you hit enter (and if the button is created in the python shell it
will close as you hit the first key) on linux.  I suspect osx and windows
will have the same problem, but have not tested.

This happens with all versions of pyqt6 on pypi and at least python3.8 and
py3.9.

Looking at `static int qtcore_input_hook()` in
`sip/QtCore/qcoreapplication.sip` there appears to be no change between
PyQt5 and PyQt6.

I suspect that the issue is Qt6 is better about closing all open windows on
exiting the QAppliaction::exec as compared to Qt5, but I could not find any
documentation on that (or smoking gun change in the source).

I suspect that changing the then qtcore_input_hook to create an QEventLoop
to exec, rather than exec'ing the main application is the solution.
However, I have not been able to test that directly and switching
IPython's input hook to exec'ing the full app did not break in the way I
expected.

Tom

-- 
Thomas Caswell
tcaswell@gmail.com

[Attachment #3 (text/html)]

<div dir="ltr">Folks,<div><br></div><div>There seems to have been a change in the \
behavior of the inputhook.   Previously, if a widget was shown, the input hook \
installed by pyqt would keep it alive and interactive while waiting for user input \
(either via `input` or via the python shell).   A minimal example \
is:</div><div><br></div><div>```python</div><div>from PyQt6 import QtWidgets<br># \
from PyQt5 import QtWidgets<br><br><br>app = \
QtWidgets.QApplication([&quot;bob&quot;])<br>b = \
QtWidgets.QPushButton(&quot;bob&quot;)<br>b.clicked.connect(lambda: \
print(&quot;clicked&quot;))<br>b.show()<br>print(input(&quot;type and hit enter &gt; \
&quot;))<br>print(input(&quot;The window should still be open &gt; \
&quot;))<br><div>```</div><div><br></div><div>This works as expected with PyQt5, but \
with PyQt6 the widget is closed as soon as you hit enter (and if the button is \
created in the python shell it will close as you hit the first key) on linux.   I \
suspect osx and windows will have the same problem, but have not \
tested.</div><div><br></div><div>This happens with all versions of pyqt6 on pypi and \
at least python3.8 and py3.9.</div><div><br></div><div>Looking at `static int \
qtcore_input_hook()` in `sip/QtCore/qcoreapplication.sip` there appears to be no \
change between PyQt5 and PyQt6.</div><div><br></div><div>I suspect that the issue is \
Qt6 is better about closing all open windows on exiting the QAppliaction::exec as \
compared to Qt5, but I could not find any documentation on that (or smoking gun \
change in the source).</div><div><br></div><div>I suspect that changing the then \
qtcore_input_hook to create an QEventLoop to exec, rather than exec&#39;ing the main \
application is the solution. However, I have not been able to test that directly and \
switching IPython&#39;s  input hook to exec&#39;ing the full app did not break in the \
way I expected.</div><div><br></div><div>Tom</div><div><br></div>-- <br><div \
dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">Thomas \
Caswell<br><a href="mailto:tcaswell@gmail.com" \
target="_blank">tcaswell@gmail.com</a></div></div></div>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic