[PyQt] Using Python's "print" or sys.stdout.write( "str" ) inside of PyQt4.

Hans-Peter Jansen hpj at urpla.net
Thu Sep 25 14:14:51 BST 2008


Am Donnerstag, 25. September 2008 schrieb Peter Lindener:
> Dear
>    PyQt4 developers -
>
>   I am currently running Python 2.5,2, with IDLE version 1.2.2 under
> Win_XP.
>
>   I'm new to using PyQt along with PyOpenGL. I have searched a bit and
> surprised, I was unable to find the answer to my most basic question
> concerning the functionality of Python's print statement when running the
> PyQt4_OpenGL demo from Python's default interaction shell, IDLE.  It
> seems that Qt's interaction loop freezes up once the stdout buffer is
> perhaps full?,  in any case,  using Python print statements from inside a
> PyQt program seems to need more supporting infrastructure than that
> included in the attached PyQtOpenGL demo..
>
> Print statements on lines 53-62 of the attached program are currently
> commented out,
>  such that it runs much like the original "hellogl.py" demo typically
> found on the path:
>
> C:\Python25\Lib\site-packages\PyQt4\examples\opengl.py
>
>    If one reintroduces these "print" and/or "sys.stdout.write()" program
> lines, one does find some of the text making it back to IDLE's Python
> shell window...  but soon enough we seem to encounter program interaction
> death.....
>
>    I have heard from some that Python's default interaction shell IDLE is
> not all so well equipped to make all of this work,  Perhaps I may need to
> be looking at using a different development shell or IDE?,  is there a
> common denominator as to how stdout and stdin are supposed to work in a
> Python environment, and do most of them handle it in the same way....it
> seems like some of this may still require some further development of
> either the IDE's involved, PyQt4 or perhaps Qt4, depending on where best
> to fix this problem...any suggestions?

I do use stdout/stderr all the time (or module logging in more advanced 
projects) but IDLE and XP are missing in the equation here. It definitely 
sounds like an IDLE problem - try to run your scripts in a cmd shell 
directly. 

If you are in need for an IDE, try eric. It shouldn't suffer from those 
issues, but I always use a separate unix shell in an xterm with eric side 
by side, since I use varying command line parameters and a huge backlog 
buffer all the time..

>    I gather there may be an easy way to establish a Qt window for
> displaying the stdout stream, and /or a way to keep Python's print
> statements working as they typically do inside Python's interaction
> shell.....   It would be great if likewise, some of Python's default
> keyboard/ "rawinput()" and sys.stdin.read()" inputput logic also could
> work as python programmers are familiar..   I'm sure this is covered
> somewhere, perhaps partly in Qt4's doc's, and perhaps somewhere in PyQt's
> notes.... a pointer to any related documentation would be great!

You're mixing different "universes" here, while you should decide on one, at 
least when it comes to interactive input processing. Mixing those will 
never play well..

>    Please forgive me for not yet understanding the nuance of this,  I'm
> still pretty new to using PyQt along with OpenGL.
>
>    Thanks ahead of time for any assistance you may provide.
>        All the best
>             -Peter

Cheers,
Pete


More information about the PyQt mailing list