2
# Terminator by Chris Jones <cmsj@tenshu.net>
4
"""container.py - classes necessary to contain Terminal widgets"""
9
from factory import Factory
10
from config import Config
11
from util import dbg, err
12
from translation import _
13
from signalman import Signalman
15
# pylint: disable-msg=R0921
16
class Container(object):
17
"""Base class for Terminator Containers"""
27
"""Class initialiser"""
30
self.cnxids = Signalman()
31
self.config = Config()
33
def register_signals(self, widget):
34
"""Register gobject signals in a way that avoids multiple inheritance"""
35
existing = gobject.signal_list_names(widget)
36
for signal in self.signals:
37
if signal['name'] in existing:
38
dbg('Container:: skipping signal %s for %s, already exists' % (
39
signal['name'], widget))
41
dbg('Container:: registering signal for %s on %s' %
42
(signal['name'], widget))
44
gobject.signal_new(signal['name'],
47
signal['return_type'],
48
signal['param_types'])
50
err('Container:: registering signal for %s on %s failed' %
51
(signal['name'], widget))
53
def connect_child(self, widget, signal, handler, *args):
54
"""Register the requested signal and record its connection ID"""
55
self.cnxids.new(widget, signal, handler, *args)
58
def disconnect_child(self, widget):
59
"""De-register the signals for a child"""
60
self.cnxids.remove_widget(widget)
62
def get_offspring(self):
63
"""Return a list of direct child widgets, if any"""
66
def split_horiz(self, widget, cwd=None):
67
"""Split this container horizontally"""
68
return(self.split_axis(widget, True, cwd))
70
def split_vert(self, widget, cwd=None):
71
"""Split this container vertically"""
72
return(self.split_axis(widget, False, cwd))
74
def split_axis(self, widget, vertical=True, cwd=None, sibling=None, siblinglast=None):
75
"""Default axis splitter. This should be implemented by subclasses"""
76
raise NotImplementedError('split_axis')
78
def add(self, widget):
79
"""Add a widget to the container"""
80
raise NotImplementedError('add')
82
def remove(self, widget):
83
"""Remove a widget from the container"""
84
raise NotImplementedError('remove')
87
"""Ensure we still have a reason to exist"""
88
raise NotImplementedError('hoover')
90
def get_children(self):
91
"""Return an ordered list of the children of this Container"""
92
raise NotImplementedError('get_children')
94
def closeterm(self, widget):
95
"""Handle the closure of a terminal"""
97
if self.get_property('term_zoomed'):
98
# We're zoomed, so unzoom and then start closing again
99
dbg('Container::closeterm: terminal zoomed, unzooming')
106
if not self.remove(widget):
107
dbg('Container::closeterm: self.remove() failed for %s' % widget)
110
self.terminator.deregister_terminal(widget)
111
self.terminator.group_hoover()
114
def resizeterm(self, widget, keyname):
115
"""Handle a keyboard event requesting a terminal resize"""
116
raise NotImplementedError('resizeterm')
118
def toggle_zoom(self, widget, fontscale = False):
119
"""Toggle the existing zoom state"""
121
if self.get_property('term_zoomed'):
124
self.zoom(widget, fontscale)
126
err('Container::toggle_zoom: %s is unable to handle zooming, for \
127
%s' % (self, widget))
129
def zoom(self, widget, fontscale = False):
130
"""Zoom a terminal"""
131
raise NotImplementedError('zoom')
133
def unzoom(self, widget):
134
"""Unzoom a terminal"""
135
raise NotImplementedError('unzoom')
137
def construct_confirm_close(self, window, reqtype):
138
"""Create a confirmation dialog for closing things"""
139
dialog = gtk.Dialog(_('Close?'), window, gtk.DIALOG_MODAL)
140
dialog.set_has_separator(False)
141
dialog.set_resizable(False)
143
dialog.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT)
144
c_all = dialog.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_ACCEPT)
145
c_all.get_children()[0].get_children()[0].get_children()[1].set_label(
146
_('Close _Terminals'))
148
primary = gtk.Label(_('<big><b>Close multiple terminals?</b></big>'))
149
primary.set_use_markup(True)
150
primary.set_alignment(0, 0.5)
151
secondary = gtk.Label(_('This %s has several terminals open. Closing \
152
the %s will also close all terminals within it.') % (reqtype, reqtype))
153
secondary.set_line_wrap(True)
156
labels.pack_start(primary, False, False, 6)
157
labels.pack_start(secondary, False, False, 6)
159
image = gtk.image_new_from_stock(gtk.STOCK_DIALOG_WARNING,
160
gtk.ICON_SIZE_DIALOG)
161
image.set_alignment(0.5, 0)
164
box.pack_start(image, False, False, 6)
165
box.pack_start(labels, False, False, 6)
166
dialog.vbox.pack_start(box, False, False, 12)
171
def propagate_title_change(self, widget, title):
172
"""Pass a title change up the widget stack"""
174
parent = self.get_parent()
175
title = widget.get_window_title()
177
if maker.isinstance(self, 'Notebook'):
178
self.update_tab_label_text(widget, title)
179
elif maker.isinstance(self, 'Window'):
180
self.title.set_title(widget, title)
182
if maker.isinstance(parent, 'Container'):
183
parent.propagate_title_change(widget, title)
185
def get_visible_terminals(self):
186
"""Walk the widget tree to find all of the visible terminals. That is,
187
any terminals which are not hidden in another Notebook pane"""
191
for child in self.get_offspring():
192
if maker.isinstance(child, 'Terminal'):
193
terminals[child] = child.get_allocation()
194
elif maker.isinstance(child, 'Container'):
195
terminals.update(child.get_visible_terminals())
197
err('Unknown child type %s' % type(child))
201
def describe_layout(self, count, parent, global_layout, child_order):
202
"""Describe our current layout"""
205
mytype = maker.type(self)
207
err('unable to detemine own type. %s' % self)
210
layout['type'] = mytype
211
layout['parent'] = parent
212
layout['order'] = child_order
214
if hasattr(self, 'get_position'):
215
position = self.get_position()
216
if hasattr(position, '__iter__'):
217
position = ':'.join([str(x) for x in position])
218
layout['position'] = position
220
if hasattr(self, 'get_size'):
221
layout['size'] = self.get_size()
223
name = 'child%d' % count
226
global_layout[name] = layout
229
for child in self.get_children():
230
if hasattr(child, 'describe_layout'):
231
count = child.describe_layout(count, name, global_layout, child_order)
232
child_order = child_order + 1
236
def create_layout(self, layout):
237
"""Apply settings for our layout"""
238
raise NotImplementedError('create_layout')
240
# vim: set expandtab ts=4 sw=4: