Cleaner context menu options

This commit is contained in:
Valentijn 2018-05-27 00:29:57 +02:00
parent c4c900f3d9
commit 805cfbf26d

View file

@ -227,7 +227,7 @@ class SongListBoxPopup(urwid.LineBox):
def __init__(self, songitem): def __init__(self, songitem):
self.songitem = songitem self.songitem = songitem
options = [ self.options = [
urwid.AttrWrap( urwid.AttrWrap(
urwid.Text(' ' + songitem.full_title), urwid.Text(' ' + songitem.full_title),
'panel' 'panel'
@ -241,41 +241,51 @@ class SongListBoxPopup(urwid.LineBox):
'panel_divider' 'panel_divider'
) )
] ]
options.append(self._create_divider())
if not gp.get_track_by_id(songitem.track.id): if not gp.get_track_by_id(songitem.track.id):
options.append(self._create_button('Add to library', self.add_to_my_library)) self._add_item('Add to library', self.add_to_my_library)
else: else:
options.append(self._create_button('Remove from library', self.remove_from_my_library)) self._add_item('Remove from library', self.remove_from_my_library)
options.append(self._create_divider())
options.append(self._create_button('Create station', self.create_station)) self._add_item('Create station', self.create_station)
options.append(self._create_divider())
if self.songitem.track in player.get_queue_tracks(): if self.songitem.track in player.get_queue_tracks():
options.append(self._create_button('Remove from queue', self.remove_from_queue)) self._add_item('Remove from queue', self.from_queue)
else: else:
options.append(self._create_button('Append to queue', self.append_to_queue)) self._add_item('Append to queue', self.append_to_queue)
if self.songitem.track.cached_url is not None: if self.songitem.track.cached_url is not None:
options.append(self._create_button('Copy URL to clipboard', self.copy_url)) self._add_item('Copy URL to clipboard', self.copy_url)
options.append(self._create_button('Close', self.close))
self.options.append(
urwid.AttrWrap(
urwid.Button('Close', on_press=self.close),
'panel',
'panel_focus'))
super(SongListBoxPopup, self).__init__( super(SongListBoxPopup, self).__init__(
urwid.Pile(options) urwid.Pile(self.options)
) )
def _create_divider(self): def _add_item(self, name, func):
""" """
Return a divider widget. Add an item to the list with a divider.
Args:
name (str): The name of the option
func: The function to call afterwards
""" """
return urwid.AttrWrap( self.options.append(
urwid.AttrWrap(
urwid.Divider(u'\u2500'), urwid.Divider(u'\u2500'),
'panel_divider', 'panel_divider',
'panel_divider_focus' 'panel_divider_focus'))
)
def _create_button(self, title, on_press): self.options.append(
return urwid.AttrWrap( urwid.AttrWrap(
urwid.Button(title, on_press=on_press), urwid.Button(name, on_press=func),
'panel', 'panel',
'panel_focus' 'panel_focus'))
)
def add_to_my_library(self, _): def add_to_my_library(self, _):
""" """