Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/widgets.py
diff options
context:
space:
mode:
authorManuel QuiƱones <manuq@laptop.org>2011-09-09 02:42:35 (GMT)
committer Simon Schampijer <simon@schampijer.de>2011-09-10 06:45:49 (GMT)
commit959f86e0406914267047dc10302f98a059b6ba21 (patch)
treed5a5582f52e5af4b3bd2b95beeff604492049eff /widgets.py
parent370dfc1c167934eb4784b0444b28a493c4cc6cec (diff)
Browse: tabs usability improved
The Add Tab button has been relocated next to the tab labels, allowing more space for the URL entry. Tabs are always shown. There is at least one tab. In that case, it cannot be closed. We prevent the closing by hiding the 'X' button. Also, the close image was sugarized. There is now a fixed width for tabs. The label text does ellipsize. The width depends on the amount of tabs. There is a maximum size that is used when there is extra space. There is a minimum size to prevent hiding the information. When a new tab is opened, it now shows an empty page, not the default page. In the future, we will add a hint in this empty page, similar to what we have for an empty Journal. Added the option to "follow link in new tab" in the link's palette. Added an icon for this item, and also the icon for "follow link" is also updated. When a new tab is opened via the '+' button, the focus goes to the URL entry in the toolbar. Signed-off-by: Manuel QuiƱones <manuq@laptop.org> Acked-by: Simon Schampijer <simon@laptop.org>
Diffstat (limited to 'widgets.py')
-rw-r--r--widgets.py93
1 files changed, 93 insertions, 0 deletions
diff --git a/widgets.py b/widgets.py
new file mode 100644
index 0000000..b39ba5e
--- /dev/null
+++ b/widgets.py
@@ -0,0 +1,93 @@
+# Copyright (C) 2006, Red Hat, Inc.
+# Copyright (C) 2011, One Laptop Per Child
+# Copyright (C) 2009, Tomeu Vizoso, Simon Schampijer
+#
+# 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 St, Fifth Floor, Boston, MA 02110-1301 USA
+
+import gobject
+import gtk
+
+from sugar.graphics.icon import Icon
+
+
+class TabAdd(gtk.HBox):
+ __gtype_name__ = 'TabAdd'
+
+ __gsignals__ = {
+ 'tab-added': (gobject.SIGNAL_RUN_FIRST,
+ gobject.TYPE_NONE,
+ ([])),
+ }
+
+ def __init__(self):
+ gtk.HBox.__init__(self)
+
+ add_tab_icon = Icon(icon_name='add')
+ button = gtk.Button()
+ button.props.relief = gtk.RELIEF_NONE
+ button.props.focus_on_click = False
+ icon_box = gtk.HBox()
+ icon_box.pack_start(add_tab_icon, True, False, 0)
+ button.add(icon_box)
+ button.connect('clicked', self.__button_clicked_cb)
+ button.set_name('browse-tab-add')
+ self.pack_start(button)
+ add_tab_icon.show()
+ icon_box.show()
+ button.show()
+
+ def __button_clicked_cb(self, button):
+ self.emit('tab-added')
+
+
+class BrowserNotebook(gtk.Notebook):
+ """Handle an extra tab at the end with an Add Tab button."""
+
+ def __init__(self):
+ gtk.Notebook.__init__(self)
+ self._switch_handler = self.connect('switch-page',
+ self.__on_switch_page)
+
+ tab_add = TabAdd()
+ tab_add.connect('tab-added', self.on_add_tab)
+ empty_page = gtk.HBox()
+ self.append_page(empty_page, tab_add)
+ empty_page.show()
+
+ def on_add_tab(self, obj):
+ raise NotImplementedError, "implement this in the subclass"
+
+ def __on_switch_page(self, notebook, page, page_num):
+ """Don't switch to the extra tab at the end."""
+ if page_num == gtk.Notebook.get_n_pages(self) - 1:
+ self.handler_block(self._switch_handler)
+ self.set_current_page(-1)
+ self.handler_unblock(self._switch_handler)
+ self.connect('switch-page', self.__on_switch_page)
+ self.stop_emission("switch-page")
+
+ def get_n_pages(self):
+ """Skip the extra tab at the end on the pages count."""
+ return gtk.Notebook.get_n_pages(self) - 1
+
+ def append_page(self, page, label):
+ """Append keeping the extra tab at the end."""
+ return self.insert_page(page, label, self.get_n_pages())
+
+ def set_current_page(self, number):
+ """If indexing from the end, skip the extra tab."""
+ if number < 0:
+ number = self.get_n_pages() - 1
+ gtk.Notebook.set_current_page(self, number)