diff options
author | Ajay Garg <ajay@activitycentral.com> | 2012-02-19 13:50:17 (GMT) |
---|---|---|
committer | Anish Mangal <anish@activitycentral.com> | 2012-04-27 10:02:36 (GMT) |
commit | 9a0feb930318de585369e4430f8862d8cbc133e6 (patch) | |
tree | b7df6aa1f33a261108103f77d0dbc63e159f6b95 | |
parent | 53fc70a4e03eb19de58d1b705b9dead93fa3c0f7 (diff) |
Properly wrap labels in the Network Control Panel (GTK#318276 workaround)
-rw-r--r-- | extensions/cpsection/network/view.py | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/extensions/cpsection/network/view.py b/extensions/cpsection/network/view.py index 48ecfd1..a7d723f 100644 --- a/extensions/cpsection/network/view.py +++ b/extensions/cpsection/network/view.py @@ -32,6 +32,28 @@ TITLE = _('Network') _APPLY_TIMEOUT = 3000 +class WrappedLabel(gtk.Label): + """Variant of gtk.Label that automatically line-wraps the text as needed. + + In theory, stock gtk.Label can already do this, but in practice a + long-standing bug in GTK prevents it from working as expected. + This class includes a workaround for that bug. + + Cave-at: WrappedLabel.set_alignment() will stop working. + """ + + def __init__(self, string=None): + gtk.Label.__init__(self, str=string) + self.set_line_wrap(True) + self.connect('size-allocate', self.__size_allocate_cb) + + def __size_allocate_cb(self, widget, rect): + """Propagate parent size allocation to gtk.Label""" + # This is a workaround for GTK bug #318276 + # https://bugzilla.gnome.org/show_bug.cgi?id=318276 + widget.set_size_request(rect.width, -1) + + # "Proxy" feature merged into "Network" ################################################################################################################# @@ -579,10 +601,9 @@ class Network(SectionView): box_wireless.set_border_width(style.DEFAULT_SPACING * 2) box_wireless.set_spacing(style.DEFAULT_SPACING) - radio_info = gtk.Label(_('Turn off the wireless radio to save battery' + radio_info = WrappedLabel(_('Turn off the wireless radio to save battery' ' life')) radio_info.set_alignment(0, 0) - radio_info.set_line_wrap(True) radio_info.show() box_wireless.pack_start(radio_info, expand=False) @@ -608,10 +629,9 @@ class Network(SectionView): self._radio_alert.props.msg = self.restart_msg self._radio_alert.show() - history_info = gtk.Label(_('Discard network history if you have' - ' trouble connecting to the network')) + history_info = WrappedLabel(_('Discard network history if you have' + ' trouble connecting to the network.')) history_info.set_alignment(0, 0) - history_info.set_line_wrap(True) history_info.show() box_wireless.pack_start(history_info, expand=False) @@ -640,12 +660,11 @@ class Network(SectionView): box_mesh.set_border_width(style.DEFAULT_SPACING * 2) box_mesh.set_spacing(style.DEFAULT_SPACING) - server_info = gtk.Label(_("The server is the equivalent of what" + server_info = 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.")) server_info.set_alignment(0, 0) - server_info.set_line_wrap(True) box_mesh.pack_start(server_info, expand=False) server_info.show() @@ -697,9 +716,8 @@ class Network(SectionView): box_hidden_network.set_border_width(style.DEFAULT_SPACING * 2) box_hidden_network.set_spacing(style.DEFAULT_SPACING) - info = gtk.Label(_("Enter the SSIDs of the hidden networks.")) + info = WrappedLabel(_("Enter the SSIDs of the hidden networks.")) info.set_alignment(0, 0) - info.set_line_wrap(True) box_hidden_network.pack_start(info, expand=False) info.show() @@ -772,10 +790,9 @@ class Network(SectionView): box_nm_connection_editor.set_border_width(style.DEFAULT_SPACING * 2) box_nm_connection_editor.set_spacing(style.DEFAULT_SPACING) - info = gtk.Label(_("Press the 'Launch' button, to launch the" + info = WrappedLabel(_("Press the 'Launch' button, to launch the" " Connection Editor.")) info.set_alignment(0, 0) - info.set_line_wrap(True) box_nm_connection_editor.pack_start(info, expand=False) launch_button = gtk.Button() |