Working with tabs
This commit is contained in:
parent
1d7adc8283
commit
26e793af10
|
@ -12,6 +12,7 @@ from container import Container
|
||||||
from terminal import Terminal
|
from terminal import Terminal
|
||||||
from editablelabel import EditableLabel
|
from editablelabel import EditableLabel
|
||||||
from translation import _
|
from translation import _
|
||||||
|
from paned import VPaned, HPaned
|
||||||
from util import err
|
from util import err
|
||||||
|
|
||||||
class Notebook(Container, gtk.Notebook):
|
class Notebook(Container, gtk.Notebook):
|
||||||
|
@ -37,6 +38,7 @@ class Notebook(Container, gtk.Notebook):
|
||||||
window.add(self)
|
window.add(self)
|
||||||
self.newtab(child)
|
self.newtab(child)
|
||||||
|
|
||||||
|
|
||||||
label = TabLabel(self.window.get_title(), self)
|
label = TabLabel(self.window.get_title(), self)
|
||||||
self.set_tab_label(child, label)
|
self.set_tab_label(child, label)
|
||||||
self.set_tab_label_packing(child, not self.config['scroll_tabbar'],
|
self.set_tab_label_packing(child, not self.config['scroll_tabbar'],
|
||||||
|
@ -57,7 +59,30 @@ class Notebook(Container, gtk.Notebook):
|
||||||
|
|
||||||
def split_axis(self, widget, vertical=True, sibling=None):
|
def split_axis(self, widget, vertical=True, sibling=None):
|
||||||
"""Default axis splitter. This should be implemented by subclasses"""
|
"""Default axis splitter. This should be implemented by subclasses"""
|
||||||
raise NotImplementedError('split_axis')
|
#raise NotImplementedError('split_axis')
|
||||||
|
page_num = self.page_num( widget )
|
||||||
|
if page_num == -1:
|
||||||
|
raise NotImplementedError('split_axis widget cannot be found')
|
||||||
|
self.remove_page(page_num)
|
||||||
|
if vertical:
|
||||||
|
container = VPaned()
|
||||||
|
else:
|
||||||
|
container = HPaned()
|
||||||
|
|
||||||
|
if not sibling:
|
||||||
|
sibling = Terminal()
|
||||||
|
self.terminator.register_terminal(sibling)
|
||||||
|
sibling.spawn_child()
|
||||||
|
|
||||||
|
self.insert_page(container, None, page_num )
|
||||||
|
self.show_all()
|
||||||
|
|
||||||
|
container.add(widget)
|
||||||
|
container.add(sibling)
|
||||||
|
self.set_current_page( page_num )
|
||||||
|
|
||||||
|
self.show_all()
|
||||||
|
|
||||||
|
|
||||||
def add(self, widget):
|
def add(self, widget):
|
||||||
"""Add a widget to the container"""
|
"""Add a widget to the container"""
|
||||||
|
@ -65,7 +90,11 @@ class Notebook(Container, gtk.Notebook):
|
||||||
|
|
||||||
def remove(self, widget):
|
def remove(self, widget):
|
||||||
"""Remove a widget from the container"""
|
"""Remove a widget from the container"""
|
||||||
raise NotImplementedError('remove')
|
page_num = self.page_num( widget )
|
||||||
|
if page_num == -1:
|
||||||
|
print('remove current page = -1')
|
||||||
|
return(False)
|
||||||
|
self.remove_page( page_num )
|
||||||
|
|
||||||
def newtab(self, widget=None):
|
def newtab(self, widget=None):
|
||||||
"""Add a new tab, optionally supplying a child widget"""
|
"""Add a new tab, optionally supplying a child widget"""
|
||||||
|
@ -74,6 +103,15 @@ class Notebook(Container, gtk.Notebook):
|
||||||
self.terminator.register_terminal(widget)
|
self.terminator.register_terminal(widget)
|
||||||
widget.spawn_child()
|
widget.spawn_child()
|
||||||
|
|
||||||
|
signals = {'close-term': self.closeterm,
|
||||||
|
#'title-change': self.title.set_title,
|
||||||
|
'split-horiz': self.split_horiz,
|
||||||
|
'split-vert': self.split_vert,
|
||||||
|
'unzoom': self.unzoom}
|
||||||
|
|
||||||
|
for signal in signals:
|
||||||
|
self.connect_child(widget, signal, signals[signal])
|
||||||
|
|
||||||
self.set_tab_reorderable(widget, True)
|
self.set_tab_reorderable(widget, True)
|
||||||
label = TabLabel(self.window.get_title(), self)
|
label = TabLabel(self.window.get_title(), self)
|
||||||
|
|
||||||
|
@ -87,6 +125,7 @@ class Notebook(Container, gtk.Notebook):
|
||||||
|
|
||||||
|
|
||||||
self.append_page(widget, None)
|
self.append_page(widget, None)
|
||||||
|
self.set_current_page(-1)
|
||||||
widget.grab_focus()
|
widget.grab_focus()
|
||||||
|
|
||||||
def resizeterm(self, widget, keyname):
|
def resizeterm(self, widget, keyname):
|
||||||
|
|
|
@ -12,6 +12,9 @@ from newterminator import Terminator
|
||||||
from terminal import Terminal
|
from terminal import Terminal
|
||||||
from container import Container
|
from container import Container
|
||||||
|
|
||||||
|
# forward declaration of class Notebook
|
||||||
|
class Notebook:
|
||||||
|
pass
|
||||||
# pylint: disable-msg=R0921
|
# pylint: disable-msg=R0921
|
||||||
# pylint: disable-msg=E1101
|
# pylint: disable-msg=E1101
|
||||||
class Paned(Container):
|
class Paned(Container):
|
||||||
|
@ -111,13 +114,18 @@ class Paned(Container):
|
||||||
def wrapcloseterm(self, widget):
|
def wrapcloseterm(self, widget):
|
||||||
"""A child terminal has closed, so this container must die"""
|
"""A child terminal has closed, so this container must die"""
|
||||||
if self.closeterm(widget):
|
if self.closeterm(widget):
|
||||||
parent = self.get_parent()
|
|
||||||
parent.remove(self)
|
|
||||||
|
|
||||||
# At this point we only have one child, which is the surviving term
|
# At this point we only have one child, which is the surviving term
|
||||||
sibling = self.children[0]
|
sibling = self.children[0]
|
||||||
self.remove(sibling)
|
self.remove(sibling)
|
||||||
parent.add(sibling)
|
|
||||||
|
parent = self.get_parent()
|
||||||
|
if isinstance( parent, Notebook ):
|
||||||
|
page_num = parent.page_num( self )
|
||||||
|
parent.remove_page( page_num )
|
||||||
|
parent.insert_page( sibling, None, page_num )
|
||||||
|
else:
|
||||||
|
parent.remove(self)
|
||||||
|
parent.add(sibling)
|
||||||
del(self)
|
del(self)
|
||||||
else:
|
else:
|
||||||
dbg("Paned::wrapcloseterm: self.closeterm failed")
|
dbg("Paned::wrapcloseterm: self.closeterm failed")
|
||||||
|
|
Loading…
Reference in New Issue