Skip to content

Commit

Permalink
ui: new function to safely display values in labels
Browse files Browse the repository at this point in the history
  • Loading branch information
multani committed Apr 6, 2012
1 parent 9fd686f commit bd7a817
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion sonata/main.py
Expand Up @@ -1047,7 +1047,7 @@ def populate_profiles_for_menu(self):
profile_names = [_("MPD_HOST/PORT")] if host \
or port else self.config.profile_names
actions = [(str(i), None,
"[%s] %s" % (i + 1, name.replace("_", "__")), None,
"[%s] %s" % (i + 1, ui.quote_label(name)), None,
None, i)
for i, name in enumerate(profile_names)]
actions.append(('disconnect', None, _('Disconnect'), None, None,
Expand Down
2 changes: 1 addition & 1 deletion sonata/playlists.py
Expand Up @@ -103,7 +103,7 @@ def populate_playlists_for_menu(self, playlistinfo):
self.UIManager().ensure_update()
actions = [("Playlist: %s" % playlist.replace("&", ""),
gtk.STOCK_JUSTIFY_CENTER,
misc.unescape_html(playlist).replace("_", "__"),
ui.quote_label(misc.unescape_html(playlist)),
None, None,
self.on_playlist_menu_click)
for playlist in playlistinfo]
Expand Down
8 changes: 8 additions & 0 deletions sonata/ui.py
Expand Up @@ -231,6 +231,14 @@ def hide(widget):
def focus(widget):
widget.grab_focus()

def quote_label(label_value):
"""Quote the content of a label so that it's safe to display."""

# Don't inadvertently create accelerators if the value contains a "_"
result = label_value.replace("_", "__")

return result

def set_widths_equal(widgets):
# Assigns the same width to all passed widgets in the list, where
# the width is the maximum width across widgets.
Expand Down

0 comments on commit bd7a817

Please sign in to comment.