Thanks for the hints, Robin!
I somehow manage to make stdout replacement work within wx shell,
however, it looks like too trivial a mistake in the original code, if
it would realy be the only source of the mentioned problems and I
can't claim, I fully understand the code of
C:\Python27\Lib\site-packages\wx-2.9.3-msw\wx\py\shell.py
C:\Python27\Lib\site-packages\wx-2.9.3-msw\wx\py\pseudo.py
C:\Python27\Lib\site-packages\wx-2.9.3-msw\wx\py\interpreter.py
...
However, the only changes I made are the added "else" branches in
interpreter.py - in the functions runsource(...) and runmodule(...)
e.g.:
# If sys.std* is still what we set it to, then restore it.
# But, if the executed source changed sys.std*, assume it was
# meant to be changed and leave it. Power to the people.
if sys.stdin == self.stdin:
sys.stdin = stdin
### ADDED PART ####
else:
self.stdin = sys.stdin
···
2012/7/11 Robin Dunn <robin@alldunn.com>:
On 7/11/12 5:27 AM, Vlastimil Brom wrote:
Hi all,
I'd like to ask about redirecting the output in the wxpython shell. It
seems, its own proxy is somehow protected and cannot be replaced.
Correct. It is setting it to the PseudoFile every time a line or block of
code is executed and then being reset back to the original sys values after
that is done. However it looks like it was intended to not do the restore
if the sys.std* values were changed while the code is executing, (see
various comments in wx.py.interpreter) but it appears that something else is
still changing them back. There is also the redirectStdout and etc.
functions that are available via the shell object, (see wx.py.shell) but
they do not seem to be working as expected either.
If you can dig in and solve these issues and provide a patch it would be
appreciated.
--
Robin Dunn
Software Craftsman
http://wxPython.org
--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en
#######
etc.
It seems, that the functions kept reseting sys.std* according to
self.std*, which were set on initialisation of the Interpreter
instance, with this update, the changes made from the code are taken
into account permanently.
The diff would be:
=================================
--- interpreter.py
+++ interpreter.py - updated
@@ -100,0 +101,2 @@
+ else:
+ self.stdin = sys.stdin
@@ -102,0 +105,2 @@
+ else:
+ self.stdout = sys.stdout
@@ -104,0 +109,2 @@
+ else:
+ self.stderr = sys.stderr
@@ -117,0 +124,2 @@
+ else:
+ self.stdin = sys.stdin
@@ -119,0 +128,2 @@
+ else:
+ self.stdout = sys.stdout
@@ -121,0 +132,2 @@
+ else:
+ self.stderr = sys.stderr
======================================
PyShell 0.9.8 - The Flakiest Python Shell
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
"UPDATED SHELL"
'UPDATED SHELL'
import sys
sys.stdout
<wx.py.pseudo.PseudoFileOut instance at 0x0368C418>
from cStringIO import StringIO
old_stdout = sys.stdout
sys.stdout = my_stdout = StringIO()
sys.stdout
2
3
4
sys.stdout = old_stdout
5
5
my_stdout.getvalue()
'<cStringIO.StringO object at 0x036A81C0>\n2\n3\n4\n'
my_stdout
<cStringIO.StringO object at 0x036A81C0>
sys.stdout
<wx.py.pseudo.PseudoFileOut instance at 0x0368C418>
=================================
Although these changes make the wx shell work for me like I'd expect,
I'd like to ask someone more experienced to check the correctness.
Or would it be appropriate to send this directly to the wxpython tracker?
Regarding the shell functions redirectStdout etc., I'm not sure, how
they were supposed to work, but maybe they would be used especially
for reseting the stdout ... to the implicit value (with
redirect=True)?
Thanks,
vbr