Author: asterix Date: 2009-04-08 20:52:50 +0200 (Wed, 08 Apr 2009) New Revision: 11221
Modified: trunk/src/dataforms_widget.py trunk/src/gtkgui_helpers.py Log: make instruction label of dataforms wrapable. see #4724
Modified: trunk/src/dataforms_widget.py =================================================================== --- trunk/src/dataforms_widget.py 2009-04-08 18:13:08 UTC (rev 11220) +++ trunk/src/dataforms_widget.py 2009-04-08 18:52:50 UTC (rev 11221) @@ -81,6 +81,7 @@ 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. '''
Modified: trunk/src/gtkgui_helpers.py =================================================================== --- trunk/src/gtkgui_helpers.py 2009-04-08 18:13:08 UTC (rev 11220) +++ trunk/src/gtkgui_helpers.py 2009-04-08 18:52:50 UTC (rev 11221) @@ -982,4 +982,31 @@ 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: