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

List:       pykde
Subject:    Re: [PyQt] QMessageBox.question returns NoButton in python interactive
From:       Kyle Altendorf <sda () fstab ! net>
Date:       2019-06-27 21:23:56
Message-ID: b6a4739078c7975f3199088fd8100cd4 () fstab ! net
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Quite true about the keypress in Linux.  Though I'm confused how the
button can be functionally resized if it's event loop is disabled while
the question box is shown.  Here in KDE anyways I can
alt+right-click+drag to resize even modally blocked windows to see this.


Cheers, 

-kyle 

On 2019-06-27 17:05, Thomas Caswell wrote:

> ok, it is defiantly related to PyOS_InputHook.  
> 
> I think I have the rough outlines of this correct below, but may have some \
> details/terminology wrong. 
> When using pyqt "interactively" the infinite loop of the terminal and the Qt event \
> loop need to be interlaced.  This is done (in plain python) via the PyOS_InputHook \
> which is a c-function which is run while the terminal is waiting for the (slow) \
> humans to type something.  The terminal than handles the keystroke (including \
> possibly running what ever python there is run) and the call the input hook again.  \
> On posix systems the Qt event loop is run forever and then file descriptors / \
> sockets are used to interrupt the event loop when the user hits a key, however on \
> windows we do not have that and instead the input hook runs the Qt event loop for a \
> short period of time, checks if a key has been hit, and if not loops.    
> Modal windows in Qt work by blocking the event loop of their parent and the run \
> their own event loop (which effectively freeze's their parents, but allows the \
> modal window to be responsive).  However, when the outer event loop is interrupted, \
> the question window gets closed and `QtWidgets.QMessageBox.question(...) returns \
> NoButton.  In the case of MS Windows, this happens on some polling loop so the \
> window just flashes.  On linux (and I suspect OSX) you can get the same behavior by \
> clicking on the button to pop up the question, but then typing into the terminal \
> (any key will do) before you click on the question box.  
> Tom 
> 
> On Thu, Jun 27, 2019 at 4:12 PM Thomas Caswell <tcaswell@gmail.com> wrote: 
> I suspect, but can not prove, that this is related to PyOS_InputHook and may depend \
> on exactly which terminal emulator you are using on windows.  
> Tom 
> 
> On Thu, Jun 27, 2019 at 3:01 PM Kyle Altendorf <sda@fstab.net> wrote: 
> 
> Seems to work ok in 5.9.2 and 5.12.1 in Linux here.  I get 16384 (Yes) and 65536 \
> (No).  
> Though this is an odd program.  I thought message boxes maybe ran their own event \
> loop if needed but is showing a button and expecting it's signals to emit \
> functionally really proper?  
> Cheers, 
> 
> -kyle 
> 
> On 2019-06-27 14:36, Luke Campagnola wrote: 
> 
> Greetings, 
> I have found that when calling QMessageBox.question, the message box flashes up \
> briefly before disappearing and the call returns NoButton. This behavior is present \
> in both PyQt4 and PyQt5 (most recently tested on 5.9.2 from anaconda package), on \
> windows (but not linux), and only if I have not called QApplication.exec_() because \
> I am running in an interactive python shell.  
> Code to reproduce (run with python -i): 
> 
> import sys
> #from PyQt4 import QtGui as QtWidgets
> from PyQt5 import QtWidgets 
> 
> app = QtWidgets.QApplication([])
> 
> def msg():
> print(QtWidgets.QMessageBox.question(btn, "title", "message"))
> 
> btn = QtWidgets.QPushButton("show messagebox")
> btn.clicked.connect(msg)
> btn.show()
> 
> # message box works if event loop is started 
> # app.exec_() 
> 
> Cheers, 
> Luke 
> _______________________________________________
> PyQt mailing list    PyQt@riverbankcomputing.com
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt \
> _______________________________________________ PyQt mailing list    \
> PyQt@riverbankcomputing.com \
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt

  -- 
Thomas Caswell
tcaswell@gmail.com 
  -- 
Thomas Caswell
tcaswell@gmail.com


[Attachment #5 (unknown)]

<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" \
/></head><body style='font-size: 10pt'> <p>Quite true about the keypress in \
Linux.&nbsp; Though I'm confused how the button can be functionally resized&nbsp;if \
it's event loop is disabled while the&nbsp;question box is shown.&nbsp; Here in KDE \
anyways I can alt+right-click+drag to resize even modally blocked windows to see \
this.</p> <p>Cheers,</p>
<p>-kyle</p>
<p><br /></p>
<p>On 2019-06-27 17:05, Thomas Caswell wrote:</p>
<blockquote type="cite" style="padding: 0 0.4em; border-left: #1010ff 2px solid; \
margin: 0"><!-- html ignored --><!-- head ignored --><!-- meta ignored --> <div \
dir="ltr">ok, it is defiantly related to PyOS_InputHook.&nbsp; <div>&nbsp;</div>
<div>I think I have the rough outlines of this correct below, but may have some \
details/terminology wrong.<br /> <div>&nbsp;</div>
<div>When using pyqt "interactively" the infinite loop of the terminal and the Qt \
event loop need to be interlaced.&nbsp; This is done (in plain python) via the \
PyOS_InputHook which is a c-function which is run while the terminal is waiting for \
the (slow) humans to type something.&nbsp; The terminal than handles the keystroke \
(including possibly running what ever python there is run) and the call the input \
hook again.&nbsp; On posix systems the Qt event loop is run forever and then file \
descriptors / sockets are used to interrupt the event loop when the user hits a key, \
however on windows we do not have that and instead the input hook runs the Qt event \
loop for a short period of time, checks if a key has been hit, and if not \
loops.&nbsp;&nbsp;</div> </div>
<div>&nbsp;</div>
<div>Modal windows in Qt work by blocking the event loop of their parent and the run \
their own event loop (which effectively freeze's their parents, but allows the modal \
window to be responsive).&nbsp; However, when the outer event loop is interrupted, \
the question window gets closed and `QtWidgets.QMessageBox.question(...) returns \
NoButton.&nbsp; In the case of MS Windows, this happens on some polling loop so the \
window just flashes.&nbsp; On linux (and I suspect OSX) you can get the same behavior \
by clicking on the button to pop up the question, but then typing into the terminal \
(any key will do) before you click on the question box.</div> <div>&nbsp;</div>
<div>Tom</div>
<div>&nbsp;</div>
</div>
<br />
<div class="gmail_quote">
<div class="gmail_attr" dir="ltr">On Thu, Jun 27, 2019 at 4:12 PM Thomas Caswell \
&lt;<a href="mailto:tcaswell@gmail.com">tcaswell@gmail.com</a>&gt; wrote:</div> \
<blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px \
solid #cccccc; padding-left: 1ex;"> <div dir="ltr">I suspect, but can not prove, that \
this is related to&nbsp;PyOS_InputHook and may depend on exactly which terminal \
emulator you are using on windows. <div>&nbsp;</div>
<div>Tom</div>
</div>
<br />
<div class="gmail_quote">
<div class="gmail_attr" dir="ltr">On Thu, Jun 27, 2019 at 3:01 PM Kyle Altendorf \
&lt;<a href="mailto:sda@fstab.net">sda@fstab.net</a>&gt; wrote:</div> <blockquote \
class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left: 1px solid #cccccc; \
padding-left: 1ex;"> <div style="font-size: 10pt;">
<p>Seems to work ok in 5.9.2 and 5.12.1 in Linux here.&nbsp; I get 16384 (Yes) and \
65536 (No).</p> <p>Though this is an odd program.&nbsp; I thought message boxes maybe \
ran their own event loop if needed but&nbsp;is showing a button and expecting it's \
signals to&nbsp;emit functionally&nbsp;really proper?</p> <p>Cheers,</p>
<p>-kyle</p>
<p><br /></p>
<p>On 2019-06-27 14:36, Luke Campagnola wrote:</p>
<blockquote style="padding: 0px 0.4em; border-left: 2px solid #1010ff; margin: 0px;">
<div dir="ltr">
<div>Greetings,</div>
<div>I have found that when calling QMessageBox.question, the message box flashes up \
briefly before disappearing and the call returns NoButton. This behavior is present \
in both PyQt4 and PyQt5 (most recently tested on 5.9.2 from anaconda package), on \
windows (but not linux), and only if I have not called QApplication.exec_() because I \
am running in an interactive python shell.</div> <div>&nbsp;</div>
<div>Code to reproduce (run with python -i):</div>
<div>&nbsp;</div>
<div style="margin-left: 40px;">import sys<br />#from PyQt4 import QtGui as \
QtWidgets<br />from PyQt5 import QtWidgets</div> <div style="margin-left: \
40px;">&nbsp;</div> <div style="margin-left: 40px;">app = \
QtWidgets.QApplication([])<br /><br />def msg():<br />&nbsp; \
&nbsp;print(QtWidgets.QMessageBox.question(btn, "title", "message"))<br /><br />btn = \
QtWidgets.QPushButton("show messagebox")<br />btn.clicked.connect(msg)<br \
/>btn.show()<br /><br /></div> <div style="margin-left: 40px;"># message box works if \
event loop is started</div> <div style="margin-left: 40px;"># app.exec_()</div>
<div style="margin-left: 40px;">&nbsp;</div>
<div>&nbsp;</div>
<div>Cheers,</div>
<div>Luke</div>
</div>
<br />
<div class="gmail-m_-3333754831937473440gmail-m_6485799613692692490pre" \
style="margin: 0px; padding: 0px; font-family: \
monospace;">_______________________________________________<br /> PyQt mailing list \
&nbsp;&nbsp;&nbsp;<a \
href="mailto:PyQt@riverbankcomputing.com">PyQt@riverbankcomputing.com</a><br /><a \
href="https://www.riverbankcomputing.com/mailman/listinfo/pyqt" target="_blank" \
rel="noopener noreferrer">https://www.riverbankcomputing.com/mailman/listinfo/pyqt</a></div>
 </blockquote>
</div>
_______________________________________________<br /> PyQt mailing list&nbsp; &nbsp; \
<a href="mailto:PyQt@riverbankcomputing.com">PyQt@riverbankcomputing.com</a><br /><a \
href="https://www.riverbankcomputing.com/mailman/listinfo/pyqt" target="_blank" \
rel="noopener noreferrer">https://www.riverbankcomputing.com/mailman/listinfo/pyqt</a></blockquote>
 </div>
<br clear="all" />
<div>&nbsp;</div>
-- <br />
<div class="gmail-m_-3333754831937473440gmail_signature" dir="ltr">Thomas Caswell<br \
/><a href="mailto:tcaswell@gmail.com">tcaswell@gmail.com</a></div> </blockquote>
</div>
<br clear="all" />
<div>&nbsp;</div>
-- <br />
<div class="gmail_signature" dir="ltr">Thomas Caswell<br /><a \
href="mailto:tcaswell@gmail.com">tcaswell@gmail.com</a></div> </blockquote>
</body></html>


[Attachment #6 (text/plain)]

_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt


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

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