All pastes #987930 Raw Edit

Anonymous

public text v1 · immutable
#987930 ·published 2008-04-17 02:53 UTC
rendered paste body
#!/usr/bin/env python
#
#   Middle Click Tab Close - Epiphany Extension
#   Copyright (C) 2006  Stefan Stuhr
#
#   Updated for epiphany 2.20
#	Copyright (C) 2008 Christopher Williams
#
#   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.

def on_button_release_event(notebook, event):
	if event.button != 2:
		return False

	notebook_x, notebook_y = notebook.allocation.x, notebook.allocation.y

	for child in notebook.get_children():
		tab = notebook.get_tab_label(child)
		width, height = tab.allocation.width, tab.allocation.height
		x, y = tab.allocation.x - notebook_x, tab.allocation.y - notebook_y

		if x < event.x < x + width and y < event.y < y + height:
			notebook.remove(child)
			break
	else:
		return False

	return True

def attach_window(window):
	notebook = window.get_notebook()
	notebook.connect("button-release-event", on_button_release_event)

def detach_window(window):
	notebook = window.get_notebook()
	notebook.disconnect_by_func(on_button_release_event)