diff options
author | Daniel Francis <francis@sugarlabs.org> | 2012-09-26 16:12:37 (GMT) |
---|---|---|
committer | Daniel Francis <francis@sugarlabs.org> | 2012-09-26 16:12:37 (GMT) |
commit | fb2d170f73b404e78ffd86d4777ab6edeb470cae (patch) | |
tree | ac57119a9216dcafd4241748641a92f04eb6eb50 | |
parent | ee19ee6f882557dfe127acaa3c0a08c2044c8763 (diff) |
Expand tabs properly
- If there is only one tab, it'll have the notebook with divided by two.
- If there are more tabs they are expanded correctly.
So this commit also corrects the expanding algorithm of the tabs.
Minor change: Remove some lines from the old tab toolbar.
-rw-r--r-- | terminal.py | 12 | ||||
-rw-r--r-- | widgets.py | 52 |
2 files changed, 28 insertions, 36 deletions
diff --git a/terminal.py b/terminal.py index 63c0d61..4245874 100644 --- a/terminal.py +++ b/terminal.py @@ -219,9 +219,6 @@ class TerminalActivity(activity.Activity): if self._notebook.get_n_pages() == 2: self._notebook.get_tab_label(self._notebook.get_nth_page(0 )).show_close_button() - self._delete_tab_button.props.sensitive = True - self._previous_tab_button.props.sensitive = True - self._next_tab_button.props.sensitive = True def __close_tab_cb(self, btn, child): index = self._notebook.page_num(child) @@ -229,11 +226,6 @@ class TerminalActivity(activity.Activity): if self._notebook.get_n_pages() == 1: self._notebook.get_tab_label(self._notebook.get_nth_page(0 )).hide_close_button() - self._delete_tab_button.props.sensitive = False - self._previous_tab_button.props.sensitive = False - self._next_tab_button.props.sensitive = False - - self._notebook.update_tab_sizes() def __prev_tab_cb(self, btn): if self._notebook.props.page == 0: @@ -311,15 +303,13 @@ class TerminalActivity(activity.Activity): index = self._notebook.append_page(box, tablabel) tablabel.show_all() - self._notebook.update_tab_sizes() - self._notebook.show_all() - # Uncomment this to only show the tab bar when there is at least # one tab. I think it's useful to always see it, since it displays # the 'window title'. # self._notebook.props.show_tabs = self._notebook.get_n_pages() > 1 tablabel.hide_close_button() if self._notebook.get_n_pages() == 1\ else None + self._notebook.show_all() # Launch the default shell in the HOME directory. os.chdir(os.environ["HOME"]) @@ -1,8 +1,7 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- # Copyright (C) 2006, Red Hat, Inc. # Copyright (C) 2011, One Laptop Per Child # Copyright (C) 2009, Tomeu Vizoso, Simon Schampijer +# Copyright (C) 2012, Daniel Francis # # 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 @@ -54,8 +53,6 @@ class TabAdd(Gtk.Button): class BrowserNotebook(Gtk.Notebook): - __gtype_name__ = 'BrowseNotebook' - __gsignals__ = { 'tab-added': (GObject.SignalFlags.RUN_FIRST, None, @@ -67,42 +64,48 @@ class BrowserNotebook(Gtk.Notebook): def __init__(self): GObject.GObject.__init__(self) - self.first_expose = True self.connect("draw", self._draw_cb) self._tab_add = TabAdd() self._tab_add.connect('tab-added', self.on_add_tab) self.set_action_widget(self._tab_add, Gtk.PackType.END) self._tab_add.show() + self.n_pages = 0 + self.width = 0 + self.button_size = 0 def _draw_cb(self, widget, event): - if self.first_expose: + # Update tab sizes + n_pages = self.get_n_pages() + width = self.get_allocation().width + button_size = self._tab_add.get_allocation().width + if n_pages != self._n_pages or width !=\ + self.width or self.button_size != button_size: + self.n_pages = n_pages + self.width = width + self.button_size = button_size self.update_tab_sizes() - self.first_expose = False def on_add_tab(self, obj): self.emit('tab-added') def update_tab_sizes(self): - n_pages = self.get_n_pages() - canvas_size = self.get_allocation() - - # FIXME - # overlap_size = self.style_get_property('tab-overlap') * n_pages - 1 - overlap_size = 0 - allowed_size = canvas_size.width - overlap_size - - tab_new_size = int(float(allowed_size) / (n_pages) -\ - self._tab_add.get_allocation().width - 5) - - for page_idx in range(n_pages): - page = self.get_nth_page(page_idx) - label = self.get_tab_label(page) - label.update_size(tab_new_size) + allowed_size = self.width + if self._n_pages == 1: + tab_new_size = int(allowed_size / 2) + for page_idx in range(self.n_pages): + page = self.get_nth_page(page_idx) + label = self.get_tab_label(page) + self.child_set_property(page, 'tab-expand', False) + label.update_size(tab_new_size) + else: + for page_idx in range(self._n_pages): + page = self.get_nth_page(page_idx) + label = self.get_tab_label(page) + label.update_size(-1) + self.child_set_property(page, 'tab-expand', True) class TabLabel(Gtk.HBox): - __gtype_name__ = 'BrowseTabLabel' - __gsignals__ = { 'tab-close': (GObject.SignalFlags.RUN_FIRST, None, @@ -127,7 +130,6 @@ class TabLabel(Gtk.HBox): icon_box.pack_start(close_tab_icon, True, False, 0) button.add(icon_box) button.connect('clicked', self.__button_clicked_cb) - button.set_name('browse-tab-close') self.pack_start(button, False, True, 0) close_tab_icon.show() icon_box.show() |