2009-08-07 09:21:37 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
# Terminator by Chris Jones <cmsj@tenshu.net>
|
|
|
|
# GPL v2 only
|
|
|
|
"""container.py - classes necessary to contain Terminal widgets"""
|
|
|
|
|
2009-08-09 21:00:43 +00:00
|
|
|
import gobject
|
2009-11-21 18:09:47 +00:00
|
|
|
import gtk
|
2009-08-09 21:00:43 +00:00
|
|
|
|
2009-08-19 00:04:53 +00:00
|
|
|
from config import Config
|
2009-11-14 18:54:12 +00:00
|
|
|
from util import dbg, err
|
2009-11-21 18:09:47 +00:00
|
|
|
from translation import _
|
2009-08-19 00:04:53 +00:00
|
|
|
|
2009-08-09 22:54:14 +00:00
|
|
|
# pylint: disable-msg=R0921
|
|
|
|
class Container(object):
|
2009-08-07 09:21:37 +00:00
|
|
|
"""Base class for Terminator Containers"""
|
|
|
|
|
2009-10-08 23:24:58 +00:00
|
|
|
terminator = None
|
2009-08-07 09:21:37 +00:00
|
|
|
immutable = None
|
|
|
|
children = None
|
|
|
|
config = None
|
2009-11-14 22:57:35 +00:00
|
|
|
signals = None
|
|
|
|
cnxids = None
|
2009-08-09 21:00:43 +00:00
|
|
|
|
2009-08-19 00:04:53 +00:00
|
|
|
def __init__(self):
|
2009-08-07 09:21:37 +00:00
|
|
|
"""Class initialiser"""
|
|
|
|
self.children = []
|
2009-11-14 22:57:35 +00:00
|
|
|
self.signals = []
|
|
|
|
self.cnxids = {}
|
2009-08-19 00:04:53 +00:00
|
|
|
self.config = Config()
|
2009-08-07 09:21:37 +00:00
|
|
|
|
2009-08-09 22:54:14 +00:00
|
|
|
def register_signals(self, widget):
|
2009-08-09 21:00:43 +00:00
|
|
|
"""Register gobject signals in a way that avoids multiple inheritance"""
|
2009-11-08 23:06:26 +00:00
|
|
|
existing = gobject.signal_list_names(widget)
|
2009-08-09 21:00:43 +00:00
|
|
|
for signal in self.signals:
|
2009-11-08 23:06:26 +00:00
|
|
|
if signal['name'] in existing:
|
|
|
|
dbg('Container:: skipping signal %s for %s, already exists' % (
|
|
|
|
signal['name'], widget))
|
|
|
|
else:
|
2009-11-20 22:52:39 +00:00
|
|
|
dbg('Container:: registering signal for %s on %s' %
|
|
|
|
(signal['name'], widget))
|
2009-11-14 18:54:12 +00:00
|
|
|
try:
|
|
|
|
gobject.signal_new(signal['name'],
|
|
|
|
widget,
|
|
|
|
signal['flags'],
|
|
|
|
signal['return_type'],
|
|
|
|
signal['param_types'])
|
|
|
|
except RuntimeError:
|
|
|
|
err('Container:: registering signal for %s on %s failed' %
|
|
|
|
(signal['name'], widget))
|
2009-08-09 21:00:43 +00:00
|
|
|
|
2009-11-14 22:57:35 +00:00
|
|
|
def connect_child(self, widget, signal, handler, data=None):
|
|
|
|
"""Register the requested signal and record its connection ID"""
|
|
|
|
if not self.cnxids.has_key(widget):
|
|
|
|
self.cnxids[widget] = []
|
|
|
|
|
|
|
|
if data is not None:
|
|
|
|
self.cnxids[widget].append(widget.connect(signal, handler, data))
|
2009-11-20 22:52:39 +00:00
|
|
|
dbg('Container::connect_child: connecting %s(%s) for %s::%s' %
|
2009-11-14 22:57:35 +00:00
|
|
|
(handler.__name__, data, widget.__class__.__name__, signal))
|
|
|
|
else:
|
|
|
|
self.cnxids[widget].append(widget.connect(signal, handler))
|
|
|
|
dbg('Container::connect_child: registering %s to handle %s::%s' %
|
|
|
|
(handler.__name__, widget.__class__.__name__, signal))
|
|
|
|
|
|
|
|
def disconnect_child(self, widget):
|
|
|
|
"""De-register the signals for a child"""
|
|
|
|
if self.cnxids.has_key(widget):
|
|
|
|
for cnxid in self.cnxids[widget]:
|
|
|
|
# FIXME: Look up the IDs to print a useful debugging message
|
2009-12-08 13:57:29 +00:00
|
|
|
dbg('Container::disconnect_child: removing handler on %s' %
|
|
|
|
widget.__class__.__name__)
|
2009-11-14 22:57:35 +00:00
|
|
|
widget.disconnect(cnxid)
|
|
|
|
del(self.cnxids[widget])
|
|
|
|
|
2009-08-07 09:21:37 +00:00
|
|
|
def get_offspring(self):
|
|
|
|
"""Return a list of child widgets, if any"""
|
|
|
|
return(self.children)
|
|
|
|
|
2009-08-07 23:31:44 +00:00
|
|
|
def split_horiz(self, widget):
|
|
|
|
"""Split this container horizontally"""
|
|
|
|
return(self.split_axis(widget, True))
|
2009-08-07 09:21:37 +00:00
|
|
|
|
2009-08-07 23:31:44 +00:00
|
|
|
def split_vert(self, widget):
|
|
|
|
"""Split this container vertically"""
|
|
|
|
return(self.split_axis(widget, False))
|
2009-08-07 09:21:37 +00:00
|
|
|
|
2009-11-17 04:56:55 +00:00
|
|
|
def split_axis(self, widget, vertical=True, sibling=None):
|
2009-08-07 23:31:44 +00:00
|
|
|
"""Default axis splitter. This should be implemented by subclasses"""
|
2009-08-09 22:54:14 +00:00
|
|
|
raise NotImplementedError('split_axis')
|
2009-08-09 17:48:06 +00:00
|
|
|
|
2009-08-27 23:20:22 +00:00
|
|
|
def add(self, widget):
|
|
|
|
"""Add a widget to the container"""
|
|
|
|
raise NotImplementedError('add')
|
|
|
|
|
2009-08-09 21:00:43 +00:00
|
|
|
def remove(self, widget):
|
|
|
|
"""Remove a widget from the container"""
|
2009-08-09 22:54:14 +00:00
|
|
|
raise NotImplementedError('remove')
|
2009-08-09 21:00:43 +00:00
|
|
|
|
2009-08-09 17:48:06 +00:00
|
|
|
def closeterm(self, widget):
|
|
|
|
"""Handle the closure of a terminal"""
|
2009-11-20 05:16:20 +00:00
|
|
|
try:
|
|
|
|
if self.get_property('term_zoomed'):
|
|
|
|
# We're zoomed, so unzoom and then start closing again
|
|
|
|
dbg('Container::closeterm: terminal zoomed, unzooming')
|
|
|
|
self.unzoom(widget)
|
|
|
|
widget.close()
|
|
|
|
return(True)
|
|
|
|
except TypeError:
|
|
|
|
pass
|
2009-08-09 17:48:06 +00:00
|
|
|
|
|
|
|
if not self.remove(widget):
|
2009-12-08 13:57:29 +00:00
|
|
|
dbg('Container::closeterm: self.remove() failed for %s' % widget)
|
2009-08-09 17:48:06 +00:00
|
|
|
return(False)
|
|
|
|
|
2009-10-05 21:15:22 +00:00
|
|
|
self.terminator.deregister_terminal(widget)
|
2009-11-07 01:40:43 +00:00
|
|
|
self.terminator.group_hoover()
|
2009-08-09 17:48:06 +00:00
|
|
|
return(True)
|
|
|
|
|
|
|
|
def resizeterm(self, widget, keyname):
|
|
|
|
"""Handle a keyboard event requesting a terminal resize"""
|
2009-08-09 22:54:14 +00:00
|
|
|
raise NotImplementedError('resizeterm')
|
2009-08-09 17:48:06 +00:00
|
|
|
|
|
|
|
def toggle_zoom(self, widget, fontscale = False):
|
|
|
|
"""Toggle the existing zoom state"""
|
2009-11-20 05:16:20 +00:00
|
|
|
try:
|
|
|
|
if self.get_property('term_zoomed'):
|
|
|
|
self.unzoom(widget)
|
|
|
|
else:
|
|
|
|
self.zoom(widget, fontscale)
|
|
|
|
except TypeError:
|
|
|
|
err('Container::toggle_zoom: %s is unable to handle zooming, for \
|
|
|
|
%s' % (self, widget))
|
2009-08-09 17:48:06 +00:00
|
|
|
|
|
|
|
def zoom(self, widget, fontscale = False):
|
|
|
|
"""Zoom a terminal"""
|
2009-08-09 22:54:14 +00:00
|
|
|
raise NotImplementedError('zoom')
|
2009-08-09 17:48:06 +00:00
|
|
|
|
|
|
|
def unzoom(self, widget):
|
|
|
|
"""Unzoom a terminal"""
|
2009-08-09 22:54:14 +00:00
|
|
|
raise NotImplementedError('unzoom')
|
|
|
|
|
2009-11-21 18:09:47 +00:00
|
|
|
def construct_confirm_close(self, window, type):
|
|
|
|
"""Create a confirmation dialog for closing things"""
|
|
|
|
dialog = gtk.Dialog(_('Close?'), window, gtk.DIALOG_MODAL)
|
|
|
|
dialog.set_has_separator(False)
|
|
|
|
dialog.set_resizable(False)
|
|
|
|
|
|
|
|
cancel = dialog.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT)
|
|
|
|
close_all = dialog.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_ACCEPT)
|
|
|
|
label = close_all.get_children()[0].get_children()[0].get_children()[1].set_label(_('Close _Terminals'))
|
|
|
|
|
2009-12-09 13:01:41 +00:00
|
|
|
primary = gtk.Label(_('<big><b>Close multiple terminals?</b></big>'))
|
2009-11-21 18:09:47 +00:00
|
|
|
primary.set_use_markup(True)
|
|
|
|
primary.set_alignment(0, 0.5)
|
|
|
|
secondary = gtk.Label(_('This %s has several terminals open. Closing the \
|
|
|
|
%s will also close all terminals within it.') % (type, type))
|
|
|
|
secondary.set_line_wrap(True)
|
|
|
|
|
|
|
|
labels = gtk.VBox()
|
|
|
|
labels.pack_start(primary, False, False, 6)
|
|
|
|
labels.pack_start(secondary, False, False, 6)
|
|
|
|
|
|
|
|
image = gtk.image_new_from_stock(gtk.STOCK_DIALOG_WARNING,
|
|
|
|
gtk.ICON_SIZE_DIALOG)
|
|
|
|
image.set_alignment(0.5, 0)
|
|
|
|
|
|
|
|
box = gtk.HBox()
|
|
|
|
box.pack_start(image, False, False, 6)
|
|
|
|
box.pack_start(labels, False, False, 6)
|
|
|
|
dialog.vbox.pack_start(box, False, False, 12)
|
|
|
|
|
|
|
|
dialog.show_all()
|
|
|
|
return(dialog)
|
|
|
|
|
2009-08-09 17:48:06 +00:00
|
|
|
# vim: set expandtab ts=4 sw=4:
|