From 490c146da95c938a0904c96552dc37f0f7221d64 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 21 Apr 2006 18:34:41 -0400 Subject: [PATCH] Ellipsize tabs only when necessary (unknown title size basically) --- browser/browser.py | 1 + shell/example-activity/activity.py | 9 +++++- shell/src/shell.py | 47 ++++++++++++++++++++++-------- 3 files changed, 44 insertions(+), 13 deletions(-) diff --git a/browser/browser.py b/browser/browser.py index bb0491a3..44ae6eaa 100755 --- a/browser/browser.py +++ b/browser/browser.py @@ -148,6 +148,7 @@ class BrowserActivity(activity.Activity): self.uri = uri def activity_on_connected_to_shell(self): + self.activity_set_ellipsize_tab(True) self.activity_set_can_close(True) self.activity_set_tab_text("Web Page") diff --git a/shell/example-activity/activity.py b/shell/example-activity/activity.py index 986a91d4..8ff6835e 100644 --- a/shell/example-activity/activity.py +++ b/shell/example-activity/activity.py @@ -60,7 +60,14 @@ class Activity(dbus.service.Object): def activity_get_gtk_plug(self): return self.__plug - + + def activity_set_ellipsize_tab(self, ellipsize): + self.__activity_object.set_ellipsize_tab(ellipsize) + + @dbus.service.method("com.redhat.Sugar.Activity", \ + in_signature="", \ + out_signature="") + def activity_set_can_close(self, can_close): self.__activity_object.set_can_close(can_close) diff --git a/shell/src/shell.py b/shell/src/shell.py index dd5f8c95..24c7eefe 100755 --- a/shell/src/shell.py +++ b/shell/src/shell.py @@ -20,6 +20,7 @@ class ActivityHost(dbus.service.Object): global activity_counter self.activity_name = activity_name + self.ellipsize_tab = False self.activity_container = activity_container @@ -41,12 +42,11 @@ class ActivityHost(dbus.service.Object): hbox.pack_start(self.tab_activity_image) self.tab_activity_image.show() - label_hbox = gtk.HBox(False, 4); - label_hbox.connect("style-set", self.__tab_label_style_set_cb) - hbox.pack_start(label_hbox) + self.label_hbox = gtk.HBox(False, 4); + self.label_hbox.connect("style-set", self.__tab_label_style_set_cb) + hbox.pack_start(self.label_hbox) self.tab_label = gtk.Label(self.activity_name) - self.tab_label.set_ellipsize(pango.ELLIPSIZE_END) self.tab_label.set_single_line_mode(True) self.tab_label.set_alignment(0.0, 0.5) self.tab_label.set_padding(0, 0) @@ -65,9 +65,9 @@ class ActivityHost(dbus.service.Object): self.tab_close_button.set_focus_on_click(gtk.FALSE) self.tab_close_button.connect("clicked", self.tab_close_button_clicked) - label_hbox.pack_start(self.tab_label) - label_hbox.pack_start(self.tab_close_button, False, False, 0) - label_hbox.show() + self.label_hbox.pack_start(self.tab_label) + self.label_hbox.pack_start(self.tab_close_button, False, False, 0) + self.label_hbox.show() hbox.show() @@ -97,6 +97,13 @@ class ActivityHost(dbus.service.Object): self.__peer_service_name, self.__peer_object_name), \ "com.redhat.Sugar.Activity") + @dbus.service.method("com.redhat.Sugar.Shell.ActivityHost", \ + in_signature="b", \ + out_signature="") + def set_ellipsize_tab(self, ellipsize): + self.ellipsize_tab = True + self.update_tab_size() + @dbus.service.method("com.redhat.Sugar.Shell.ActivityHost", \ in_signature="b", \ out_signature="") @@ -136,13 +143,29 @@ class ActivityHost(dbus.service.Object): def get_object_path(self): return self.dbus_object_name + def update_tab_size(self): + if self.ellipsize_tab: + self.tab_label.set_ellipsize(pango.ELLIPSIZE_END) + + context = self.label_hbox.get_pango_context() + font_desc = self.label_hbox.style.font_desc + metrics = context.get_metrics(font_desc, context.get_language()) + char_width = metrics.get_approximate_digit_width() + [w, h] = self.__get_close_icon_size() + tab_width = 15 * pango.PIXELS(char_width) + 2 * w + self.label_hbox.set_size_request(tab_width, -1); + else: + self.tab_label.set_ellipsize(pango.ELLIPSIZE_NONE) + widget.set_size_request(-1, -1) + + def __get_close_icon_size(self): + settings = self.label_hbox.get_settings() + return gtk.icon_size_lookup_for_settings(settings, gtk.ICON_SIZE_MENU) + def __tab_label_style_set_cb(self, widget, previous_style): - context = widget.get_pango_context() - metrics = context.get_metrics(widget.style.font_desc, context.get_language()) - char_width = metrics.get_approximate_digit_width() - [w, h] = gtk.icon_size_lookup_for_settings(widget.get_settings(), gtk.ICON_SIZE_MENU) - widget.set_size_request(15 * pango.PIXELS(char_width) + 2 * w, -1); + [w, h] = self.__get_close_icon_size() self.tab_close_button.set_size_request (w + 5, h + 2) + self.update_tab_size() class ActivityContainer(dbus.service.Object):