2020-04-05 14:36:06 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
2007-07-28 01:33:48 +00:00
|
|
|
# Terminator - multiple gnome terminals in one window
|
2010-01-04 23:56:28 +00:00
|
|
|
# Copyright (C) 2006-2010 cmsj@tenshu.net
|
2007-07-28 01:33:48 +00:00
|
|
|
#
|
|
|
|
# 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
|
2008-09-03 23:52:04 +00:00
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
|
|
|
# USA
|
2007-07-28 01:33:48 +00:00
|
|
|
|
2008-02-12 22:06:19 +00:00
|
|
|
"""Terminator by Chris Jones <cmsj@tenshu.net>"""
|
2007-12-27 17:44:38 +00:00
|
|
|
|
2010-01-04 12:57:14 +00:00
|
|
|
import sys
|
2010-01-29 23:52:21 +00:00
|
|
|
import os
|
2015-11-30 20:54:23 +00:00
|
|
|
import psutil
|
|
|
|
import pwd
|
2013-01-30 12:27:02 +00:00
|
|
|
try:
|
|
|
|
ORIGCWD = os.getcwd()
|
|
|
|
except OSError:
|
|
|
|
ORIGCWD = os.path.expanduser("~")
|
2008-05-22 14:37:59 +00:00
|
|
|
|
2010-01-04 23:52:57 +00:00
|
|
|
# Check we have simple basics like Gtk+ and a valid $DISPLAY
|
2008-01-03 08:10:39 +00:00
|
|
|
try:
|
2014-09-19 14:08:08 +00:00
|
|
|
import gi
|
2015-11-07 00:15:46 +00:00
|
|
|
gi.require_version('Gtk','3.0')
|
2010-01-05 09:24:44 +00:00
|
|
|
# pylint: disable-msg=W0611
|
2014-09-19 14:10:43 +00:00
|
|
|
from gi.repository import Gtk, Gdk
|
2010-01-04 23:52:57 +00:00
|
|
|
|
2014-09-19 14:08:08 +00:00
|
|
|
if Gdk.Display.get_default() == None:
|
2010-01-04 23:52:57 +00:00
|
|
|
print('You need to run terminator in an X environment. ' \
|
|
|
|
'Make sure $DISPLAY is properly set')
|
|
|
|
sys.exit(1)
|
2008-07-02 09:16:52 +00:00
|
|
|
|
2008-07-16 23:54:21 +00:00
|
|
|
except ImportError:
|
2010-01-04 23:52:57 +00:00
|
|
|
print('You need to install the python bindings for ' \
|
|
|
|
'gobject, gtk and pango to run Terminator.')
|
|
|
|
sys.exit(1)
|
2008-06-09 13:15:30 +00:00
|
|
|
|
2010-01-04 23:52:57 +00:00
|
|
|
import terminatorlib.optionparse
|
2010-01-11 20:11:35 +00:00
|
|
|
from terminatorlib.terminator import Terminator
|
2010-01-04 23:52:57 +00:00
|
|
|
from terminatorlib.factory import Factory
|
|
|
|
from terminatorlib.version import APP_NAME, APP_VERSION
|
2010-02-01 12:11:44 +00:00
|
|
|
from terminatorlib.util import dbg, err
|
2013-08-28 21:09:17 +00:00
|
|
|
from terminatorlib.layoutlauncher import LayoutLauncher
|
2020-09-20 20:54:10 +00:00
|
|
|
from terminatorlib.configjson import ConfigJson
|
2008-06-17 10:15:28 +00:00
|
|
|
|
2007-07-29 02:06:52 +00:00
|
|
|
if __name__ == '__main__':
|
2015-08-10 20:51:56 +00:00
|
|
|
# Workaround for IBus intefering with broadcast when using dead keys
|
|
|
|
# Environment also needs IBUS_DISABLE_SNOOPER=1, or double chars appear
|
|
|
|
# in the receivers.
|
2015-11-30 20:54:23 +00:00
|
|
|
username = pwd.getpwuid(os.getuid()).pw_name
|
2020-06-03 18:44:19 +00:00
|
|
|
ibus_running = [p for p in psutil.process_iter() if p.name() == 'ibus-daemon' and p.username() == username]
|
2015-11-30 20:54:23 +00:00
|
|
|
ibus_running = len(ibus_running) > 0
|
|
|
|
if ibus_running:
|
|
|
|
os.environ['IBUS_DISABLE_SNOOPER']='1'
|
2015-08-10 20:51:56 +00:00
|
|
|
|
2011-08-25 21:10:04 +00:00
|
|
|
dbus_service = None
|
|
|
|
|
2010-01-04 23:52:57 +00:00
|
|
|
dbg ("%s starting up, version %s" % (APP_NAME, APP_VERSION))
|
|
|
|
|
2020-08-28 20:51:37 +00:00
|
|
|
OPTIONS,dbus_options = terminatorlib.optionparse.parse_options()
|
2008-06-15 10:15:45 +00:00
|
|
|
|
2020-09-20 20:54:10 +00:00
|
|
|
if OPTIONS.configjson:
|
2020-09-24 12:19:58 +00:00
|
|
|
configjson = ConfigJson()
|
|
|
|
layoutname = configjson.extend_config(OPTIONS.configjson)
|
2020-09-20 20:54:10 +00:00
|
|
|
if layoutname and ((not OPTIONS.layout) or OPTIONS.layout == 'default'):
|
|
|
|
OPTIONS.layout = layoutname
|
2020-09-24 12:19:58 +00:00
|
|
|
if not OPTIONS.profile:
|
|
|
|
OPTIONS.profile = configjson.get_profile_to_use()
|
2020-09-20 20:54:10 +00:00
|
|
|
|
2020-05-06 15:58:47 +00:00
|
|
|
TERMINATOR = Terminator()
|
|
|
|
TERMINATOR.set_origcwd(ORIGCWD)
|
|
|
|
|
2013-08-28 21:09:17 +00:00
|
|
|
if OPTIONS.select:
|
|
|
|
# launch gui, return selection
|
|
|
|
LAYOUTLAUNCHER=LayoutLauncher()
|
|
|
|
else:
|
2015-09-01 20:59:36 +00:00
|
|
|
# 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
|
2015-09-19 03:25:25 +00:00
|
|
|
import dbus
|
2015-09-01 20:59:36 +00:00
|
|
|
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)
|
2017-02-06 07:43:44 +00:00
|
|
|
if OPTIONS.working_directory is None:
|
|
|
|
OPTIONS.working_directory = ORIGCWD
|
2020-08-28 20:51:37 +00:00
|
|
|
optionslist = dbus.Dictionary(dbus_options, signature='ss')
|
2015-09-01 20:59:36 +00:00
|
|
|
if OPTIONS.new_tab:
|
|
|
|
dbg('Requesting a new tab')
|
2015-09-19 03:25:25 +00:00
|
|
|
ipc.new_tab_cmdline(optionslist)
|
2015-09-01 20:59:36 +00:00
|
|
|
else:
|
|
|
|
dbg('Requesting a new window')
|
2015-09-19 03:25:25 +00:00
|
|
|
ipc.new_window_cmdline(optionslist)
|
2015-09-01 20:59:36 +00:00
|
|
|
sys.exit()
|
|
|
|
except ImportError:
|
|
|
|
dbg('dbus not imported')
|
|
|
|
pass
|
|
|
|
|
|
|
|
MAKER = Factory()
|
|
|
|
TERMINATOR.set_dbus_data(dbus_service)
|
|
|
|
TERMINATOR.reconfigure()
|
2015-11-30 20:54:23 +00:00
|
|
|
TERMINATOR.ibus_running = ibus_running
|
2015-09-01 20:59:36 +00:00
|
|
|
|
2013-08-28 21:09:17 +00:00
|
|
|
try:
|
|
|
|
dbg('Creating a terminal with layout: %s' % OPTIONS.layout)
|
|
|
|
TERMINATOR.create_layout(OPTIONS.layout)
|
2018-04-24 18:22:10 +00:00
|
|
|
except (KeyError,ValueError) as ex:
|
2013-08-28 21:09:17 +00:00
|
|
|
err('layout creation failed, creating a window ("%s")' % ex)
|
|
|
|
TERMINATOR.new_window()
|
|
|
|
TERMINATOR.layout_done()
|
2008-07-16 23:43:55 +00:00
|
|
|
|
2018-04-24 18:22:10 +00:00
|
|
|
if OPTIONS.debug and OPTIONS.debug >= 2:
|
2010-01-04 23:52:57 +00:00
|
|
|
import terminatorlib.debugserver as debugserver
|
|
|
|
# pylint: disable-msg=W0611
|
|
|
|
import threading
|
2008-02-12 13:49:36 +00:00
|
|
|
|
2014-09-19 14:08:08 +00:00
|
|
|
Gdk.threads_init()
|
2010-01-04 23:52:57 +00:00
|
|
|
(DEBUGTHREAD, DEBUGSVR) = debugserver.spawn(locals())
|
2010-03-19 22:16:08 +00:00
|
|
|
TERMINATOR.debug_address = DEBUGSVR.server_address
|
2008-07-16 23:43:55 +00:00
|
|
|
|
2008-06-17 00:58:41 +00:00
|
|
|
try:
|
2014-09-19 14:08:08 +00:00
|
|
|
Gtk.main()
|
2010-01-04 23:52:57 +00:00
|
|
|
except KeyboardInterrupt:
|
|
|
|
pass
|
2006-11-10 05:18:31 +00:00
|
|
|
|