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

List:       pykde
Subject:    Re: regression in inputhook support from pyqt5 to pyqt6
From:       Thomas Caswell <tcaswell () gmail ! com>
Date:       2021-11-30 17:38:53
Message-ID: CAA48SF8BM1nuULGqhTpZL=kdNrM3jCG6fyBe1ALAimbAUMGuiA () mail ! gmail ! com
[Download RAW message or body]

Phil,

Thanks, I can confirm it works for me on linux with 6.2.2.dev2111291237.

Tom

On Mon, Nov 29, 2021 at 7:02 AM Phil Thompson <phil@riverbankcomputing.com>
wrote:

> On 28/11/2021 01:49, Thomas Caswell wrote:
> > 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.
>
> It's not closing the windows, it just seems to hide them.
>
> > 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.
>
> A separate event loop seems to work (at least on macOS). Fixed in the
> next snapshot.
>
> Thanks,
> Phil
>


-- 
Thomas Caswell
tcaswell@gmail.com

[Attachment #3 (text/html)]

<div dir="ltr">Phil,<div><br></div>Thanks, I can confirm it works for me on linux \
with 6.2.2.dev2111291237.<div><br></div><div>Tom</div></div><br><div \
class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Nov 29, 2021 at 7:02 AM \
Phil Thompson &lt;<a \
href="mailto:phil@riverbankcomputing.com">phil@riverbankcomputing.com</a>&gt; \
wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 28/11/2021 01:49, \
Thomas Caswell wrote:<br> &gt; Folks,<br>
&gt; <br>
&gt; There seems to have been a change in the behavior of the inputhook.<br>
&gt; Previously, if a widget was shown, the input hook installed by pyqt <br>
&gt; would<br>
&gt; keep it alive and interactive while waiting for user input (either via<br>
&gt; `input` or via the python shell).   A minimal example is:<br>
&gt; <br>
&gt; ```python<br>
&gt; from PyQt6 import QtWidgets<br>
&gt; # from PyQt5 import QtWidgets<br>
&gt; <br>
&gt; <br>
&gt; app = QtWidgets.QApplication([&quot;bob&quot;])<br>
&gt; b = QtWidgets.QPushButton(&quot;bob&quot;)<br>
&gt; b.clicked.connect(lambda: print(&quot;clicked&quot;))<br>
&gt; b.show()<br>
&gt; print(input(&quot;type and hit enter &gt; &quot;))<br>
&gt; print(input(&quot;The window should still be open &gt; &quot;))<br>
&gt; ```<br>
&gt; <br>
&gt; This works as expected with PyQt5, but with PyQt6 the widget is closed <br>
&gt; as<br>
&gt; soon as you hit enter (and if the button is created in the python shell <br>
&gt; it<br>
&gt; will close as you hit the first key) on linux.   I suspect osx and <br>
&gt; windows<br>
&gt; will have the same problem, but have not tested.<br>
<br>
It&#39;s not closing the windows, it just seems to hide them.<br>
<br>
&gt; This happens with all versions of pyqt6 on pypi and at least python3.8 <br>
&gt; and<br>
&gt; py3.9.<br>
&gt; <br>
&gt; Looking at `static int qtcore_input_hook()` in<br>
&gt; `sip/QtCore/qcoreapplication.sip` there appears to be no change between<br>
&gt; PyQt5 and PyQt6.<br>
&gt; <br>
&gt; I suspect that the issue is Qt6 is better about closing all open <br>
&gt; windows on<br>
&gt; exiting the QAppliaction::exec as compared to Qt5, but I could not find <br>
&gt; any<br>
&gt; documentation on that (or smoking gun change in the source).<br>
&gt; <br>
&gt; I suspect that changing the then qtcore_input_hook to create an <br>
&gt; QEventLoop<br>
&gt; to exec, rather than exec&#39;ing the main application is the solution.<br>
&gt; However, I have not been able to test that directly and switching<br>
&gt; IPython&#39;s input hook to exec&#39;ing the full app did not break in the way \
<br> &gt; I<br>
&gt; expected.<br>
<br>
A separate event loop seems to work (at least on macOS). Fixed in the <br>
next snapshot.<br>
<br>
Thanks,<br>
Phil<br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" \
class="gmail_signature">Thomas Caswell<br><a href="mailto:tcaswell@gmail.com" \
target="_blank">tcaswell@gmail.com</a></div>



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

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