3

It's my first post. I read a lot of subjects per day on Stackoverflow, and i appreciate to find there some help. And today it's my turn to ask a question because i didn't find solution to my need.

I want to have a terminal in the app i'm writing; i(ve read a lot about a lots (subprocess, thread, pty, etc, etc), but i didn't find a simple solution as this one written with pygtk and vte. Here is the code:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import pygtk
pygtk.require('2.0')
import gtk, vte

window = gtk.Window()
window.resize(600,400)
window.show()

term  = vte.Terminal()
pid   = term.fork_command('bash')
term.set_emulation('xterm')
term.show()

window.add(term)
window.show_all()
window.connect("destroy", lambda w: gtk.main_quit())
gtk.main()

Do you know a way to do that with wxPython?

Thanks a lot for your help, many thanks!! :)

Edit0:

I have to precise that:

  • i'm talking about a bash shell (as in the code above), not a python shell
  • i write it for linux

Edit1:

Thanks for your answers! :)

Joran, i've read already this question, and i've tried all the code proposed. Although it's interesting, that's not the way i want to do it as you can see in my question. It seems to be very difficult to write an app that recreate a terminal emulator.

That's why i'm searching for a solution like the code i proposed.

pythonm, i don't see the relation between your idea and my question...

Thanks for your help!

Edit2

Please look at this short code:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
import os
import pty


shell = os.environ['SHELL']
script = open('typescript', 'w')

def read(fd):
    data = os.read(fd, 1024)
    script.write(data)
    return data

pty.spawn(shell, read)

Any idea to "put" this in a widget with wxpython?

Edit3

Look that too:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import pexpect


c = pexpect.spawn ('bash -i')
c.interact()
c.kill(1) 

So simple and so easy to do...

Tell me if it's impossible to embed that in a wx widget.

ptomato
  • 56,175
  • 13
  • 112
  • 165
shtefh
  • 51
  • 5

1 Answers1

1

I've seen this question come up a couple times in the last month or two. The answer is no, wxPython doesn't have this capability. You would have to use subprocess to launch something and communicate with it.

Mike Driscoll
  • 32,629
  • 8
  • 45
  • 88