[meld] Use WrapLabel from libview to fix wrapping in MsgAreas



commit 33fc88121c6de2ae32cb12b019d936b15afa04f6
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sun Aug 30 10:10:51 2009 +1000

    Use WrapLabel from libview to fix wrapping in MsgAreas
    
    The current wrapping behaviour of gtk.Label causes serious problems when
    using MsgAreas, as Meld's layout means that non-resizing labels in a pane
    cause sizing consistency problems. This commit adds a Python port (by
    Gian Mario Tagliaretti) of WrapLabel from libview, and uses it to provide
    properly wrapping labels in MsgArea.

 meld/ui/msgarea.py   |    6 +++-
 meld/ui/wraplabel.py |   68 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 72 insertions(+), 2 deletions(-)
---
diff --git a/meld/ui/msgarea.py b/meld/ui/msgarea.py
index e53095b..a1483d0 100644
--- a/meld/ui/msgarea.py
+++ b/meld/ui/msgarea.py
@@ -21,6 +21,8 @@ import logging
 import gobject
 import gtk
 
+from wraplabel import WrapLabel
+
 _logger = logging.getLogger("hotwire.ui.MsgArea")
 
 # This file is a Python translation of gedit/gedit/gedit-message-area.c
@@ -192,7 +194,7 @@ class MsgArea(gtk.HBox):
         hbox_content.pack_start (vbox, True, True, 0)
 
         primary_markup = "<b>%s</b>" % (primary_text,)
-        primary_label = gtk.Label(primary_markup)
+        primary_label = WrapLabel(primary_markup)
         primary_label.show()
         vbox.pack_start(primary_label, True, True, 0)
         primary_label.set_use_markup(True)
@@ -203,7 +205,7 @@ class MsgArea(gtk.HBox):
 
         if secondary_text:
             secondary_markup = "<small>%s</small>" % (secondary_text,)
-            secondary_label = gtk.Label(secondary_markup)
+            secondary_label = WrapLabel(secondary_markup)
             secondary_label.show()
             vbox.pack_start(secondary_label, True, True, 0)
             secondary_label.set_flags(gtk.CAN_FOCUS)
diff --git a/meld/ui/wraplabel.py b/meld/ui/wraplabel.py
new file mode 100644
index 0000000..d40a5be
--- /dev/null
+++ b/meld/ui/wraplabel.py
@@ -0,0 +1,68 @@
+# Copyright (c) 2005 VMware, Inc.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+# Python translation from wrapLabel.{cc|h} by Gian Mario Tagliaretti
+
+import gtk
+import gobject
+import pango
+
+
+class WrapLabel(gtk.Label):
+    __gtype_name__ = 'WrapLabel'
+
+    def __init__(self, str=None):
+        gtk.Label.__init__(self)
+
+        self.__wrap_width = 0
+        self.layout = self.get_layout()
+        self.layout.set_wrap(pango.WRAP_WORD_CHAR)
+
+        if str != None:
+            self.set_text(str)
+
+        self.set_alignment(0.0, 0.0)
+
+    def do_size_request(self, requisition):
+        layout = self.get_layout()
+        width, height = layout.get_pixel_size()
+        requisition.width = 0
+        requisition.height = height
+
+    def do_size_allocate(self, allocation):
+        gtk.Label.do_size_allocate(self, allocation)
+        self.__set_wrap_width(allocation.width)
+
+    def set_text(self, str):
+        gtk.Label.set_text(self, str)
+        self.__set_wrap_width(self.__wrap_width)
+
+    def set_markup(self, str):
+        gtk.Label.set_markup(self, str)
+        self.__set_wrap_width(self.__wrap_width)
+
+    def __set_wrap_width(self, width):
+        if width == 0:
+            return
+        layout = self.get_layout()
+        layout.set_width(width * pango.SCALE)
+        if self.__wrap_width != width:
+            self.__wrap_width = width
+            self.queue_resize()



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