2008-08-29 18:22:16 +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
|
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:
|
2010-01-04 23:52:57 +00:00
|
|
|
import pygtk
|
|
|
|
pygtk.require ("2.0")
|
2010-01-05 09:24:44 +00:00
|
|
|
# pylint: disable-msg=W0611
|
|
|
|
import gtk, pango, gobject
|
2010-01-04 23:52:57 +00:00
|
|
|
|
|
|
|
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)
|
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
|
2008-06-17 10:15:28 +00:00
|
|
|
|
2007-07-29 02:06:52 +00:00
|
|
|
if __name__ == '__main__':
|
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))
|
|
|
|
|
|
|
|
OPTIONS = terminatorlib.optionparse.parse_options()
|
2008-06-15 10:15:45 +00:00
|
|
|
|
2010-07-21 22:17:34 +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:
|
2010-07-22 12:59:06 +00:00
|
|
|
if OPTIONS.nodbus:
|
|
|
|
dbg('dbus disabled by command line')
|
|
|
|
raise ImportError
|
2010-07-21 22:17:34 +00:00
|
|
|
from terminatorlib import ipc
|
2011-12-29 20:39:09 +00:00
|
|
|
import dbus
|
2010-07-21 22:17:34 +00:00
|
|
|
try:
|
2011-08-25 21:10:04 +00:00
|
|
|
dbus_service = ipc.DBusService()
|
2010-07-21 22:17:34 +00:00
|
|
|
except ipc.DBusException:
|
2012-10-30 00:11:24 +00:00
|
|
|
dbg('Unable to become master process, operating via DBus')
|
2011-12-29 20:39:09 +00:00
|
|
|
# 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'
|
2011-12-29 20:43:12 +00:00
|
|
|
optionslist[opt] = val and '%s'%val or ''
|
2011-12-29 20:39:09 +00:00
|
|
|
optionslist = dbus.Dictionary(optionslist, signature='ss')
|
2012-10-30 00:11:24 +00:00
|
|
|
if OPTIONS.new_tab:
|
|
|
|
dbg('Requesting a new tab')
|
|
|
|
ipc.new_tab(optionslist)
|
|
|
|
else:
|
|
|
|
dbg('Requesting a new window')
|
|
|
|
ipc.new_window(optionslist)
|
2010-07-21 22:17:34 +00:00
|
|
|
sys.exit()
|
|
|
|
except ImportError:
|
2010-07-22 08:24:47 +00:00
|
|
|
dbg('dbus not imported')
|
2010-07-21 22:17:34 +00:00
|
|
|
pass
|
|
|
|
|
2010-01-04 23:52:57 +00:00
|
|
|
MAKER = Factory()
|
|
|
|
TERMINATOR = Terminator()
|
2010-04-18 08:49:32 +00:00
|
|
|
TERMINATOR.set_origcwd(ORIGCWD)
|
2011-08-25 21:10:04 +00:00
|
|
|
TERMINATOR.set_dbus_data(dbus_service)
|
2010-01-11 23:46:18 +00:00
|
|
|
TERMINATOR.reconfigure()
|
2013-08-28 21:09:17 +00:00
|
|
|
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()
|
2008-07-16 23:43:55 +00:00
|
|
|
|
2010-01-14 13:15:05 +00:00
|
|
|
if 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
|
|
|
|
2010-01-04 23:52:57 +00:00
|
|
|
gtk.gdk.threads_init()
|
|
|
|
(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:
|
2010-01-04 23:52:57 +00:00
|
|
|
gtk.main()
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
pass
|
2006-11-10 05:18:31 +00:00
|
|
|
|