Armed with a text editor

mu's views on program and recipe! design

#!/usr/bin/env python
#
#   Expand Four Tabs - Epiphany Extension
#   Copyright (C) 2006  Stefan Stuhr, Michael Urman
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#

import gtk
import epiphany

def hbox_style_set_cb(hbox, previous_style):
    hbox._expand4tabs_original_width = hbox.get_size_request()[0]
    hbox.set_size_request(16, -1)

def attach_tab(window, tab):
    notebook = window.get_notebook()
    notebook.child_set(tab, "tab-expand", True)

    hbox = notebook.get_tab_label(tab)
    if not isinstance(hbox, gtk.HBox): return

    hbox._expand4tabs_original_width = hbox.get_size_request()[0]
    hbox.set_size_request(16, -1)
    hbox._expand4tabs_hbox_style_set_sig = hbox.connect("style-set",
            hbox_style_set_cb)

def detach_tab(window, tab):
    notebook = window.get_notebook()
    hbox = notebook.get_tab_label(tab)

    if tab.get_parent() == notebook:
        notebook.child_set(tab, "tab-expand", False)

    if not isinstance(hbox, gtk.HBox): return

    try:
        sig = hbox._expand4tabs_hbox_style_set_sig
    except AttributeError:
        pass
    else:
        hbox.disconnect(sig)
        del hbox._expand4tabs_hbox_style_set_sig

    try:
        width = hbox._expand4tabs_original_width
    except AttributeError:
        pass
    else:
        window.set_geometry_hints(hbox, -1)
        hbox.set_size_request(width, -1)
        del hbox._expand4tabs_original_width