#!/usr/bin/env python # # Tab Active Close Button - Epiphany Extension # Copyright (C) 2006 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 attach_window(window): window._tab_active_close_sig = window.connect("notify::active-tab", active_tab_cb) def detach_window(window): try: sig = window._tab_active_close_sig except AttributeError: pass else: window.disconnect(sig) del window._tab_active_close_sig def apply_close_button(unbound, notebook, tab): hbox = notebook.get_tab_label(tab) if isinstance(hbox, gtk.HBox): children = hbox.get_children() if len(children) == 2 and isinstance(children[1], gtk.Button): unbound(children[1]) def active_tab_cb(window, pspec): try: notebook = window.get_notebook() for tab in map(notebook.get_nth_page, range(notebook.get_n_pages())): apply_close_button(gtk.Button.hide, notebook, tab) apply_close_button(gtk.Button.show, notebook, window.get_active_tab()) except Exception: pass def attach_tab(window, tab): if tab is not window.get_active_tab(): apply_close_button(gtk.Button.hide, window.get_notebook(), tab) def detach_tab(window, tab): apply_close_button(gtk.Button.show, window.get_notebook(), tab)