Start implementing our Paned container and switch to it
This commit is contained in:
parent
c60aae8bed
commit
6b4c660cbc
|
@ -22,12 +22,7 @@ class Container(object):
|
|||
'zoomed' : 1,
|
||||
'maximised' : 2 }
|
||||
|
||||
signals = [ {'name': 'group-hoover-needed',
|
||||
'flags': gobject.SIGNAL_RUN_LAST,
|
||||
'return_type': gobject.TYPE_BOOLEAN,
|
||||
'param_types': ()
|
||||
}
|
||||
]
|
||||
signals = []
|
||||
|
||||
def __init__(self):
|
||||
"""Class initialiser"""
|
||||
|
@ -38,16 +33,13 @@ class Container(object):
|
|||
def register_signals(self, widget):
|
||||
"""Register gobject signals in a way that avoids multiple inheritance"""
|
||||
for signal in self.signals:
|
||||
dbg("Container:: registering signal for %s on %s" % (signal['name'], widget))
|
||||
gobject.signal_new(signal['name'],
|
||||
widget,
|
||||
signal['flags'],
|
||||
signal['return_type'],
|
||||
signal['param_types'])
|
||||
|
||||
def emit(self, signal):
|
||||
"""Emit a gobject signal"""
|
||||
raise NotImplementedError('emit')
|
||||
|
||||
def get_offspring(self):
|
||||
"""Return a list of child widgets, if any"""
|
||||
return(self.children)
|
||||
|
@ -86,7 +78,7 @@ class Container(object):
|
|||
return(False)
|
||||
|
||||
self.terminator.deregister_terminal(widget)
|
||||
self.emit('need_group_hoover')
|
||||
self.terminator.group_hoover()
|
||||
return(True)
|
||||
|
||||
def resizeterm(self, widget, keyname):
|
||||
|
|
|
@ -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:
|
|
@ -86,6 +86,7 @@ class Searchbar(gtk.HBox):
|
|||
self.pack_end(close, False, False)
|
||||
|
||||
self.hide()
|
||||
self.set_no_show_all(True)
|
||||
|
||||
def get_vte(self):
|
||||
"""Find our parent widget"""
|
||||
|
|
|
@ -752,7 +752,10 @@ class Terminal(gtk.VBox):
|
|||
self.vte.feed(_('Unable to find a shell'))
|
||||
return(-1)
|
||||
|
||||
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=[],
|
||||
loglastlog=login, logwtmp=update_records,
|
||||
|
|
|
@ -13,6 +13,7 @@ from version import APP_NAME
|
|||
from container import Container
|
||||
from newterminator import Terminator
|
||||
from terminal import Terminal
|
||||
from paned import HPaned,VPaned
|
||||
|
||||
try:
|
||||
import deskbar.core.keybinder as bindkey
|
||||
|
@ -37,6 +38,7 @@ class Window(Container, gtk.Window):
|
|||
def __init__(self):
|
||||
"""Class initialiser"""
|
||||
self.terminator = Terminator()
|
||||
self.terminator.window = self
|
||||
self.cnxids = []
|
||||
|
||||
Container.__init__(self)
|
||||
|
@ -182,21 +184,20 @@ class Window(Container, gtk.Window):
|
|||
|
||||
def split_axis(self, widget, vertical=True):
|
||||
"""Split the window"""
|
||||
# FIXME: this .remove isn't good enough, what about signal handlers?
|
||||
self.remove(widget)
|
||||
|
||||
# FIXME: we should be creating proper containers, not these gtk widgets
|
||||
if vertical:
|
||||
container = gtk.VPaned()
|
||||
container = VPaned()
|
||||
else:
|
||||
container = gtk.HPaned()
|
||||
container = HPaned()
|
||||
|
||||
sibling = Terminal()
|
||||
self.terminator.register_terminal(sibling)
|
||||
|
||||
container.pack1(widget, True, True)
|
||||
container.pack2(sibling, True, True)
|
||||
container.show()
|
||||
for term in [widget, sibling]:
|
||||
container.add(term)
|
||||
container.show_all()
|
||||
|
||||
self.add(container)
|
||||
sibling.spawn_child()
|
||||
|
|
Loading…
Reference in New Issue