2008-06-26 23:24:52 +00:00
|
|
|
#!/usr/bin/python
|
2010-01-11 20:06:53 +00:00
|
|
|
# Terminator by Chris Jones <cmsj@tenshu.net>
|
|
|
|
# GPL v2 only
|
|
|
|
"""terminator.py - class for the master Terminator singleton"""
|
|
|
|
|
2010-03-10 12:52:50 +00:00
|
|
|
import copy
|
2010-04-18 08:49:32 +00:00
|
|
|
import os
|
2014-09-19 14:10:43 +00:00
|
|
|
from gi.repository import Gtk, Gdk
|
2010-01-11 20:06:53 +00:00
|
|
|
|
|
|
|
from borg import Borg
|
|
|
|
from config import Config
|
|
|
|
from keybindings import Keybindings
|
2011-02-23 21:05:41 +00:00
|
|
|
from util import dbg, err, enumerate_descendants
|
2010-01-29 23:41:18 +00:00
|
|
|
from factory import Factory
|
2015-06-19 01:58:41 +00:00
|
|
|
from cwd import get_pid_cwd
|
2010-03-19 12:39:44 +00:00
|
|
|
from version import APP_NAME, APP_VERSION
|
2010-01-11 20:06:53 +00:00
|
|
|
|
2014-09-19 14:10:43 +00:00
|
|
|
def eventkey2gdkevent(eventkey): # FIXME FOR GTK3: is there a simpler way of casting from specific EventKey to generic (union) GdkEvent?
|
2015-11-28 18:53:57 +00:00
|
|
|
gdkevent = Gdk.Event.new(eventkey.type)
|
2014-09-19 14:10:43 +00:00
|
|
|
gdkevent.key.window = eventkey.window
|
|
|
|
gdkevent.key.send_event = eventkey.send_event
|
|
|
|
gdkevent.key.time = eventkey.time
|
|
|
|
gdkevent.key.state = eventkey.state
|
|
|
|
gdkevent.key.keyval = eventkey.keyval
|
|
|
|
gdkevent.key.length = eventkey.length
|
|
|
|
gdkevent.key.string = eventkey.string
|
|
|
|
gdkevent.key.hardware_keycode = eventkey.hardware_keycode
|
|
|
|
gdkevent.key.group = eventkey.group
|
|
|
|
gdkevent.key.is_modifier = eventkey.is_modifier
|
|
|
|
return gdkevent
|
|
|
|
|
2010-01-11 20:06:53 +00:00
|
|
|
class Terminator(Borg):
|
|
|
|
"""master object for the application"""
|
|
|
|
|
|
|
|
windows = None
|
2013-08-28 21:09:17 +00:00
|
|
|
launcher_windows = None
|
2010-01-11 20:06:53 +00:00
|
|
|
windowtitle = None
|
|
|
|
terminals = None
|
|
|
|
groups = None
|
|
|
|
config = None
|
|
|
|
keybindings = None
|
2015-11-28 19:03:51 +00:00
|
|
|
style_provider = None
|
2015-11-29 01:51:26 +00:00
|
|
|
last_focused_term = None
|
2010-01-11 20:06:53 +00:00
|
|
|
|
2010-01-29 23:52:21 +00:00
|
|
|
origcwd = None
|
2011-08-25 21:10:04 +00:00
|
|
|
dbus_path = None
|
|
|
|
dbus_name = None
|
2015-06-19 01:58:41 +00:00
|
|
|
pid_cwd = None
|
2010-03-19 12:39:44 +00:00
|
|
|
gnome_client = None
|
2010-03-19 22:16:08 +00:00
|
|
|
debug_address = None
|
2015-11-30 20:54:23 +00:00
|
|
|
ibus_running = None
|
2010-01-29 23:52:21 +00:00
|
|
|
|
2010-02-17 19:57:05 +00:00
|
|
|
doing_layout = None
|
2015-07-15 00:51:18 +00:00
|
|
|
layoutname = None
|
2013-10-31 17:50:21 +00:00
|
|
|
last_active_window = None
|
2010-02-17 19:57:05 +00:00
|
|
|
|
2010-01-11 20:06:53 +00:00
|
|
|
groupsend = None
|
|
|
|
groupsend_type = {'all':0, 'group':1, 'off':2}
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
"""Class initialiser"""
|
|
|
|
|
|
|
|
Borg.__init__(self, self.__class__.__name__)
|
|
|
|
self.prepare_attributes()
|
|
|
|
|
|
|
|
def prepare_attributes(self):
|
|
|
|
"""Initialise anything that isn't already"""
|
|
|
|
|
|
|
|
if not self.windows:
|
|
|
|
self.windows = []
|
2013-08-28 21:09:17 +00:00
|
|
|
if not self.launcher_windows:
|
|
|
|
self.launcher_windows = []
|
2010-01-11 20:06:53 +00:00
|
|
|
if not self.terminals:
|
|
|
|
self.terminals = []
|
|
|
|
if not self.groups:
|
|
|
|
self.groups = []
|
|
|
|
if not self.config:
|
|
|
|
self.config = Config()
|
2015-06-22 18:06:21 +00:00
|
|
|
if self.groupsend == None:
|
|
|
|
self.groupsend = self.groupsend_type[self.config['broadcast_default']]
|
2010-01-11 20:06:53 +00:00
|
|
|
if not self.keybindings:
|
|
|
|
self.keybindings = Keybindings()
|
|
|
|
self.keybindings.configure(self.config['keybindings'])
|
2010-02-17 19:57:05 +00:00
|
|
|
if not self.doing_layout:
|
|
|
|
self.doing_layout = False
|
2015-06-19 01:58:41 +00:00
|
|
|
if not self.pid_cwd:
|
|
|
|
self.pid_cwd = get_pid_cwd()
|
2010-03-19 12:39:44 +00:00
|
|
|
if self.gnome_client is None:
|
|
|
|
self.attempt_gnome_client()
|
|
|
|
|
2010-04-18 08:49:32 +00:00
|
|
|
def set_origcwd(self, cwd):
|
|
|
|
"""Store the original cwd our process inherits"""
|
|
|
|
if cwd == '/':
|
|
|
|
cwd = os.path.expanduser('~')
|
|
|
|
os.chdir(cwd)
|
|
|
|
self.origcwd = cwd
|
|
|
|
|
2011-08-25 21:10:04 +00:00
|
|
|
def set_dbus_data(self, dbus_service):
|
|
|
|
"""Store the DBus bus details, if they are available"""
|
|
|
|
if dbus_service:
|
|
|
|
self.dbus_name = dbus_service.bus_name.get_name()
|
|
|
|
self.dbus_path = dbus_service.bus_path
|
|
|
|
|
2010-03-19 12:39:44 +00:00
|
|
|
def attempt_gnome_client(self):
|
|
|
|
"""Attempt to find a GNOME Session to register with"""
|
|
|
|
try:
|
2014-09-19 14:10:43 +00:00
|
|
|
from gi.repository import Gnome
|
|
|
|
self.gnome_program = Gnome.init(APP_NAME, APP_VERSION) # VERIFY FOR GTK3
|
|
|
|
self.gnome_client = Gnome.Ui.master_client() # VERIFY FOR GTK3
|
2010-03-19 12:39:44 +00:00
|
|
|
self.gnome_client.connect_to_session_manager()
|
|
|
|
self.gnome_client.connect('save-yourself', self.save_yourself)
|
|
|
|
self.gnome_client.connect('die', self.die)
|
|
|
|
dbg('GNOME session support enabled and registered')
|
2012-01-14 20:11:46 +00:00
|
|
|
except (ImportError, AttributeError):
|
2010-03-19 12:39:44 +00:00
|
|
|
self.gnome_client = False
|
|
|
|
dbg('GNOME session support not available')
|
|
|
|
|
|
|
|
def save_yourself(self, *args):
|
|
|
|
"""Save as much state as possible for the session manager"""
|
|
|
|
dbg('preparing session manager state')
|
|
|
|
# FIXME: Implement this
|
|
|
|
|
|
|
|
def die(self, *args):
|
|
|
|
"""Die at the hands of the session manager"""
|
|
|
|
dbg('session manager asked us to die')
|
|
|
|
# FIXME: Implement this
|
2010-01-11 20:06:53 +00:00
|
|
|
|
2012-10-30 00:11:24 +00:00
|
|
|
def get_windows(self):
|
|
|
|
"""Return a list of windows"""
|
|
|
|
return self.windows
|
|
|
|
|
2010-01-11 20:06:53 +00:00
|
|
|
def register_window(self, window):
|
|
|
|
"""Register a new window widget"""
|
|
|
|
if window not in self.windows:
|
|
|
|
dbg('Terminator::register_window: registering %s:%s' % (id(window),
|
|
|
|
type(window)))
|
|
|
|
self.windows.append(window)
|
|
|
|
|
|
|
|
def deregister_window(self, window):
|
|
|
|
"""de-register a window widget"""
|
|
|
|
dbg('Terminator::deregister_window: de-registering %s:%s' %
|
|
|
|
(id(window), type(window)))
|
2010-01-29 23:37:25 +00:00
|
|
|
if window in self.windows:
|
|
|
|
self.windows.remove(window)
|
|
|
|
else:
|
|
|
|
err('%s is not in registered window list' % window)
|
|
|
|
|
2010-01-11 20:06:53 +00:00
|
|
|
if len(self.windows) == 0:
|
|
|
|
# We have no windows left, we should exit
|
2010-01-28 13:41:44 +00:00
|
|
|
dbg('no windows remain, quitting')
|
2014-09-19 14:08:08 +00:00
|
|
|
Gtk.main_quit()
|
2010-01-11 20:06:53 +00:00
|
|
|
|
2013-08-28 21:09:17 +00:00
|
|
|
def register_launcher_window(self, window):
|
|
|
|
"""Register a new launcher window widget"""
|
|
|
|
if window not in self.launcher_windows:
|
|
|
|
dbg('Terminator::register_launcher_window: registering %s:%s' % (id(window),
|
|
|
|
type(window)))
|
|
|
|
self.launcher_windows.append(window)
|
|
|
|
|
|
|
|
def deregister_launcher_window(self, window):
|
|
|
|
"""de-register a launcher window widget"""
|
|
|
|
dbg('Terminator::deregister_launcher_window: de-registering %s:%s' %
|
|
|
|
(id(window), type(window)))
|
|
|
|
if window in self.launcher_windows:
|
|
|
|
self.launcher_windows.remove(window)
|
|
|
|
else:
|
|
|
|
err('%s is not in registered window list' % window)
|
|
|
|
|
|
|
|
if len(self.launcher_windows) == 0 and len(self.windows) == 0:
|
|
|
|
# We have no windows left, we should exit
|
|
|
|
dbg('no windows remain, quitting')
|
2014-09-19 14:08:08 +00:00
|
|
|
Gtk.main_quit()
|
2013-08-28 21:09:17 +00:00
|
|
|
|
2010-01-11 20:06:53 +00:00
|
|
|
def register_terminal(self, terminal):
|
|
|
|
"""Register a new terminal widget"""
|
|
|
|
if terminal not in self.terminals:
|
|
|
|
dbg('Terminator::register_terminal: registering %s:%s' %
|
|
|
|
(id(terminal), type(terminal)))
|
|
|
|
self.terminals.append(terminal)
|
|
|
|
|
|
|
|
def deregister_terminal(self, terminal):
|
|
|
|
"""De-register a terminal widget"""
|
|
|
|
dbg('Terminator::deregister_terminal: de-registering %s:%s' %
|
|
|
|
(id(terminal), type(terminal)))
|
|
|
|
self.terminals.remove(terminal)
|
|
|
|
|
|
|
|
if len(self.terminals) == 0:
|
2010-01-28 13:41:44 +00:00
|
|
|
dbg('no terminals remain, destroying all windows')
|
2010-01-11 20:06:53 +00:00
|
|
|
for window in self.windows:
|
|
|
|
window.destroy()
|
2008-07-08 18:38:51 +00:00
|
|
|
else:
|
2010-01-11 20:06:53 +00:00
|
|
|
dbg('Terminator::deregister_terminal: %d terminals remain' %
|
|
|
|
len(self.terminals))
|
|
|
|
|
2011-08-24 21:38:56 +00:00
|
|
|
def find_terminal_by_uuid(self, uuid):
|
|
|
|
"""Search our terminals for one matching the supplied UUID"""
|
|
|
|
dbg('searching self.terminals for: %s' % uuid)
|
|
|
|
for terminal in self.terminals:
|
|
|
|
dbg('checking: %s (%s)' % (terminal.uuid.urn, terminal))
|
|
|
|
if terminal.uuid.urn == uuid:
|
|
|
|
return terminal
|
|
|
|
return None
|
|
|
|
|
2015-12-02 19:57:59 +00:00
|
|
|
def new_window(self, cwd=None, profile=None):
|
2010-01-29 23:41:18 +00:00
|
|
|
"""Create a window with a Terminal in it"""
|
|
|
|
maker = Factory()
|
|
|
|
window = maker.make('Window')
|
|
|
|
terminal = maker.make('Terminal')
|
2010-07-03 15:16:50 +00:00
|
|
|
if cwd:
|
|
|
|
terminal.set_cwd(cwd)
|
2015-12-02 19:57:59 +00:00
|
|
|
if profile and self.config['always_split_with_profile']:
|
|
|
|
terminal.force_set_profile(None, profile)
|
2010-01-29 23:41:18 +00:00
|
|
|
window.add(terminal)
|
2010-05-15 18:07:07 +00:00
|
|
|
window.show(True)
|
2010-01-29 23:41:18 +00:00
|
|
|
terminal.spawn_child()
|
|
|
|
|
|
|
|
return(window, terminal)
|
|
|
|
|
2010-02-01 12:11:44 +00:00
|
|
|
def create_layout(self, layoutname):
|
|
|
|
"""Create all the parts necessary to satisfy the specified layout"""
|
|
|
|
layout = None
|
2010-02-02 00:39:41 +00:00
|
|
|
objects = {}
|
2010-02-01 12:11:44 +00:00
|
|
|
|
2010-02-17 19:57:05 +00:00
|
|
|
self.doing_layout = True
|
|
|
|
|
2010-03-10 12:52:50 +00:00
|
|
|
layout = copy.deepcopy(self.config.layout_get_config(layoutname))
|
2010-02-01 12:11:44 +00:00
|
|
|
if not layout:
|
|
|
|
# User specified a non-existent layout. default to one Terminal
|
|
|
|
err('layout %s not defined' % layout)
|
2011-08-24 19:00:51 +00:00
|
|
|
self.new_window()
|
|
|
|
return
|
2010-02-01 12:11:44 +00:00
|
|
|
|
2010-02-02 00:39:41 +00:00
|
|
|
# Wind the flat objects into a hierarchy
|
|
|
|
hierarchy = {}
|
|
|
|
count = 0
|
|
|
|
# Loop over the layout until we have consumed it, or hit 1000 loops.
|
|
|
|
# This is a stupid artificial limit, but it's safe.
|
|
|
|
while len(layout) > 0 and count < 1000:
|
|
|
|
count = count + 1
|
|
|
|
if count == 1000:
|
|
|
|
err('hit maximum loop boundary. THIS IS VERY LIKELY A BUG')
|
|
|
|
for obj in layout.keys():
|
|
|
|
if layout[obj]['type'].lower() == 'window':
|
|
|
|
hierarchy[obj] = {}
|
|
|
|
hierarchy[obj]['type'] = 'Window'
|
|
|
|
hierarchy[obj]['children'] = {}
|
2010-02-27 13:55:38 +00:00
|
|
|
|
|
|
|
# Copy any additional keys
|
|
|
|
for objkey in layout[obj].keys():
|
|
|
|
if layout[obj][objkey] != '' and not hierarchy[obj].has_key(objkey):
|
|
|
|
hierarchy[obj][objkey] = layout[obj][objkey]
|
|
|
|
|
2010-02-02 00:39:41 +00:00
|
|
|
objects[obj] = hierarchy[obj]
|
|
|
|
del(layout[obj])
|
|
|
|
else:
|
|
|
|
# Now examine children to see if their parents exist yet
|
|
|
|
if not layout[obj].has_key('parent'):
|
|
|
|
err('Invalid object: %s' % obj)
|
|
|
|
del(layout[obj])
|
|
|
|
continue
|
|
|
|
if objects.has_key(layout[obj]['parent']):
|
2010-02-17 19:47:33 +00:00
|
|
|
# Our parent has been created, add ourselves
|
2010-02-02 00:39:41 +00:00
|
|
|
childobj = {}
|
|
|
|
childobj['type'] = layout[obj]['type']
|
|
|
|
childobj['children'] = {}
|
2010-02-17 19:47:33 +00:00
|
|
|
|
|
|
|
# Copy over any additional object keys
|
|
|
|
for objkey in layout[obj].keys():
|
|
|
|
if not childobj.has_key(objkey):
|
|
|
|
childobj[objkey] = layout[obj][objkey]
|
|
|
|
|
2010-02-02 00:39:41 +00:00
|
|
|
objects[layout[obj]['parent']]['children'][obj] = childobj
|
|
|
|
objects[obj] = childobj
|
|
|
|
del(layout[obj])
|
|
|
|
|
|
|
|
layout = hierarchy
|
|
|
|
|
2010-02-01 12:11:44 +00:00
|
|
|
for windef in layout:
|
2010-02-02 00:39:41 +00:00
|
|
|
if layout[windef]['type'] != 'Window':
|
2010-02-01 12:11:44 +00:00
|
|
|
err('invalid layout format. %s' % layout)
|
|
|
|
raise(ValueError)
|
2010-06-15 14:19:05 +00:00
|
|
|
dbg('Creating a window')
|
2010-02-01 12:11:44 +00:00
|
|
|
window, terminal = self.new_window()
|
2010-02-27 13:55:38 +00:00
|
|
|
if layout[windef].has_key('position'):
|
|
|
|
parts = layout[windef]['position'].split(':')
|
|
|
|
if len(parts) == 2:
|
|
|
|
window.move(int(parts[0]), int(parts[1]))
|
2010-02-27 14:18:08 +00:00
|
|
|
if layout[windef].has_key('size'):
|
|
|
|
parts = layout[windef]['size']
|
2010-04-02 16:04:54 +00:00
|
|
|
winx = int(parts[0])
|
|
|
|
winy = int(parts[1])
|
|
|
|
if winx > 1 and winy > 1:
|
|
|
|
window.resize(winx, winy)
|
2013-06-20 17:48:22 +00:00
|
|
|
if layout[windef].has_key('title'):
|
|
|
|
window.title.force_title(layout[windef]['title'])
|
2013-09-04 20:59:27 +00:00
|
|
|
if layout[windef].has_key('maximised'):
|
|
|
|
if layout[windef]['maximised'] == 'True':
|
|
|
|
window.ismaximised = True
|
|
|
|
else:
|
|
|
|
window.ismaximised = False
|
|
|
|
window.set_maximised(window.ismaximised)
|
|
|
|
if layout[windef].has_key('fullscreen'):
|
|
|
|
if layout[windef]['fullscreen'] == 'True':
|
|
|
|
window.isfullscreen = True
|
|
|
|
else:
|
|
|
|
window.isfullscreen = False
|
|
|
|
window.set_fullscreen(window.isfullscreen)
|
2013-09-02 14:54:07 +00:00
|
|
|
window.create_layout(layout[windef])
|
2010-02-01 12:11:44 +00:00
|
|
|
|
2015-07-15 00:51:18 +00:00
|
|
|
self.layoutname = layoutname
|
|
|
|
|
2010-02-17 19:57:05 +00:00
|
|
|
def layout_done(self):
|
|
|
|
"""Layout operations have finished, record that fact"""
|
|
|
|
self.doing_layout = False
|
2013-12-18 17:06:59 +00:00
|
|
|
maker = Factory()
|
2010-02-17 19:57:05 +00:00
|
|
|
|
2013-12-18 17:06:59 +00:00
|
|
|
window_last_active_term_mapping = {}
|
2013-10-31 17:50:21 +00:00
|
|
|
for window in self.windows:
|
2013-12-18 17:06:59 +00:00
|
|
|
if window.is_child_notebook():
|
|
|
|
source = window.get_toplevel().get_children()[0]
|
|
|
|
else:
|
|
|
|
source = window
|
|
|
|
window_last_active_term_mapping[window] = copy.copy(source.last_active_term)
|
2013-10-31 17:50:21 +00:00
|
|
|
|
2010-02-17 19:57:05 +00:00
|
|
|
for terminal in self.terminals:
|
|
|
|
if not terminal.pid:
|
|
|
|
terminal.spawn_child()
|
|
|
|
|
2013-11-19 11:46:11 +00:00
|
|
|
for window in self.windows:
|
2013-12-18 17:06:59 +00:00
|
|
|
if window.is_child_notebook():
|
|
|
|
# For windows with a notebook
|
|
|
|
notebook = window.get_toplevel().get_children()[0]
|
|
|
|
# Cycle through pages by number
|
|
|
|
for page in xrange(0, notebook.get_n_pages()):
|
|
|
|
# Try and get the entry in the previously saved mapping
|
|
|
|
mapping = window_last_active_term_mapping[window]
|
|
|
|
page_last_active_term = mapping.get(notebook.get_nth_page(page), None)
|
|
|
|
if page_last_active_term is None:
|
|
|
|
# Couldn't find entry, so we find the first child of type Terminal
|
|
|
|
children = notebook.get_nth_page(page).get_children()
|
|
|
|
for page_last_active_term in children:
|
|
|
|
if maker.isinstance(page_last_active_term, 'Terminal'):
|
|
|
|
page_last_active_term = page_last_active_term.uuid
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
err('Should never reach here!')
|
|
|
|
page_last_active_term = None
|
|
|
|
if page_last_active_term is None:
|
|
|
|
# Bail on this tab as we're having no luck here, continue with the next
|
|
|
|
continue
|
|
|
|
# Set the notebook entry, then ensure Terminal is visible and focussed
|
|
|
|
urn = page_last_active_term.urn
|
|
|
|
notebook.last_active_term[notebook.get_nth_page(page)] = page_last_active_term
|
|
|
|
if urn:
|
|
|
|
term = self.find_terminal_by_uuid(urn)
|
|
|
|
if term:
|
|
|
|
term.ensure_visible_and_focussed()
|
|
|
|
else:
|
|
|
|
# For windows without a notebook ensure Terminal is visible and focussed
|
|
|
|
if window_last_active_term_mapping[window]:
|
|
|
|
term = self.find_terminal_by_uuid(window_last_active_term_mapping[window].urn)
|
|
|
|
term.ensure_visible_and_focussed()
|
2013-11-19 11:46:11 +00:00
|
|
|
|
|
|
|
for window in self.windows:
|
|
|
|
if window.uuid == self.last_active_window:
|
|
|
|
window.show()
|
|
|
|
|
2010-01-11 20:06:53 +00:00
|
|
|
def reconfigure(self):
|
|
|
|
"""Update configuration for the whole application"""
|
|
|
|
|
2015-11-28 19:03:51 +00:00
|
|
|
if self.style_provider is not None:
|
|
|
|
Gtk.StyleContext.remove_provider_for_screen(
|
|
|
|
Gdk.Screen.get_default(),
|
|
|
|
self.style_provider)
|
|
|
|
self.style_provider = None
|
2010-01-11 23:46:18 +00:00
|
|
|
if self.config['handle_size'] in xrange(0, 6):
|
2015-11-28 19:03:51 +00:00
|
|
|
css = """
|
|
|
|
GtkPaned {
|
|
|
|
-GtkPaned-handle-size: %s
|
2010-04-07 21:23:31 +00:00
|
|
|
}
|
2015-11-28 19:03:51 +00:00
|
|
|
""" % self.config['handle_size']
|
|
|
|
self.style_provider = Gtk.CssProvider()
|
|
|
|
self.style_provider.load_from_data(css)
|
|
|
|
Gtk.StyleContext.add_provider_for_screen(
|
|
|
|
Gdk.Screen.get_default(),
|
|
|
|
self.style_provider,
|
|
|
|
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
|
2010-01-11 20:06:53 +00:00
|
|
|
|
|
|
|
# Cause all the terminals to reconfigure
|
|
|
|
for terminal in self.terminals:
|
|
|
|
terminal.reconfigure()
|
|
|
|
|
2010-02-07 22:32:55 +00:00
|
|
|
# Reparse our keybindings
|
|
|
|
self.keybindings.configure(self.config['keybindings'])
|
|
|
|
|
2010-04-01 22:15:42 +00:00
|
|
|
# Update tab position if appropriate
|
|
|
|
maker = Factory()
|
|
|
|
for window in self.windows:
|
|
|
|
child = window.get_child()
|
|
|
|
if maker.isinstance(child, 'Notebook'):
|
|
|
|
child.configure()
|
|
|
|
|
2010-01-11 20:06:53 +00:00
|
|
|
def create_group(self, name):
|
|
|
|
"""Create a new group"""
|
|
|
|
if name not in self.groups:
|
|
|
|
dbg('Terminator::create_group: registering group %s' % name)
|
|
|
|
self.groups.append(name)
|
|
|
|
|
|
|
|
def closegroupedterms(self, group):
|
|
|
|
"""Close all terminals in a group"""
|
2013-07-15 16:34:43 +00:00
|
|
|
for terminal in self.terminals[:]:
|
2010-01-11 20:06:53 +00:00
|
|
|
if terminal.group == group:
|
|
|
|
terminal.close()
|
|
|
|
|
|
|
|
def group_hoover(self):
|
|
|
|
"""Clean out unused groups"""
|
|
|
|
|
|
|
|
if self.config['autoclean_groups']:
|
|
|
|
inuse = []
|
|
|
|
todestroy = []
|
|
|
|
|
|
|
|
for terminal in self.terminals:
|
|
|
|
if terminal.group:
|
|
|
|
if not terminal.group in inuse:
|
|
|
|
inuse.append(terminal.group)
|
|
|
|
|
|
|
|
for group in self.groups:
|
|
|
|
if not group in inuse:
|
|
|
|
todestroy.append(group)
|
|
|
|
|
|
|
|
dbg('Terminator::group_hoover: %d groups, hoovering %d' %
|
|
|
|
(len(self.groups), len(todestroy)))
|
|
|
|
for group in todestroy:
|
|
|
|
self.groups.remove(group)
|
|
|
|
|
|
|
|
def group_emit(self, terminal, group, type, event):
|
|
|
|
"""Emit to each terminal in a group"""
|
|
|
|
dbg('Terminator::group_emit: emitting a keystroke for group %s' %
|
|
|
|
group)
|
|
|
|
for term in self.terminals:
|
|
|
|
if term != terminal and term.group == group:
|
2014-09-19 14:10:43 +00:00
|
|
|
term.vte.emit(type, eventkey2gdkevent(event))
|
2010-01-11 20:06:53 +00:00
|
|
|
|
|
|
|
def all_emit(self, terminal, type, event):
|
|
|
|
"""Emit to all terminals"""
|
|
|
|
for term in self.terminals:
|
|
|
|
if term != terminal:
|
2014-09-19 14:10:43 +00:00
|
|
|
term.vte.emit(type, eventkey2gdkevent(event))
|
2010-01-11 20:06:53 +00:00
|
|
|
|
|
|
|
def do_enumerate(self, widget, pad):
|
|
|
|
"""Insert the number of each terminal in a group, into that terminal"""
|
|
|
|
if pad:
|
|
|
|
numstr = '%0'+str(len(str(len(self.terminals))))+'d'
|
2008-06-26 23:24:52 +00:00
|
|
|
else:
|
2010-01-11 20:06:53 +00:00
|
|
|
numstr = '%d'
|
|
|
|
|
2011-02-23 21:02:09 +00:00
|
|
|
terminals = []
|
|
|
|
for window in self.windows:
|
|
|
|
containers, win_terminals = enumerate_descendants(window)
|
|
|
|
terminals.extend(win_terminals)
|
|
|
|
|
2010-01-11 20:06:53 +00:00
|
|
|
for term in self.get_target_terms(widget):
|
2011-02-23 21:02:09 +00:00
|
|
|
idx = terminals.index(term)
|
2010-01-11 20:06:53 +00:00
|
|
|
term.feed(numstr % (idx + 1))
|
|
|
|
|
2012-06-24 18:36:39 +00:00
|
|
|
def get_sibling_terms(self, widget):
|
|
|
|
termset = []
|
|
|
|
for term in self.terminals:
|
|
|
|
if term.group == widget.group:
|
|
|
|
termset.append(term)
|
|
|
|
return(termset)
|
|
|
|
|
2010-01-11 20:06:53 +00:00
|
|
|
def get_target_terms(self, widget):
|
|
|
|
"""Get the terminals we should currently be broadcasting to"""
|
|
|
|
if self.groupsend == self.groupsend_type['all']:
|
|
|
|
return(self.terminals)
|
|
|
|
elif self.groupsend == self.groupsend_type['group']:
|
2012-06-24 18:36:39 +00:00
|
|
|
if widget.group != None:
|
|
|
|
return(self.get_sibling_terms(widget))
|
|
|
|
return([widget])
|
2010-01-11 20:06:53 +00:00
|
|
|
|
2010-04-02 15:45:32 +00:00
|
|
|
def get_focussed_terminal(self):
|
|
|
|
"""iterate over all the terminals to find which, if any, has focus"""
|
|
|
|
for terminal in self.terminals:
|
2015-03-02 12:16:09 +00:00
|
|
|
if terminal.has_focus():
|
2010-04-02 15:45:32 +00:00
|
|
|
return(terminal)
|
|
|
|
return(None)
|
|
|
|
|
2010-01-11 20:06:53 +00:00
|
|
|
def focus_changed(self, widget):
|
|
|
|
"""We just moved focus to a new terminal"""
|
|
|
|
for terminal in self.terminals:
|
2010-01-18 23:27:22 +00:00
|
|
|
terminal.titlebar.update(widget)
|
2010-01-11 20:06:53 +00:00
|
|
|
return
|
2010-02-01 12:11:44 +00:00
|
|
|
|
2012-06-24 18:36:39 +00:00
|
|
|
def focus_left(self, widget):
|
|
|
|
self.last_focused_term=widget
|
|
|
|
|
2010-02-01 12:11:44 +00:00
|
|
|
def describe_layout(self):
|
|
|
|
"""Describe our current layout"""
|
2010-02-02 00:39:41 +00:00
|
|
|
layout = {}
|
|
|
|
count = 0
|
2010-02-01 12:11:44 +00:00
|
|
|
for window in self.windows:
|
2010-02-02 00:39:41 +00:00
|
|
|
parent = ''
|
2010-03-11 13:04:01 +00:00
|
|
|
count = window.describe_layout(count, parent, layout, 0)
|
2010-02-01 12:11:44 +00:00
|
|
|
|
|
|
|
return(layout)
|
|
|
|
|
2010-01-11 20:06:53 +00:00
|
|
|
# vim: set expandtab ts=4 sw=4:
|