[GTK] Virtual python shell with Vte.Pty.spawn_async() - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: [GTK] Virtual python shell with Vte.Pty.spawn_async() (/thread-16720.html) |
[GTK] Virtual python shell with Vte.Pty.spawn_async() - jiri - Mar-11-2019 I would like add virtual python shell with Vte to my GTK3.0 python3 app and I am able to do this with spawn_sync() method, but this method is deprecated, so I would like to do it with preferred way with Vte.Pty.spawn_async(), but I dont understeand how .... I tried some parts of code, but with no luck. Pleas, give me someone some working code in python. For example, I tried variant like this: import gi gi.require_version('Gtk', '3.0') gi.require_version('Vte', '2.91') from gi.repository import Gtk, Vte class TheWindow(Gtk.Window): def __init__(self): Gtk.Window.__init__(self, title="GTK3 IDE") self.box = Gtk.HBox(spacing=6) self.add(self.box) self.terminal = Vte.Terminal() self.terminal.pty_new_sync(Vte.PtyFlags.DEFAULT) self.pty = Vte.Pty() self.pty.new_sync(Vte.PtyFlags.DEFAULT, None) self.pty.spawn_async( None, ["/bin/python"], None, GLib.SpawnFlags.DO_NOT_REAP_CHILD, None, None, -1 ) self.terminal.set_pty(self.pty)Thanks a lot for any help. RE: [GTK] Virtual python shell with Vte.Pty.spawn_async() - jiri - Mar-14-2019 I find some mistakes in my code, now it is working great, there is final solution: import gi gi.require_version('Gtk', '3.0') gi.require_version('Vte', '2.91') from gi.repository import Gtk, Vte, GLib, Pango, Gio class TheWindow(Gtk.Window): def __init__(self): Gtk.Window.__init__(self, title="GTK3 IDE") self.set_default_size(600, 300) terminal = Vte.Terminal() #pty = terminal.pty_new_sync(Vte.PtyFlags.DEFAULT) pty = Vte.Pty.new_sync(Vte.PtyFlags.DEFAULT) terminal.set_pty(pty) pty.spawn_async( None, ["/bin/python"], None, GLib.SpawnFlags.DO_NOT_REAP_CHILD, None, None, -1, None, self.ready ) #self.terminal.get_pty(self.pty) box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) scroller = Gtk.ScrolledWindow() scroller.set_hexpand(True) scroller.set_vexpand(True) scroller.add(terminal) box.pack_start(scroller, False, True, 2) self.add(box) def ready(self, pty, task): print('pty ', pty) win=TheWindow() win.connect('destroy', Gtk.main_quit) win.show_all() Gtk.main() RE: [GTK] Virtual python shell with Vte.Pty.spawn_async() - Axel_Erfurt - Oct-20-2019 with your code you can not execute a command try import gi gi.require_version('Gtk', '3.0') gi.require_version('Vte', '2.91') from gi.repository import Gtk, Vte, GLib, Pango, Gio import os class TheWindow(Gtk.Window): def __init__(self): Gtk.Window.__init__(self, title="GTK3 IDE") self.set_default_size(600, 300) terminal = Vte.Terminal() pty = Vte.Pty.new_sync(Vte.PtyFlags.DEFAULT) terminal.set_pty(pty) terminal.spawn_sync( Vte.PtyFlags.DEFAULT, os.environ['HOME'], ["/bin/sh"], [], GLib.SpawnFlags.DO_NOT_REAP_CHILD, None, None, ) box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) scroller = Gtk.ScrolledWindow() scroller.set_hexpand(True) scroller.set_vexpand(True) scroller.add(terminal) box.pack_start(scroller, False, True, 2) self.add(box) def ready(self, pty, task): print('pty ', pty) win=TheWindow() win.connect('destroy', Gtk.main_quit) win.show_all() Gtk.main() |