2009-08-10 23:15:40 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
# Terminator by Chris Jones <cmsj@tenshu.net>
|
|
|
|
# GPL v2 only
|
|
|
|
"""terminator.py - class for the master Terminator singleton"""
|
|
|
|
|
2009-08-11 22:19:06 +00:00
|
|
|
from borg import Borg
|
2009-09-02 22:17:54 +00:00
|
|
|
|
2009-08-11 22:19:06 +00:00
|
|
|
class Terminator(Borg):
|
2009-08-10 23:15:40 +00:00
|
|
|
"""master object for the application"""
|
|
|
|
|
|
|
|
window = None
|
|
|
|
windowtitle = None
|
|
|
|
terminals = None
|
|
|
|
groups = None
|
|
|
|
config = None
|
2009-09-04 21:11:52 +00:00
|
|
|
|
|
|
|
splittogroup = None
|
|
|
|
autocleangroups = None
|
2009-09-02 22:17:54 +00:00
|
|
|
groupsend = None
|
2009-09-03 12:59:17 +00:00
|
|
|
groupsend_type = {'all':0, 'group':1, 'off':2}
|
2009-08-10 23:15:40 +00:00
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
"""Class initialiser"""
|
|
|
|
|
2009-08-11 22:19:06 +00:00
|
|
|
Borg.__init__(self)
|
|
|
|
self.prepare_attributes()
|
|
|
|
|
|
|
|
def prepare_attributes(self):
|
2009-08-18 11:55:52 +00:00
|
|
|
"""Initialise anything that isn't already"""
|
2009-08-11 22:19:06 +00:00
|
|
|
|
|
|
|
if not self.terminals:
|
|
|
|
self.terminals = []
|
|
|
|
if not self.groups:
|
|
|
|
self.groups = []
|
2009-09-02 22:17:54 +00:00
|
|
|
if not self.groupsend:
|
2009-09-03 12:59:17 +00:00
|
|
|
self.groupsend = self.groupsend_type['group']
|
2009-09-04 21:11:52 +00:00
|
|
|
if not self.splittogroup:
|
|
|
|
self.splittogroup = False
|
|
|
|
if not self.autocleangroups:
|
|
|
|
self.autocleangroups = True
|
2009-08-10 23:15:40 +00:00
|
|
|
|
2009-09-02 22:17:54 +00:00
|
|
|
def register_terminal(self, terminal):
|
|
|
|
"""Register a new terminal widget"""
|
2009-08-10 23:15:40 +00:00
|
|
|
|
|
|
|
self.terminals.append(terminal)
|
|
|
|
|
|
|
|
def reconfigure_terminals(self):
|
|
|
|
"""Tell all terminals to update their configuration"""
|
|
|
|
|
|
|
|
for terminal in self.terminals:
|
|
|
|
terminal.reconfigure()
|
|
|
|
|
|
|
|
def group_hoover(self):
|
|
|
|
"""Clean out unused groups"""
|
|
|
|
|
|
|
|
if self.config['autoclean_groups']:
|
|
|
|
todestroy = []
|
|
|
|
for group in self.groups:
|
|
|
|
for terminal in self.terminals:
|
|
|
|
save = False
|
|
|
|
if terminal.group == group:
|
|
|
|
save = True
|
2009-08-10 23:22:55 +00:00
|
|
|
break
|
2009-08-10 23:15:40 +00:00
|
|
|
|
|
|
|
if not save:
|
|
|
|
todestroy.append(group)
|
|
|
|
|
|
|
|
for group in todestroy:
|
|
|
|
self.groups.remove(group)
|
|
|
|
|
2009-09-04 21:48:35 +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'
|
|
|
|
else:
|
|
|
|
numstr='%d'
|
|
|
|
|
|
|
|
for term in self.get_target_terms(widget):
|
|
|
|
idx = self.terminals.index(term)
|
|
|
|
term.feed(numstr % (idx + 1))
|
|
|
|
|
|
|
|
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']:
|
|
|
|
set = []
|
|
|
|
for term in self.terminals:
|
|
|
|
if term == widget or (term.group != None and term.group ==
|
|
|
|
widget.group):
|
|
|
|
set.append(term)
|
|
|
|
return(set)
|
|
|
|
else:
|
|
|
|
return([widget])
|
|
|
|
|
2009-09-04 23:34:09 +00:00
|
|
|
def group_tab(self, widget):
|
|
|
|
"""Group all the terminals in a tab"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
def ungroup_tab(self, widget):
|
|
|
|
"""Ungroup all the terminals in a tab"""
|
|
|
|
pass
|
2009-08-10 23:15:40 +00:00
|
|
|
# vim: set expandtab ts=4 sw=4:
|