How to add vte terminal widget in GTK3?
Here a basic example:
#!/usr/bin/env python
from gi.repository import Gtk, Vte
from gi.repository import GLib
import os
terminal = Vte.Terminal()
terminal.spawn_sync(
Vte.PtyFlags.DEFAULT,
os.environ['HOME'],
["/bin/sh"],
[],
GLib.SpawnFlags.DO_NOT_REAP_CHILD,
None,
None,
)
win = Gtk.Window()
win.connect('delete-event', Gtk.main_quit)
win.add(terminal)
win.show_all()
Gtk.main()
Building on ADcomp's answer to address wanting to add them dynamically in the future, I think you might want to subclass Vte.terminal.
#!/usr/bin/env python
from gi.repository import Gtk, Vte
from gi.repository import GLib
import os
class MyTerm(Vte.Terminal):
def __init__(self, *args, **kwds):
super(MyTerm, self).__init__(*args, **kwds)
self.spawn_sync(
Vte.PtyFlags.DEFAULT,
os.environ['HOME'],
["/bin/sh"],
[],
GLib.SpawnFlags.DO_NOT_REAP_CHILD,
None,
None,
)
win = Gtk.Window()
win.connect('delete-event', Gtk.main_quit)
bigbox = Gtk.Box()
win.add(bigbox)
bigbox.add(MyTerm())
bigbox.add(MyTerm())
win.show_all()
Gtk.main()
Since VTE 0.38, vte_terminal_fork_command_full ()
has been renamed to vte_terminal_spawn_sync ()
. So if you are using newer versions, you have to change @ADcomp's answer into the following:
terminal.spawn_sync(
Vte.PtyFlags.DEFAULT,
os.environ['HOME'],
["/bin/sh"],
[],
GLib.SpawnFlags.DO_NOT_REAP_CHILD,
None,
None,
)