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-08-19 00:04:53 +00:00
|
|
|
from config import Config
|
2009-08-27 23:20:22 +00:00
|
|
|
from util import dbg
|
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-08-09 17:48:06 +00:00
|
|
|
state_zoomed = None
|
|
|
|
|
|
|
|
states_zoom = { 'none' : 0,
|
|
|
|
'zoomed' : 1,
|
|
|
|
'maximised' : 2 }
|
2009-08-07 09:21:37 +00:00
|
|
|
|
2009-08-09 21:00:43 +00:00
|
|
|
signals = [ {'name': 'group-hoover-needed',
|
|
|
|
'flags': gobject.SIGNAL_RUN_LAST,
|
|
|
|
'return_type': gobject.TYPE_BOOLEAN,
|
|
|
|
'param_types': ()
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2009-08-19 00:04:53 +00:00
|
|
|
def __init__(self):
|
2009-08-07 09:21:37 +00:00
|
|
|
"""Class initialiser"""
|
|
|
|
self.children = []
|
2009-08-19 00:04:53 +00:00
|
|
|
self.config = Config()
|
2009-08-27 23:20:22 +00:00
|
|
|
self.state_zoomed = self.states_zoom['none']
|
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"""
|
|
|
|
for signal in self.signals:
|
|
|
|
gobject.signal_new(signal['name'],
|
2009-08-09 22:54:14 +00:00
|
|
|
widget,
|
2009-08-09 21:00:43 +00:00
|
|
|
signal['flags'],
|
|
|
|
signal['return_type'],
|
|
|
|
signal['param_types'])
|
|
|
|
|
2009-08-09 22:54:14 +00:00
|
|
|
def emit(self, signal):
|
|
|
|
"""Emit a gobject signal"""
|
|
|
|
raise NotImplementedError('emit')
|
|
|
|
|
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-08-07 23:31:44 +00:00
|
|
|
def split_axis(self, widget, vertical=True):
|
|
|
|
"""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
|
|
|
|
|
|
|
def unsplit(self, widget, keep=False):
|
|
|
|
"""Default unsplitter. This should be implemented by subclasses"""
|
2009-08-09 22:54:14 +00:00
|
|
|
raise NotImplementedError('unsplit')
|
2009-08-07 09:21:37 +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-08-27 23:20:22 +00:00
|
|
|
if self.state_zoomed != self.states_zoom['none']:
|
|
|
|
dbg('closeterm: current zoomed state is: %s' % self.state_zoomed)
|
2009-08-09 17:48:06 +00:00
|
|
|
self.unzoom(widget)
|
|
|
|
|
|
|
|
if not self.remove(widget):
|
|
|
|
return(False)
|
|
|
|
|
2009-10-05 21:15:22 +00:00
|
|
|
self.terminator.deregister_terminal(widget)
|
2009-08-09 21:00:43 +00:00
|
|
|
self.emit('need_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-08-27 23:20:22 +00:00
|
|
|
if self.state_zoomed != self.states_zoom['none']:
|
2009-08-09 17:48:06 +00:00
|
|
|
self.unzoom(widget)
|
|
|
|
else:
|
|
|
|
self.zoom(widget, fontscale)
|
|
|
|
|
|
|
|
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-08-09 17:48:06 +00:00
|
|
|
# vim: set expandtab ts=4 sw=4:
|