Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

ui: new function to safely display values in labels

  • Loading branch information...
commit bd7a817332a5f2e7d33ef2fcdabfdc549bf89d63 1 parent 9fd686f
@multani authored
Showing with 10 additions and 2 deletions.
  1. +1 −1  sonata/main.py
  2. +1 −1  sonata/playlists.py
  3. +8 −0 sonata/ui.py
View
2  sonata/main.py
@@ -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,
View
2  sonata/playlists.py
@@ -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]
View
8 sonata/ui.py
@@ -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.
Please sign in to comment.
Something went wrong with that request. Please try again.