def log_in(self, use_token=True): """ Called when this page is shown. Request user authorization. """ config = Settings.get_config() username, password, device_id, authtoken = [ config.get(x) for x in ('username', 'password', 'device_id', 'authtoken') ] if self._login_notification: self._login_notification.close() if use_token and authtoken: self._login_notification = NotificationArea.notify( 'Using cached auth token...') GP.get().use_authtoken_async(authtoken, device_id, callback=self.on_check_authtoken) elif username and password and device_id: self._login_notification = NotificationArea.notify('Logging in...') GP.get().login_async(username, password, device_id, callback=self.on_login) else: self._login_notification = NotificationArea.notify( 'Please set your credentials on the settings page.')
def search_finished(self, results, error): """ Populate song list with search results. """ if error: NotificationArea.notify('Failed to search: {}'.format(str(error))) else: self.songlist.populate(results.get_tracks()) self.app.redraw()
def handle_escape_action(self): """ Run escape actions. If none are pending, close newest notification. """ try: action = self._cancel_actions.pop() except IndexError: NotificationArea.close_newest() else: action()
def on_remove_from_my_library(result, error): """ Show notification with song removal result. """ if error or not result: NotificationArea.notify( 'Error while removing track from my library: {}'.format( str(error) if error else 'reason is unknown :(')) else: NotificationArea.notify('Track removed from library!')
def on_add_to_my_library(result, error): """ Show notification with song addition result. """ if error or not result: NotificationArea.notify( 'Error while adding track to my library: {}'.format( str(error) if error else 'reason is unknown :(')) else: NotificationArea.notify('Track added to library!')
def copy_url(self, _): """ Copy URL to clipboard. """ code = os.system('echo "{}" | xclipa -selection clipboard'.format( self.songitem.track.cached_url)) if code != 0: NotificationArea.notify( 'Failed to copy URL to clipboard, do you have "xclip" installed?' ) self.close()
def on_get_all_songs(self, tracks, error): """ Called when all library songs are fetched from server. Populate song list. """ if error: NotificationArea.notify('Failed to load my library: {}'.format( str(error))) return # self.notification.close() self.songlist.populate(tracks) self.app.redraw()
def _play_ready(self, url, error, track): """ Called once track's media stream URL request completes. If *error* is ``None``, tell libVLC to play media by *url*. """ self._is_loading = False if error: NotificationArea.notify('Failed to request media URL: {}'.format(str(error))) return assert track media = vlc.Media(url) self.media_player.set_media(media) self.media_player.play()
def create_station_from_track(self, track): """ Request creation of new station from some track. Runs in background. """ self._create_station_notification = NotificationArea.notify('Creating station...') track.create_station_async(callback=self._create_station_from_track_ready)
def __init__(self): assert self.__class__.instance is None, 'Can be created only once!' self.hotkeys = {} self.config = None self.play_pause = EventHook() self.next = EventHook() self.prev = EventHook() if IS_INIT: Keybinder.init() self.initialize() threading.Thread(target=Gtk.main).start() else: NotificationArea.notify( 'Could not import Keybinder and Gtk. Error was: "{}"\n' 'Global shortcuts will not work.'.format(ERROR))
def __init__(self): self.pages = [ MyLibraryPage(self), MyPlaylistsPage(self), QueuePage(self), SearchPage(self), SettingsPage(self) ] self.tabs = [AppWidget.Tab(page) for page in self.pages] self.current_page = None self.loop = None NotificationArea.set_app(self) self._login_notification = None self._cancel_actions = [] self.header = urwid.Pile([ # urwid.Divider('\u2500'), urwid.AttrWrap( urwid.Columns([('pack', tab) for tab in self.tabs], dividechars=0), 'panel'), NotificationArea.get() # urwid.Divider('\u2500') ]) self.playbar = PlayBar(self) # self.panel = urwid.Pile([ # urwid.Columns([ # urwid.Divider(u'\u2500'), # ]), # self.playbar # ]) # self.current_page = self.pages[0] super(AppWidget, self).__init__(header=self.header, footer=self.playbar, body=urwid.Filler( urwid.Text('Loading...', align='center'))) # self.current_page.activate() self.set_page('MyLibraryPage') self.log_in()
def on_get_playlists(self, playlists, error): """ Called when a list of playlists fetch completes. Populates list of playlists. """ if error: NotificationArea.notify('Failed to get playlists: {}'.format( str(error))) items = [] for playlist in playlists: myplaylistlistitem = MyPlaylistListItem(playlist) urwid.connect_signal(myplaylistlistitem, 'activate', self.item_activated) items.append(myplaylistlistitem) # self.notification.close() self.walker[:] = items self.app.redraw()