mirror of
https://github.com/vale981/clay
synced 2025-03-05 09:31:40 -05:00
More context options.
This commit is contained in:
parent
ba72255d98
commit
c274fafac4
3 changed files with 66 additions and 22 deletions
|
@ -8,7 +8,7 @@ Main app entrypoint.
|
|||
|
||||
import sys
|
||||
sys.path.insert(0, '.') # noqa
|
||||
# sys.path.insert(0, '/home/anderson/src/urwid') # noqa
|
||||
sys.path.insert(0, '/home/anderson/src/urwid') # noqa
|
||||
|
||||
import urwid
|
||||
|
||||
|
@ -325,6 +325,13 @@ class AppWidget(urwid.Frame):
|
|||
"""
|
||||
self._cancel_actions.append(action)
|
||||
|
||||
def unregister_cancel_action(self, action):
|
||||
"""
|
||||
Remove cancel action from action stack.
|
||||
"""
|
||||
if action in self._cancel_actions:
|
||||
self._cancel_actions.remove(action)
|
||||
|
||||
def keypress(self, size, key):
|
||||
"""
|
||||
Handle keypress.
|
||||
|
|
|
@ -29,18 +29,18 @@ class Queue(object):
|
|||
self.repeat_one = False
|
||||
|
||||
self.tracks = []
|
||||
self.current_track = None
|
||||
self.current_track_index = None
|
||||
|
||||
def load(self, tracks, current_track=None):
|
||||
def load(self, tracks, current_track_index=None):
|
||||
"""
|
||||
Load list of tracks into queue.
|
||||
|
||||
*current_track* can be either ``None`` or ``int`` (zero-indexed).
|
||||
*current_track_index* can be either ``None`` or ``int`` (zero-indexed).
|
||||
"""
|
||||
self.tracks = tracks[:]
|
||||
if (current_track is None) and self.tracks:
|
||||
current_track = 0
|
||||
self.current_track = current_track
|
||||
if (current_track_index is None) and self.tracks:
|
||||
current_track_index = 0
|
||||
self.current_track_index = current_track_index
|
||||
|
||||
def append(self, track):
|
||||
"""
|
||||
|
@ -57,16 +57,18 @@ class Queue(object):
|
|||
|
||||
index = self.tracks.index(track)
|
||||
self.tracks.remove(track)
|
||||
if index < self.current_track:
|
||||
self.current_track -= 1
|
||||
if self.current_track_index is None:
|
||||
return
|
||||
if index < self.current_track_index:
|
||||
self.current_track_index -= 1
|
||||
|
||||
def get_current_track(self):
|
||||
"""
|
||||
Return current :class:`clay.gp.Track`
|
||||
"""
|
||||
if self.current_track is None:
|
||||
if self.current_track_index is None:
|
||||
return None
|
||||
return self.tracks[self.current_track]
|
||||
return self.tracks[self.current_track_index]
|
||||
|
||||
def next(self, force=False):
|
||||
"""
|
||||
|
@ -79,21 +81,21 @@ class Queue(object):
|
|||
Manual track switching calls this method with ``force=True`` while
|
||||
:class:`.Player` end-of-track event will call it with ``force=False``.
|
||||
"""
|
||||
if self.current_track is None:
|
||||
if self.current_track_index is None:
|
||||
if not self.tracks:
|
||||
return None
|
||||
self.current_track = self.tracks[0]
|
||||
self.current_track_index = self.tracks[0]
|
||||
|
||||
if self.repeat_one and not force:
|
||||
return self.get_current_track()
|
||||
|
||||
if self.random:
|
||||
self.current_track = randint(0, len(self.tracks) - 1)
|
||||
self.current_track_index = randint(0, len(self.tracks) - 1)
|
||||
return self.get_current_track()
|
||||
|
||||
self.current_track += 1
|
||||
if (self.current_track + 1) >= len(self.tracks):
|
||||
self.current_track = 0
|
||||
self.current_track_index += 1
|
||||
if (self.current_track_index + 1) >= len(self.tracks):
|
||||
self.current_track_index = 0
|
||||
|
||||
return self.get_current_track()
|
||||
|
||||
|
|
|
@ -220,6 +220,23 @@ class SongListBoxPopup(urwid.LineBox):
|
|||
'panel_divider',
|
||||
'panel_divider_focus'
|
||||
))
|
||||
if self.songitem.track in Player.get().get_queue_tracks():
|
||||
options.append(urwid.AttrWrap(
|
||||
urwid.Button('Remove from queue', on_press=self.remove_from_queue),
|
||||
'panel',
|
||||
'panel_focus'
|
||||
))
|
||||
else:
|
||||
options.append(urwid.AttrWrap(
|
||||
urwid.Button('Append to queue', on_press=self.append_to_queue),
|
||||
'panel',
|
||||
'panel_focus'
|
||||
))
|
||||
options.append(urwid.AttrWrap(
|
||||
urwid.Divider(u'\u2500'),
|
||||
'panel_divider',
|
||||
'panel_divider_focus'
|
||||
))
|
||||
options.append(urwid.AttrWrap(
|
||||
urwid.Button('Close', on_press=self.close),
|
||||
'panel',
|
||||
|
@ -263,6 +280,20 @@ class SongListBoxPopup(urwid.LineBox):
|
|||
self.songitem.track.remove_from_my_library_async(callback=on_remove_from_my_library)
|
||||
self.close()
|
||||
|
||||
def append_to_queue(self, _):
|
||||
"""
|
||||
Appends related track to queue.
|
||||
"""
|
||||
Player.get().append_to_queue(self.songitem.track)
|
||||
self.close()
|
||||
|
||||
def remove_from_queue(self, _):
|
||||
"""
|
||||
Removes related track from queue.
|
||||
"""
|
||||
Player.get().remove_from_queue(self.songitem.track)
|
||||
self.close()
|
||||
|
||||
def create_station(self, _):
|
||||
"""
|
||||
Create a station from this track.
|
||||
|
@ -317,6 +348,7 @@ class SongListBox(urwid.Frame):
|
|||
)
|
||||
|
||||
self._is_filtering = False
|
||||
self.popup = None
|
||||
|
||||
super(SongListBox, self).__init__(
|
||||
body=self.content
|
||||
|
@ -444,10 +476,10 @@ class SongListBox(urwid.Frame):
|
|||
"""
|
||||
Show context menu.
|
||||
"""
|
||||
popup = SongListBoxPopup(songitem)
|
||||
self.app.append_cancel_action(popup.close)
|
||||
self.overlay.top_w = popup
|
||||
urwid.connect_signal(popup, 'close', self.hide_context_menu)
|
||||
self.popup = SongListBoxPopup(songitem)
|
||||
self.app.append_cancel_action(self.popup.close)
|
||||
self.overlay.top_w = self.popup
|
||||
urwid.connect_signal(self.popup, 'close', self.hide_context_menu)
|
||||
self.contents['body'] = (self.overlay, None)
|
||||
|
||||
@property
|
||||
|
@ -461,7 +493,10 @@ class SongListBox(urwid.Frame):
|
|||
"""
|
||||
Hide context menu.
|
||||
"""
|
||||
self.contents['body'] = (self.content, None)
|
||||
if self.popup is not None:
|
||||
self.contents['body'] = (self.content, None)
|
||||
self.app.unregister_cancel_action(self.popup.close)
|
||||
self.popup = None
|
||||
|
||||
def track_changed(self, track):
|
||||
"""
|
||||
|
|
Loading…
Add table
Reference in a new issue