middle click tab close



Hi,

I've updated the code from http://www.sstuhr.dk/epiphany-extensions/ of
'middle click tab close' to work with recent versions of epiphany (2.22,
2.24).
Not really the cleanest code, but does the job.

Thanks,
-- 
Maciej Borzęcki <maciek borzecki gmail com>
#!/usr/bin/env python
#
#   Middle Click Tab Close - Epiphany Extension
#   Copyright (C) 2006  Stefan Stuhr
#                 2008  Maciej Borzecki
#
#   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.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License along
#   with this program; if not, write to the Free Software Foundation, Inc.,
#   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.


import gtk
import epiphany

def click_cb(notebook, event, window):
    if (event.button != 2):
        return
    (ww, wh) = window.get_size()
    closest_tab = None
    closest_tab_x = ww
    for tab in notebook._tabs_list:
        w = notebook.get_tab_label(tab)
        lx, ly = w.get_pointer()
        (x, y) = w.get_pointer()
        if (x < 0):
            continue
        if (lx < closest_tab_x):
            closest_tab_x = lx
            closest_tab = tab
    notebook.remove_page(notebook.page_num(closest_tab))

def attach_window(window):
    notebook = window.get_notebook()
    sig = notebook.connect('button-press-event', click_cb, window)
    notebook._button_press_event_sig = sig
    notebook._tabs_list = list()

def detach_window(window):
    notebook = window.get_notebook()
    notebook.disconnect(notebook._button_press_event_sig)
    del notebook._tabs_list

def attach_tab(window, tab):
    notebook = window.get_notebook()
    widget = notebook.get_tab_label(tab)
    notebook._tabs_list.append(tab)

def detach_tab(window, tab):
    notebook = window.get_notebook()
    notebook._tabs_list.remove(tab)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]