在 GTK 构件中使用 Python VTE 库嵌入虚拟终端[译]
原文: python embedding virtual terminal gtk widget python vte library
python-vte bindings allow you to embed a simplistic virtual terminal in any of your GTK apps real easy. This tutorial will show how you can add a terminal to a widget in less than 30 lines, 4 lines only being necessary to set a the terminal session.
Python-vte 绑定允许你在任意一个GTK 程序中十分容易地嵌入一个简单的虚拟终端。本指南将向您展示如何使用少于30 行代码在一个构件上添加一个终端,其中有4 行代码是设置终端会话所必须的。
A simple Terminal with python-vte
一个简单的python-vte 终端
With python-vte bindings, all that is necessary to have a working terminal is to:
使用python-vte 绑定,生成一个运行的终端必须具备以下条件:
instanciate the vte terminal object
vte 终端对象的一个实例;
tell it what to do when the terminal session is killed via connect child-exited signal
当终端会话结束时,通过使用child-exited 信号连接实例,告诉它怎么做;
and finaly fork a child process which will default to the default user shell
最后fork 一个设置默认用户shell 的子进程。
Here is the bit of code required to add a virtual terminal to a GTK window:
这里有一段代码,要求在GTK 窗体中添加一个虚拟终端:
1 | #!/usr/bin/env python |
That’s it, download the script attached to this tutorial, make it executable and run it. You will have a functioning terminal!
至此,下载本指南附件中的脚本,赋于可执行权限,然后运行。您将获得一个运行的终端!