[PATCH 5/7] Update NotebookLabel tab drawing



This change does the following:
- Makes tab width dynamic
  - This conserves space for tabs with a small amount of text
  - This allows the text of tabs with a large amount of text to be
    fully shown.  Previously the tab size was hardcoded and part
    of the tab text would be truncated.
  - Gnome's Human Interface Guidelines recommend dynamic tab widths.
- Simplifies tab drawing
  - Removes complex Pango text and icon size calculations

Signed-off-by: Peter Tyser <ptyser gmail com>
---
 meld/ui/notebooklabel.py |   40 +++++++++++++---------------------------
 1 files changed, 13 insertions(+), 27 deletions(-)

diff --git a/meld/ui/notebooklabel.py b/meld/ui/notebooklabel.py
index 4b6c0a9..5e3c2ab 100644
--- a/meld/ui/notebooklabel.py
+++ b/meld/ui/notebooklabel.py
@@ -19,8 +19,6 @@
 from gettext import gettext as _
 
 import gtk
-import pango
-
 gtk.rc_parse_string(
     """
     style "meld-tab-close-button-style" {
@@ -33,48 +31,36 @@ gtk.rc_parse_string(
     """)
 
 class NotebookLabel(gtk.HBox):
-    tab_width_in_chars = 30
-
     def __init__(self, iconname, text, onclose):
         gtk.HBox.__init__(self, False, 4)
 
         label = gtk.Label(text)
-        # FIXME: ideally, we would use custom ellipsization that ellipsized the
-        # two paths separately, but that requires significant changes to label
-        # generation in many different parts of the code
-        label.set_ellipsize(pango.ELLIPSIZE_MIDDLE)
         label.set_single_line_mode(True)
-        label.set_alignment(0.0, 0.5)
         label.set_padding(0, 0)
 
-        context = self.get_pango_context()
-        metrics = context.get_metrics(self.style.font_desc, context.get_language())
-        char_width = metrics.get_approximate_digit_width()
-        (w, h) = gtk.icon_size_lookup_for_settings (self.get_settings(), gtk.ICON_SIZE_MENU)
-        self.set_size_request(self.tab_width_in_chars * pango.PIXELS(char_width) + 2 * w, -1)
+        # Get stock close and document icons for tabs
+        close_image = gtk.image_new_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU)
+        icon_image = gtk.image_new_from_icon_name(iconname, gtk.ICON_SIZE_MENU)
 
-        button = gtk.Button()
-        button.set_relief(gtk.RELIEF_NONE)
-        button.set_focus_on_click(False)
-        image = gtk.image_new_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU)
+        close_button = gtk.Button()
+        close_button.set_relief(gtk.RELIEF_NONE)
+        close_button.set_focus_on_click(False)
         if gtk.pygtk_version >= (2, 12, 0):
-            image.set_tooltip_text(_("Close tab"))
-        button.add(image)
-        button.set_name("meld-tab-close-button")
-        button.set_size_request(w + 2, h + 2)
-        button.connect("clicked", onclose)
-
-        icon = gtk.image_new_from_icon_name(iconname, gtk.ICON_SIZE_MENU)
+            close_image.set_tooltip_text(_("Close tab"))
+        close_button.add(close_image)
+        close_button.set_name("meld-tab-close-button")
+        close_button.connect("clicked", onclose)
 
+        # Allow middle-clicking to close a tab
         label_box = gtk.EventBox()
         label_box.add_events(gtk.gdk.BUTTON_PRESS_MASK)
         label_box.props.visible_window = False
         label_box.connect("button-press-event", self.on_label_clicked)
         label_box.add(label)
 
-        self.pack_start(icon, expand=False)
+        self.pack_start(icon_image, expand=False)
         self.pack_start(label_box)
-        self.pack_start(button, expand=False)
+        self.pack_start(close_button, expand=False)
         if gtk.pygtk_version >= (2, 12, 0):
             self.set_tooltip_text(text)
         self.show_all()
-- 
1.7.1.13.gcfb88



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