reading input and output of wx.py.shell to a textctrl

classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

reading input and output of wx.py.shell to a textctrl

linuxNewBee
I have created a wx.py.shell in my code and now user is entering command and getting response back in the shell itself.

Now on a button click I want to redirect all the commands(input) and response(output) to textctrl. Can anybody help me here ???? I tried a lot but its not working...

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: reading input and output of wx.py.shell to a textctrl

linuxNewBee
anybody ...??


On Wed, Aug 6, 2014 at 11:22 PM, Hemadri Saxena <[hidden email]> wrote:
I have created a wx.py.shell in my code and now user is entering command and getting response back in the shell itself.

Now on a button click I want to redirect all the commands(input) and response(output) to textctrl. Can anybody help me here ???? I tried a lot but its not working...

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.



--
Thanks and Regards
Hemadri Saxena
9086087510

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: reading input and output of wx.py.shell to a textctrl

Vlastimil Brom
In reply to this post by linuxNewBee
2014-08-07 5:22 GMT+02:00 Hemadri Saxena <[hidden email]>:
> I have created a wx.py.shell in my code and now user is entering command and
> getting response back in the shell itself.
>
> Now on a button click I want to redirect all the commands(input) and
> response(output) to textctrl. Can anybody help me here ???? I tried a lot
> but its not working...
>
Hi,
would possibly just redirecting sys.stdout (and probably sys.stderr)
work in this case?
cf.
http://www.blog.pythonlibrary.org/2009/01/01/wxpython-redirecting-stdout-stderr/
You could use the AppendText(...) method of a textctrl instead of
WriteText(...) too.

You should maybe keep a reference to the original stdout (and stderr)
in some variable, in order to restore it easily again, if it would be
needed in the code  to enable normal function of the shell.

However, I guess, this would be about the first posibility you tried,
hence if this won't work, some details or sample code might be needed
to see the problems and possible solutions.

hth,
  vbr

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: reading input and output of wx.py.shell to a textctrl

linuxNewBee
I have seen this link many times ....This doesn't work for shelll...There are many predefined functions of shell like readline() redirect etc...all somehow doesn't work for me ...

when I print sys.stdout its print some garbage 


On Thu, Aug 7, 2014 at 1:16 PM, Vlastimil Brom <[hidden email]> wrote:
2014-08-07 5:22 GMT+02:00 Hemadri Saxena <[hidden email]>:
> I have created a wx.py.shell in my code and now user is entering command and
> getting response back in the shell itself.
>
> Now on a button click I want to redirect all the commands(input) and
> response(output) to textctrl. Can anybody help me here ???? I tried a lot
> but its not working...
>
Hi,
would possibly just redirecting sys.stdout (and probably sys.stderr)
work in this case?
cf.
http://www.blog.pythonlibrary.org/2009/01/01/wxpython-redirecting-stdout-stderr/
You could use the AppendText(...) method of a textctrl instead of
WriteText(...) too.

You should maybe keep a reference to the original stdout (and stderr)
in some variable, in order to restore it easily again, if it would be
needed in the code  to enable normal function of the shell.

However, I guess, this would be about the first posibility you tried,
hence if this won't work, some details or sample code might be needed
to see the problems and possible solutions.

hth,
  vbr

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.



--
Thanks and Regards
Hemadri Saxena
9086087510

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: reading input and output of wx.py.shell to a textctrl

Rufus V. Smith
In reply to this post by linuxNewBee
Hemadri,

    It is poor form to bump your own message if you don't get a response on the first day.

    You should assume that nobody who had an answer for you had yet read it, and you risk
offending those who might have answered you, but decided not when you clutter up the thread
with the bump.

Rufus

(If your message had gone a month unanswered, a bump would be okay.)

On Thursday, August 7, 2014 12:46:11 PM UTC-4, Hemadri Saxena wrote:
anybody ...??


On Wed, Aug 6, 2014 at 11:22 PM, Hemadri Saxena <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="BazBwcDxhHAJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">hemadri...@...> wrote:
I have created a wx.py.shell in my code and now user is entering command and getting response back in the shell itself.


--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
C M
Reply | Threaded
Open this post in threaded view
|

Re: reading input and output of wx.py.shell to a textctrl

C M
In reply to this post by linuxNewBee
> all somehow doesn't work for me ...

Hi Hemadri.  People on this list are really helpful, but it's even easier to help if you are as specific and as clear as you can be in terms of what you are observing when something "somehow doesn't work".  For example, if you get an error, copy and paste the error into your question. 

It seems like this essay is the standard one people are referred to on this issue:
http://www.catb.org/esr/faqs/smart-questions.html

In it, for example, it says:   "saying 'it doesn't work', will get you ignored".  So, post your code, post your errors, be specific, and let's hope you can get some help.

Also, please bottom post, and not top post.  See here:
http://www.idallen.com/topposting.html

Last:  what is your overall goal?  Why do you need to make yet another shell?

Che

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: reading input and output of wx.py.shell to a textctrl

linuxNewBee
My goal is I have a Shell wx.py.shell and a textctrl...I want to grab all the command response from shell(shell input and output). 

For accomplishing this I want to control stdin, stdout and stderror of the shell and do some processing(parsing) and send to the textctrl.

I tried the following :
1. Shell has many predefined functions which I used in code as self.shell.readline() which print garbage as below. so this doesn't work for me.

<idlelib.rpc.RPCProxy object at 0x0000000002A8DD30>

2. From link you were referring  this is following class RedirectText as below
class RedirectText(object):
    def __init__(self,aWxTextCtrl):
        self.out=aWxTextCtrl
def write(self, string):
    wx.CallAfter(self.out.WriteText, string)
# redirect text here
        redir=RedirectText(log)
        sys.stdout=redir
so I tried to use 

text = sys.stdout (to read whats there in stdout)..but that doesn't work either again garbage is return

Hope this make sense now.

Can 


On Thu, Aug 7, 2014 at 2:00 PM, C M <[hidden email]> wrote:
> all somehow doesn't work for me ...

Hi Hemadri.  People on this list are really helpful, but it's even easier to help if you are as specific and as clear as you can be in terms of what you are observing when something "somehow doesn't work".  For example, if you get an error, copy and paste the error into your question. 

It seems like this essay is the standard one people are referred to on this issue:
http://www.catb.org/esr/faqs/smart-questions.html

In it, for example, it says:   "saying 'it doesn't work', will get you ignored".  So, post your code, post your errors, be specific, and let's hope you can get some help.

Also, please bottom post, and not top post.  See here:
http://www.idallen.com/topposting.html

Last:  what is your overall goal?  Why do you need to make yet another shell?

Che

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.



--
Thanks and Regards
Hemadri Saxena
9086087510

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: reading input and output of wx.py.shell to a textctrl

Vlastimil Brom
2014-08-07 20:18 GMT+02:00 Hemadri Saxena <[hidden email]>:

> My goal is I have a Shell wx.py.shell and a textctrl...I want to grab all
> the command response from shell(shell input and output).
>
> For accomplishing this I want to control stdin, stdout and stderror of the
> shell and do some processing(parsing) and send to the textctrl.
>
> I tried the following :
> 1. Shell has many predefined functions which I used in code as
> self.shell.readline() which print garbage as below. so this doesn't work for
> me.
>
> <idlelib.rpc.RPCProxy object at 0x0000000002A8DD30>
>
> 2. From link you were referring  this is following class RedirectText as
> below
>
> class RedirectText(object):
>     def __init__(self,aWxTextCtrl):
>         self.out=aWxTextCtrl
>
> def write(self, string):
>     wx.CallAfter(self.out.WriteText, string)
>
> # redirect text here
>         redir=RedirectText(log)
>         sys.stdout=redir
>
> so I tried to use
>
> text = sys.stdout (to read whats there in stdout)..but that doesn't work
> either again garbage is return
>
> Hope this make sense now.
>
> Can
>> --
> --
> Thanks and Regards
> Hemadri Saxena
> 9086087510
>
>

Hi,
with the details, you provided now, some problems can be identified;
 most importantly:
text = sys.stdout
won't work like you would probably indend - it just binds the name
text to the stdout object,
it won't call it, as there are no parens ...(), and even if it were
called, it wouldn't return the text content.

Check the mentioned sample
http://www.blog.pythonlibrary.org/2009/01/01/wxpython-redirecting-stdout-stderr/

the important part is to replace the custom writable object as sys.stdout

        # redirect text here
        redir=RedirectText(log)
        sys.stdout=redir

in this way, it gets called whenever some output is neede (like in
response to print(...) etc.)

Furthermore,
 <idlelib.rpc.RPCProxy object at 0x0000000002A8DD30>
is rather strange in this context
it likely originates form Idle - the builtin python ide/shell using
another gui - tkinter.

There can be various unwanted interactions between different gui
toolkits and this should normally be avioded.

hth,
  vbr

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: reading input and output of wx.py.shell to a textctrl

Andrea Gavana
In reply to this post by linuxNewBee
Hi,


On 7 August 2014 20:18, Hemadri Saxena <[hidden email]> wrote:
My goal is I have a Shell wx.py.shell and a textctrl...I want to grab all the command response from shell(shell input and output). 

For accomplishing this I want to control stdin, stdout and stderror of the shell and do some processing(parsing) and send to the textctrl.

I tried the following :
1. Shell has many predefined functions which I used in code as self.shell.readline() which print garbage as below. so this doesn't work for me.

<idlelib.rpc.RPCProxy object at 0x0000000002A8DD30>


This doesn't make any sense. A wxPython shell cannot possibly return a IDLE thing, it's just weird. I don't know the PyShell code so well but I would be surprised if you get an IDLE process inside a wx one.

You will have to show us a small, runnable sample app of what you have tried so far as we do not currently have a crystal ball to guess it. I'm sure you will get a ton more help if you did this.

Please do not top post.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://www.infinity77.net

# ------------------------------------------------------------- #
def ask_mailing_list_support(email):

    if mention_platform_and_version() and include_sample_app():
        send_message(email)
    else:
        install_malware()
        erase_hard_drives()
# ------------------------------------------------------------- #

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: reading input and output of wx.py.shell to a textctrl

linuxNewBee
Let me put my code and elaborate it more...

In shell I have defied a textctrl and bind my shell  to a  event  when user press "enter"

self.LogArea = wx.TextCtrl(self, style=wx.TE_MULTILINE|wx.TE_READONLY)
self.shell.Bind(wx.EVT_KEY_DOWN, self.onEnter)

onEnter has the following code

def onEnter(self, event):
        """"""
        keycode = event.GetKeyCode()
        if keycode == wx.WXK_RETURN or keycode == wx.WXK_NUMPAD_ENTER: 
            print "you pressed ENTER!"

           #commented code which I tried which is giving me garbage
            #print self.shell.readline()
            #print self.shell.redirectStdin()
            #print self.shell.redirectStdout()
            #self.LogArea .AppendText(self.shell.redirectStdout())


            redir =RedirectText(self.LogArea )
            sys.stdout=redir

            #self.shell.prompt()           
        event.Skip()

Now when I run this it launches the Shell and on prompt I entered "Print "hello world""  this print "hello world" on the shell it self and on logarea (textctrl) it printed "you pressed ENTER!"... 


I want to control the shell input and output...I want my  logarea (textctrl) to print "hello world" instead of  "you pressed ENTER!"

Is there anyway to redirect the shell input/output


On Thu, Aug 7, 2014 at 2:46 PM, Andrea Gavana <[hidden email]> wrote:
Hi,


On 7 August 2014 20:18, Hemadri Saxena <[hidden email]> wrote:
My goal is I have a Shell wx.py.shell and a textctrl...I want to grab all the command response from shell(shell input and output). 

For accomplishing this I want to control stdin, stdout and stderror of the shell and do some processing(parsing) and send to the textctrl.

I tried the following :
1. Shell has many predefined functions which I used in code as self.shell.readline() which print garbage as below. so this doesn't work for me.

<idlelib.rpc.RPCProxy object at 0x0000000002A8DD30>


This doesn't make any sense. A wxPython shell cannot possibly return a IDLE thing, it's just weird. I don't know the PyShell code so well but I would be surprised if you get an IDLE process inside a wx one.

You will have to show us a small, runnable sample app of what you have tried so far as we do not currently have a crystal ball to guess it. I'm sure you will get a ton more help if you did this.

Please do not top post.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://www.infinity77.net

# ------------------------------------------------------------- #
def ask_mailing_list_support(email):

    if mention_platform_and_version() and include_sample_app():
        send_message(email)
    else:
        install_malware()
        erase_hard_drives()
# ------------------------------------------------------------- #

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.



--
Thanks and Regards
Hemadri Saxena
9086087510

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: reading input and output of wx.py.shell to a textctrl

Andrea Gavana
Hi,


On 7 August 2014 21:17, Hemadri Saxena wrote:
Let me put my code and elaborate it more...

In shell I have defied a textctrl and bind my shell  to a  event  when user press "enter"

self.LogArea = wx.TextCtrl(self, style=wx.TE_MULTILINE|wx.TE_READONLY)
self.shell.Bind(wx.EVT_KEY_DOWN, self.onEnter)

onEnter has the following code

def onEnter(self, event):
        """"""
        keycode = event.GetKeyCode()
        if keycode == wx.WXK_RETURN or keycode == wx.WXK_NUMPAD_ENTER: 
            print "you pressed ENTER!"

           #commented code which I tried which is giving me garbage
            #print self.shell.readline()
            #print self.shell.redirectStdin()
            #print self.shell.redirectStdout()
            #self.LogArea .AppendText(self.shell.redirectStdout())


            redir =RedirectText(self.LogArea )
            sys.stdout=redir

            #self.shell.prompt()           
        event.Skip()

Now when I run this it launches the Shell and on prompt I entered "Print "hello world""  this print "hello world" on the shell it self and on logarea (textctrl) it printed "you pressed ENTER!"... 


I want to control the shell input and output...I want my  logarea (textctrl) to print "hello world" instead of  "you pressed ENTER!"

Is there anyway to redirect the shell input/output


I guess my written English is not good enough here:

1. Please do *not* top post: 

top-post: n., v.
[common] To put the newly-added portion of an email or Usenet response before the quoted part, as opposed to the more logical sequence of quoted portion first with original following.


2. The code you posted is *not* a runnable sample. You should not instantiate a RedirectText class every time the user presses the Enter key, but rather initialize it in your class __init__ method, whatever your class is. What is self.shell? How do we take your piece of code and run it standalone? That's the purpose of a small, runnable sample app, and it's the only way we will be able to help you in fixing your problems.


Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://www.infinity77.net

# ------------------------------------------------------------- #
def ask_mailing_list_support(email):

    if mention_platform_and_version() and include_sample_app():
        send_message(email)
    else:
        install_malware()
        erase_hard_drives()
# ------------------------------------------------------------- #

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: reading input and output of wx.py.shell to a textctrl

Nathan McCorkle
FYI the web interface on mobile at least doesn't give any quoted text, so top/bottom posting is moot.


--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: reading input and output of wx.py.shell to a textctrl

Nathan McCorkle
In reply to this post by Vlastimil Brom
Vbr, you don't need to save the original stdout, as it is found in sys.__stdout__ (as is stderr).

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: reading input and output of wx.py.shell to a textctrl

Andrea Gavana
In reply to this post by Nathan McCorkle



On 8 August 2014 00:05, Nathan McCorkle <[hidden email]> wrote:
FYI the web interface on mobile at least doesn't give any quoted text, so top/bottom posting is moot.


--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.


That is irrelevant, not everyone reads wxPython-related emails via the mobile. And then it depends on the mobile, my iPhone does the right things. the rule always applies: do not top post.


--
Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://www.infinity77.net

# ------------------------------------------------------------- #
def ask_mailing_list_support(email):

    if mention_platform_and_version() and include_sample_app():
        send_message(email)
    else:
        install_malware()
        erase_hard_drives()
# ------------------------------------------------------------- #

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: reading input and output of wx.py.shell to a textctrl

Vlastimil Brom
In reply to this post by Nathan McCorkle
2014-08-08 0:07 GMT+02:00 Nathan McCorkle <[hidden email]>:
> Vbr, you don't need to save the original stdout, as it is found in sys.__stdout__ (as is stderr).
>
Well, it may be ok, in most cases, but there are cases of multiple
manipulations with stdout ...  the OP's scenario is likely one of
them, as pyshell changes it by itself and then it changes once more in
user code, cf. (in pyshell etc.):
>>> import sys
>>> sys.stdout
<wx.py.pseudo.PseudoFileOut object at 0x02B56CF0>
>>> sys.__stdout__
<_io.TextIOWrapper name='<stdout>' mode='w' encoding='cp852'>
>>>

vbr

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.