Start implementing our Paned container and switch to it

This commit is contained in:
Chris Jones 2009-11-07 01:40:43 +00:00
parent c60aae8bed
commit 6b4c660cbc
5 changed files with 109 additions and 18 deletions

View File

@ -22,12 +22,7 @@ class Container(object):
'zoomed' : 1, 'zoomed' : 1,
'maximised' : 2 } 'maximised' : 2 }
signals = [ {'name': 'group-hoover-needed', signals = []
'flags': gobject.SIGNAL_RUN_LAST,
'return_type': gobject.TYPE_BOOLEAN,
'param_types': ()
}
]
def __init__(self): def __init__(self):
"""Class initialiser""" """Class initialiser"""
@ -38,16 +33,13 @@ class Container(object):
def register_signals(self, widget): def register_signals(self, widget):
"""Register gobject signals in a way that avoids multiple inheritance""" """Register gobject signals in a way that avoids multiple inheritance"""
for signal in self.signals: for signal in self.signals:
dbg("Container:: registering signal for %s on %s" % (signal['name'], widget))
gobject.signal_new(signal['name'], gobject.signal_new(signal['name'],
widget, widget,
signal['flags'], signal['flags'],
signal['return_type'], signal['return_type'],
signal['param_types']) signal['param_types'])
def emit(self, signal):
"""Emit a gobject signal"""
raise NotImplementedError('emit')
def get_offspring(self): def get_offspring(self):
"""Return a list of child widgets, if any""" """Return a list of child widgets, if any"""
return(self.children) return(self.children)
@ -86,7 +78,7 @@ class Container(object):
return(False) return(False)
self.terminator.deregister_terminal(widget) self.terminator.deregister_terminal(widget)
self.emit('need_group_hoover') self.terminator.group_hoover()
return(True) return(True)
def resizeterm(self, widget, keyname): def resizeterm(self, widget, keyname):

94
terminatorlib/paned.py Executable file
View File

@ -0,0 +1,94 @@
#!/usr/bin/python
# Terminator by Chris Jones <cmsj@tenshu.net>
# GPL v2 only
"""paned.py - a base Paned container class and the vertical/horizontal
variants"""
import gobject
import gtk
from newterminator import Terminator
from container import Container
# pylint: disable-msg=R0921
class Paned(Container):
"""Base class for Paned Containers"""
cnxids = None
def __init__(self):
"""Class initialiser"""
self.terminator = Terminator()
self.cnxids = {}
Container.__init__(self)
gobject.type_register(HPaned)
self.register_signals(HPaned)
def split_axis(self, widget, vertical=True):
"""Default axis splitter. This should be implemented by subclasses"""
raise NotImplementedError('split_axis')
def add(self, widget):
"""Add a widget to the container"""
if len(self.children) == 0:
self.pack1(widget, True, True)
self.children.append(widget)
elif len(self.children) == 1:
self.pack2(widget, True, True)
self.children.append(widget)
else:
raise ValueError('already have two children')
self.cnxids[widget] = []
self.cnxids[widget].append(widget.connect('close-term',
self.wrapcloseterm))
# FIXME: somehow propagate the title-change signal to the Window
self.cnxids[widget].append(widget.connect('split-horiz',
self.split_horiz))
self.cnxids[widget].append(widget.connect('split-vert',
self.split_vert))
def remove(self, widget):
"""Remove a widget from the container"""
gtk.Paned.remove(self, widget)
for cnxid in self.cnxids[widget]:
widget.disconnect(cnxid)
del(self.cnxids[widget])
self.children.remove(widget)
return(True)
def wrapcloseterm(self, widget):
"""A child terminal has closed, so this container must die"""
if self.closeterm(widget):
parent = self.get_parent()
parent.remove(self)
# At this point we only have one child, which is the surviving term
sibling = self.children[0]
self.remove(sibling)
parent.add(sibling)
del(self)
else:
print "self.closeterm failed"
def resizeterm(self, widget, keyname):
"""Handle a keyboard event requesting a terminal resize"""
raise NotImplementedError('resizeterm')
class HPaned(Paned, gtk.HPaned):
"""Merge gtk.HPaned into our base Paned Container"""
def __init__(self):
"""Class initialiser"""
Paned.__init__(self)
gtk.HPaned.__init__(self)
class VPaned(Paned, gtk.VPaned):
"""Merge gtk.VPaned into our base Paned Container"""
def __init__(self):
"""Class initialiser"""
Paned.__init__(self)
gtk.VPaned.__init__(self)
gobject.type_register(HPaned)
gobject.type_register(VPaned)
# vim: set expandtab ts=4 sw=4:

View File

@ -86,6 +86,7 @@ class Searchbar(gtk.HBox):
self.pack_end(close, False, False) self.pack_end(close, False, False)
self.hide() self.hide()
self.set_no_show_all(True)
def get_vte(self): def get_vte(self):
"""Find our parent widget""" """Find our parent widget"""

View File

@ -752,7 +752,10 @@ class Terminal(gtk.VBox):
self.vte.feed(_('Unable to find a shell')) self.vte.feed(_('Unable to find a shell'))
return(-1) return(-1)
os.putenv('WINDOWID', '%s' % self.vte.get_parent_window().xid) try:
os.putenv('WINDOWID', '%s' % self.vte.get_parent_window().xid)
except AttributeError:
pass
self.pid = self.vte.fork_command(command=shell, argv=args, envv=[], self.pid = self.vte.fork_command(command=shell, argv=args, envv=[],
loglastlog=login, logwtmp=update_records, loglastlog=login, logwtmp=update_records,

View File

@ -13,6 +13,7 @@ from version import APP_NAME
from container import Container from container import Container
from newterminator import Terminator from newterminator import Terminator
from terminal import Terminal from terminal import Terminal
from paned import HPaned,VPaned
try: try:
import deskbar.core.keybinder as bindkey import deskbar.core.keybinder as bindkey
@ -37,6 +38,7 @@ class Window(Container, gtk.Window):
def __init__(self): def __init__(self):
"""Class initialiser""" """Class initialiser"""
self.terminator = Terminator() self.terminator = Terminator()
self.terminator.window = self
self.cnxids = [] self.cnxids = []
Container.__init__(self) Container.__init__(self)
@ -182,21 +184,20 @@ class Window(Container, gtk.Window):
def split_axis(self, widget, vertical=True): def split_axis(self, widget, vertical=True):
"""Split the window""" """Split the window"""
# FIXME: this .remove isn't good enough, what about signal handlers?
self.remove(widget) self.remove(widget)
# FIXME: we should be creating proper containers, not these gtk widgets # FIXME: we should be creating proper containers, not these gtk widgets
if vertical: if vertical:
container = gtk.VPaned() container = VPaned()
else: else:
container = gtk.HPaned() container = HPaned()
sibling = Terminal() sibling = Terminal()
self.terminator.register_terminal(sibling) self.terminator.register_terminal(sibling)
container.pack1(widget, True, True) for term in [widget, sibling]:
container.pack2(sibling, True, True) container.add(term)
container.show() container.show_all()
self.add(container) self.add(container)
sibling.spawn_child() sibling.spawn_child()