On 08/07/2012 03:32 PM, Sascha Silbe wrote:
When line wrapping is enabled (label.set_line_wrap(True)), GTK restricts
labels to an arbitrary size, rather than utilising the entire allocated space.
This has been known upstream since 2005 (GTK#318276 [1]), but remains unfixed
to date.

Work around this bug by using a size-allocate signal handler that sets the
requested size of the label to the actual allocation.

[1] https://bugzilla.gnome.org/show_bug.cgi?id=318276

Could it be that the issue is fixed in GTK+ 3 and introspection? I have attached two examples.

Regards,
   Simon





from gi.repository import Gtk

class WrappedLabel(Gtk.Label):
    def __init__(self, label=None):
        Gtk.Label.__init__(self, label=label)
        self.set_line_wrap(True)
        self.connect('size-allocate', self.__size_allocate_cb)
    def __size_allocate_cb(self, widget, rect):
        widget.set_size_request(rect.width, -1)

def _destroy_cb(widget, data=None):
    Gtk.main_quit()

window = Gtk.Window()
window.connect("destroy", _destroy_cb)
window.set_default_size(450, 450)

entry = WrappedLabel("The server is the equivalent of what"
                     " room you are in; people on the same"
                     " server will be able to see each other,"
                     " even when they aren't on the same "
                     " network.")
'''
entry = Gtk.Label("The server is the equivalent of what"
                  " room you are in; people on the same"                                                                                                                              
                  " server will be able to see each other,"                                                                                                                           
                  " even when they aren't on the same "                                                                                                                              
                  " network.")
'''
entry.set_line_wrap(True)
window.add(entry)
entry.show()

window.show()
Gtk.main()
import gtk

class WrappedLabel(gtk.Label):
    def __init__(self, label=None):
        gtk.Label.__init__(self, str=label)
        self.set_line_wrap(True)
        self.connect('size-allocate', self.__size_allocate_cb)
    def __size_allocate_cb(self, widget, rect):
        widget.set_size_request(rect.width, -1)

def _destroy_cb(widget, data=None):
    gtk.main_quit()

window = gtk.Window()
window.connect("destroy", _destroy_cb)
window.set_default_size(450, 450)
'''
entry = WrappedLabel("The server is the equivalent of what"
                     " room you are in; people on the same"
                     " server will be able to see each other,"
                     " even when they aren't on the same "
                     " network.")
'''
entry = gtk.Label("The server is the equivalent of what"
                  " room you are in; people on the same"                                                                                                                              
                  " server will be able to see each other,"                                                                                                                           
                  " even when they aren't on the same "                                                                                                                              
                  " network.")

entry.set_line_wrap(True)
window.add(entry)
entry.show()

window.show()
gtk.main()
_______________________________________________
Sugar-devel mailing list
Sugar-devel@lists.sugarlabs.org
http://lists.sugarlabs.org/listinfo/sugar-devel

Reply via email to