terminator/terminator

133 lines
4.6 KiB
Plaintext
Raw Normal View History

#!/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
"""Terminator by Chris Jones <cmsj@tenshu.net>"""
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:
2014-09-19 14:08:08 +00:00
import gi
# pylint: disable-msg=W0611
from gi.repository import Gtk, Gdk
2014-09-19 14:08:08 +00:00
if Gdk.Display.get_default() == None:
print('You need to run terminator in an X environment. ' \
'Make sure $DISPLAY is properly set')
sys.exit(1)
2008-07-16 23:54:21 +00:00
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
from terminatorlib.layoutlauncher import LayoutLauncher
if __name__ == '__main__':
# Workaround for IBus intefering with broadcast when using dead keys
# Environment also needs IBUS_DISABLE_SNOOPER=1, or double chars appear
# in the receivers.
os.environ['IBUS_DISABLE_SNOOPER']='1'
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:
dbg('dbus not fixed for GTK3 yet')
raise ImportError
if OPTIONS.nodbus:
dbg('dbus disabled by command line')
raise ImportError
from terminatorlib import ipc
from gi import DBus # VERIFY FOR GTK3
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') # VERIFY FOR GTK3
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)
2010-01-11 23:46:18 +00:00
TERMINATOR.reconfigure()
if OPTIONS.select:
# launch gui, return selection
LAYOUTLAUNCHER=LayoutLauncher()
else:
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
2014-09-19 14:08:08 +00:00
Gdk.threads_init()
(DEBUGTHREAD, DEBUGSVR) = debugserver.spawn(locals())
TERMINATOR.debug_address = DEBUGSVR.server_address
try:
2014-09-19 14:08:08 +00:00
Gtk.main()
except KeyboardInterrupt:
pass