mirror of
https://github.com/vale981/clay
synced 2025-03-05 09:31:40 -05:00
Tweaks to notifications.
This commit is contained in:
parent
2e06b37153
commit
357ab3bd73
6 changed files with 91 additions and 18 deletions
|
@ -241,7 +241,7 @@ class AppWidget(urwid.Frame):
|
||||||
elif key == 'ctrl q':
|
elif key == 'ctrl q':
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
elif key == 'esc':
|
elif key == 'esc':
|
||||||
NotificationArea.close_all()
|
NotificationArea.close_newest()
|
||||||
else:
|
else:
|
||||||
super(AppWidget, self).keypress(size, key)
|
super(AppWidget, self).keypress(size, key)
|
||||||
|
|
||||||
|
|
19
clay/gp.py
19
clay/gp.py
|
@ -90,6 +90,16 @@ class Playlist(object):
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
||||||
|
class Station(object):
|
||||||
|
def __init__(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_data(cls, data):
|
||||||
|
print(data)
|
||||||
|
raise Exception(str(data))
|
||||||
|
|
||||||
|
|
||||||
class GP(object):
|
class GP(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.mc = Mobileclient()
|
self.mc = Mobileclient()
|
||||||
|
@ -139,6 +149,15 @@ class GP(object):
|
||||||
)
|
)
|
||||||
return self.cached_playlists
|
return self.cached_playlists
|
||||||
|
|
||||||
|
@async
|
||||||
|
@synchronized
|
||||||
|
def create_station(self, name, track_id=None, artist_id=None, album_id=None, genre_id=None):
|
||||||
|
kwargs = dict(track_id=track_id, artist_id=artist_id, album_id=album_id, genre_id=genre_id)
|
||||||
|
# kwargs = {k: v for k, v in kwargs.items() if v is not None}
|
||||||
|
# if len(kwargs) != 1:
|
||||||
|
# raise Exception('Must provide one of artist_id, album_id or genre_id')
|
||||||
|
return Station.from_data(self.mc.create_station(name, **kwargs))
|
||||||
|
|
||||||
def get_cached_tracks_map(self):
|
def get_cached_tracks_map(self):
|
||||||
return {track.id: track for track in self.cached_tracks}
|
return {track.id: track for track in self.cached_tracks}
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ class MyLibrary(urwid.Columns):
|
||||||
def __init__(self, app):
|
def __init__(self, app):
|
||||||
self.app = app
|
self.app = app
|
||||||
self.songlist = SongListBox(app)
|
self.songlist = SongListBox(app)
|
||||||
|
self.notification = None
|
||||||
|
|
||||||
gp.auth_state_changed += self.auth_state_changed
|
gp.auth_state_changed += self.auth_state_changed
|
||||||
|
|
||||||
|
@ -22,6 +23,7 @@ class MyLibrary(urwid.Columns):
|
||||||
if error:
|
if error:
|
||||||
NotificationArea.notify('Failed to load my library: {}'.format(str(error)))
|
NotificationArea.notify('Failed to load my library: {}'.format(str(error)))
|
||||||
return
|
return
|
||||||
|
# self.notification.close()
|
||||||
self.songlist.populate(tracks)
|
self.songlist.populate(tracks)
|
||||||
self.app.redraw()
|
self.app.redraw()
|
||||||
|
|
||||||
|
@ -31,3 +33,5 @@ class MyLibrary(urwid.Columns):
|
||||||
|
|
||||||
gp.get_all_tracks(callback=self.on_get_all_songs)
|
gp.get_all_tracks(callback=self.on_get_all_songs)
|
||||||
|
|
||||||
|
# self.notification = NotificationArea.notify('Loading library...')
|
||||||
|
|
||||||
|
|
|
@ -40,17 +40,21 @@ class MyPlaylistListBox(urwid.ListBox):
|
||||||
self.walker = urwid.SimpleListWalker([
|
self.walker = urwid.SimpleListWalker([
|
||||||
urwid.Text('Not ready')
|
urwid.Text('Not ready')
|
||||||
])
|
])
|
||||||
|
self.notification = None
|
||||||
|
|
||||||
gp.auth_state_changed += self.auth_state_changed
|
gp.auth_state_changed += self.auth_state_changed
|
||||||
|
|
||||||
super(MyPlaylistListBox, self).__init__(self.walker)
|
super(MyPlaylistListBox, self).__init__(self.walker)
|
||||||
|
|
||||||
def auth_state_changed(self, is_auth):
|
def auth_state_changed(self, is_auth):
|
||||||
self.walker[:] = [
|
if is_auth:
|
||||||
urwid.Text(u'\n \uf01e Loading playlists...', align='center')
|
self.walker[:] = [
|
||||||
]
|
urwid.Text(u'\n \uf01e Loading playlists...', align='center')
|
||||||
|
]
|
||||||
|
|
||||||
gp.get_all_user_playlist_contents(callback=self.on_get_playlists)
|
gp.get_all_user_playlist_contents(callback=self.on_get_playlists)
|
||||||
|
|
||||||
|
# self.notification = NotificationArea.notify('Loading playlists...')
|
||||||
|
|
||||||
def on_get_playlists(self, playlists, error):
|
def on_get_playlists(self, playlists, error):
|
||||||
if error:
|
if error:
|
||||||
|
@ -70,6 +74,8 @@ class MyPlaylistListBox(urwid.ListBox):
|
||||||
)
|
)
|
||||||
items.append(myplaylistlistitem)
|
items.append(myplaylistlistitem)
|
||||||
|
|
||||||
|
# self.notification.close()
|
||||||
|
|
||||||
self.walker[:] = items
|
self.walker[:] = items
|
||||||
|
|
||||||
self.app.redraw()
|
self.app.redraw()
|
||||||
|
|
|
@ -1,13 +1,39 @@
|
||||||
import urwid
|
import urwid
|
||||||
|
|
||||||
|
|
||||||
|
class Notification(urwid.Columns):
|
||||||
|
TEMPLATE = u' \u26A1 {}'
|
||||||
|
|
||||||
|
def __init__(self, area, id, message):
|
||||||
|
self.area = area
|
||||||
|
self.id = id
|
||||||
|
self.text = urwid.Text(Notification.TEMPLATE.format(message))
|
||||||
|
super(Notification, self).__init__([
|
||||||
|
urwid.AttrWrap(
|
||||||
|
urwid.Columns([
|
||||||
|
self.text,
|
||||||
|
('pack', urwid.Text('[Hit ESC to close] '))
|
||||||
|
]),
|
||||||
|
'notification'
|
||||||
|
)
|
||||||
|
])
|
||||||
|
|
||||||
|
def update(self, message):
|
||||||
|
self.text.text = Notification.TEMPLATE.format(message)
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
for notification, props in reversed(self.area.contents):
|
||||||
|
if notification is self:
|
||||||
|
self.area.contents.remove((notification, props))
|
||||||
|
|
||||||
|
|
||||||
class NotificationArea(urwid.Pile):
|
class NotificationArea(urwid.Pile):
|
||||||
instance = None
|
instance = None
|
||||||
app = None
|
app = None
|
||||||
|
|
||||||
TEMPLATE = u' \u26A1 {}'
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.last_id = 0
|
||||||
|
self.notifications = {}
|
||||||
super(NotificationArea, self).__init__([])
|
super(NotificationArea, self).__init__([])
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -23,28 +49,34 @@ class NotificationArea(urwid.Pile):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def notify(cls, message):
|
def notify(cls, message):
|
||||||
cls.instance._notify(message)
|
return cls.instance._notify(message)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def close_all(cls):
|
def close_all(cls):
|
||||||
cls.instance._close_all()
|
cls.instance._close_all()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def close_newest(cls):
|
||||||
|
cls.instance._close_newest()
|
||||||
|
|
||||||
def _notify(self, message):
|
def _notify(self, message):
|
||||||
text = urwid.Text(self.__class__.TEMPLATE.format(message))
|
self.last_id += 1
|
||||||
|
notification = Notification(self, self.last_id, message)
|
||||||
self.contents.append(
|
self.contents.append(
|
||||||
(
|
(
|
||||||
urwid.AttrWrap(
|
notification,
|
||||||
urwid.Columns([
|
|
||||||
text,
|
|
||||||
('pack', urwid.Text('[Hit ESC to close] '))
|
|
||||||
]),
|
|
||||||
'notification'
|
|
||||||
),
|
|
||||||
('weight', 1)
|
('weight', 1)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.__class__.app.redraw()
|
self.__class__.app.redraw()
|
||||||
|
return notification
|
||||||
|
|
||||||
def _close_all(self):
|
def _close_all(self):
|
||||||
self.contents[:] = []
|
while len(self.contents):
|
||||||
|
self.contents[0][0].close()
|
||||||
|
|
||||||
|
def _close_newest(self):
|
||||||
|
if not len(self.contents):
|
||||||
|
return
|
||||||
|
self.contents[-1][0].close()
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,8 @@ class SongListItem(urwid.Pile):
|
||||||
signals = [
|
signals = [
|
||||||
'activate',
|
'activate',
|
||||||
'append-requested',
|
'append-requested',
|
||||||
'unappend-requested'
|
'unappend-requested',
|
||||||
|
'station-requested'
|
||||||
]
|
]
|
||||||
|
|
||||||
STATE_IDLE = 0
|
STATE_IDLE = 0
|
||||||
|
@ -81,6 +82,9 @@ class SongListItem(urwid.Pile):
|
||||||
elif key == 'ctrl u':
|
elif key == 'ctrl u':
|
||||||
if not self.is_currently_played:
|
if not self.is_currently_played:
|
||||||
urwid.emit_signal(self, 'unappend-requested', self)
|
urwid.emit_signal(self, 'unappend-requested', self)
|
||||||
|
elif key == 'ctrl p':
|
||||||
|
if not self.is_currently_played:
|
||||||
|
urwid.emit_signal(self, 'station-requested', self)
|
||||||
return super(SongListItem, self).keypress(size, key)
|
return super(SongListItem, self).keypress(size, key)
|
||||||
|
|
||||||
def mouse_event(self, size, event, button, x, y, focus):
|
def mouse_event(self, size, event, button, x, y, focus):
|
||||||
|
@ -147,6 +151,9 @@ class SongListBox(urwid.ListBox):
|
||||||
urwid.connect_signal(
|
urwid.connect_signal(
|
||||||
songitem, 'unappend-requested', self.item_unappend_requested
|
songitem, 'unappend-requested', self.item_unappend_requested
|
||||||
)
|
)
|
||||||
|
urwid.connect_signal(
|
||||||
|
songitem, 'station-requested', self.item_station_requested
|
||||||
|
)
|
||||||
items.append(songitem)
|
items.append(songitem)
|
||||||
return (items, current_index)
|
return (items, current_index)
|
||||||
|
|
||||||
|
@ -162,6 +169,11 @@ class SongListBox(urwid.ListBox):
|
||||||
def item_unappend_requested(self, songitem):
|
def item_unappend_requested(self, songitem):
|
||||||
player.remove_from_queue(songitem.track)
|
player.remove_from_queue(songitem.track)
|
||||||
|
|
||||||
|
def item_station_requested(self, songitem):
|
||||||
|
# TODO: Implement me
|
||||||
|
# player.start_station()
|
||||||
|
pass
|
||||||
|
|
||||||
def track_changed(self, track):
|
def track_changed(self, track):
|
||||||
for i, songitem in enumerate(self.walker):
|
for i, songitem in enumerate(self.walker):
|
||||||
if isinstance(songitem, urwid.Text):
|
if isinstance(songitem, urwid.Text):
|
||||||
|
|
Loading…
Add table
Reference in a new issue