From 4ac97dae2bc7130c0eb18ba72ed2815400c080f8 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Wed, 8 Apr 2009 18:52:50 +0000 Subject: [PATCH] make instruction label of dataforms wrapable. see #4724 --- src/dataforms_widget.py | 1 + src/gtkgui_helpers.py | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/dataforms_widget.py b/src/dataforms_widget.py index c997f7ed0..a5bba4dc3 100644 --- a/src/dataforms_widget.py +++ b/src/dataforms_widget.py @@ -81,6 +81,7 @@ class DataFormWidget(gtk.Alignment, object): self.instructions_label.hide() else: self.instructions_label.set_text(dataform.instructions) + gtkgui_helpers.label_set_autowrap(self.instructions_label) def get_data_form(self): ''' Data form displayed in the widget or None if no form. ''' diff --git a/src/gtkgui_helpers.py b/src/gtkgui_helpers.py index fa54ff471..3983b6aba 100644 --- a/src/gtkgui_helpers.py +++ b/src/gtkgui_helpers.py @@ -982,4 +982,31 @@ def reload_jabber_state_images(): make_jabber_state_images() gajim.interface.roster.update_jabber_state_images() +def label_set_autowrap(widget): + '''Make labels automatically re-wrap if their containers are resized. + Accepts label or container widgets.''' + if isinstance (widget, gtk.Container): + children = widget.get_children() + for i in xrange (len (children)): + label_set_autowrap(children[i]) + elif isinstance(widget, gtk.Label): + widget.set_line_wrap(True) + widget.connect_after('size-allocate', __label_size_allocate) + +def __label_size_allocate(widget, allocation): + '''Callback which re-allocates the size of a label.''' + layout = widget.get_layout() + + lw_old, lh_old = layout.get_size() + # fixed width labels + if lw_old/pango.SCALE == allocation.width: + return + + # set wrap width to the pango.Layout of the labels ### + layout.set_width (allocation.width * pango.SCALE) + lw, lh = layout.get_size () + + if lh_old != lh: + widget.set_size_request (-1, lh / pango.SCALE) + # vim: se ts=3: