python terminator_linux为什么运行terminator还需要python

本文档揭示了terminator Linux终端模拟器启动时为何需要Python。通过查看其源代码,可以发现terminator是一个使用Python编写的程序,依赖于GTK+、Pango和gobject等库。如果缺少必要的环境,如$DISPLAY变量未设置或缺少Python绑定,terminator将无法正常运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

展开全部

# Konvict @ localhost in ~32313133353236313431303231363533e78988e69d8331333363373163 [16:51:09]

#$ cat /usr/bin/terminator

#!/usr/bin/python

#    Terminator - multiple gnome terminals in one window

#    Copyright (C) 2006-2010  cmsj@tenshu.net

#

#    This program is free software; you can redistribute it and/or modify

#    it under the terms of the GNU General Public License as published by

#    the Free Software Foundation, version 2 only.

#

#    This program is distributed in the hope that it will be useful,

#    but WITHOUT ANY WARRANTY; without even the implied warranty of

#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

#    GNU General Public License for more details.

#

#    You should have received a copy of the GNU General Public License

#    along with this program; if not, write to the Free Software

#    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301

#    USA

"""Terminator by Chris Jones """

import sys

import os

try:

ORIGCWD = os.getcwd()

except OSError:

ORIGCWD = os.path.expanduser("~")

# Check we have simple basics like Gtk+ and a valid $DISPLAY

try:

import pygtk

pygtk.require ("2.0")

# pylint: disable-msg=W0611

import gtk, pango, gobject

if gtk.gdk.display_get_default() == None:

print('You need to run terminator in an X environment. ' \

'Make sure $DISPLAY is properly set')

sys.exit(1)

except ImportError:

print('You need to install the python bindings for ' \

'gobject, gtk and pango to run Terminator.')

sys.exit(1)

import terminatorlib.optionparse

from terminatorlib.terminator import Terminator

from terminatorlib.factory import Factory

from terminatorlib.version import APP_NAME, APP_VERSION

from terminatorlib.util import dbg, err

if __name__ == '__main__':

dbus_service = None

dbg ("%s starting up, version %s" % (APP_NAME, APP_VERSION))

OPTIONS = terminatorlib.optionparse.parse_options()

# Attempt to import our dbus server. If one exists already we will just

# connect to that and ask for a new window. If not, we will create one and

# continue. Failure to import dbus, or the global config option "dbus"

# being False will cause us to continue without the dbus server and open a

# window.

try:

if OPTIONS.nodbus:

dbg('dbus disabled by command line')

raise ImportError

from terminatorlib import ipc

import dbus

try:

dbus_service = ipc.DBusService()

except ipc.DBusException:

dbg('Unable to become master process, operating via DBus')

# get rid of the None and True types so dbus can handle them (empty

# and 'True' strings are used instead), also arrays are joined

# (the -x argument for example)

optionslist = {}

for opt, val in OPTIONS.__dict__.items():

if type(val) == type([]):

val = ' '.join(val)

if val == True:

val = 'True'

optionslist[opt] = val and '%s'%val or ''

optionslist = dbus.Dictionary(optionslist, signature='ss')

if OPTIONS.new_tab:

dbg('Requesting a new tab')

ipc.new_tab(optionslist)

else:

dbg('Requesting a new window')

ipc.new_window(optionslist)

sys.exit()

except ImportError:

dbg('dbus not imported')

pass

MAKER = Factory()

TERMINATOR = Terminator()

TERMINATOR.set_origcwd(ORIGCWD)

TERMINATOR.set_dbus_data(dbus_service)

TERMINATOR.reconfigure()

try:

dbg('Creating a terminal with layout: %s' % OPTIONS.layout)

TERMINATOR.create_layout(OPTIONS.layout)

except (KeyError,ValueError), ex:

err('layout creation failed, creating a window ("%s")' % ex)

TERMINATOR.new_window()

TERMINATOR.layout_done()

if OPTIONS.debug > 2:

import terminatorlib.debugserver as debugserver

# pylint: disable-msg=W0611

import threading

gtk.gdk.threads_init()

(DEBUGTHREAD, DEBUGSVR) = debugserver.spawn(locals())

TERMINATOR.debug_address = DEBUGSVR.server_address

try:

gtk.main()

except KeyboardInterrupt:

pass

因为terminator是用python写的。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值