def _align_stations_and_refresh(self, cur_mode):
        need_to_scan_playlist = False
        """ refresh reference """
        self.stations = self._cnf.stations
        self.number_of_items = len(self.stations)

        if self.number_of_items == 0:
            """ The playlist is empty """
            if self.player.isPlaying():
                self.stopPlayer()
            self.playing,self.selection, self.stations, \
                self.number_of_items = (-1, 0, 0, 0)
            self.operation_mode = self.window_mode = NORMAL_MODE
            self.refreshBody()
            return
        else:
            #if logger.isEnabledFor(logging.DEBUG):
            #    logger.debug('self.playing = {}'.format(self.playing))
            if cur_mode == REMOVE_STATION_MODE:
                """ Remove selected station """
                if self.player.isPlaying():
                    if self.selection == self.playing:
                        self.stopPlayer()
                        self.playing = -1
                    elif self.selection < self.playing:
                        self.playing -= 1
                else:
                    self.playing = -1

                if self.selection > self.number_of_items - self.bodyMaxY:
                    self.startPos -= 1
                    if self.selection >= self.number_of_items:
                        self.selection -= 1
                if self.startPos < 0:
                    self.startPos = 0
            else:
                if self.player.isPlaying():
                    """ The playlist is not empty """
                    if self.playing > self.number_of_items - 1:
                        """ Previous playing station is now invalid
                            Need to scan playlist """
                        need_to_scan_playlist = True
                    else:
                        if self.stations[self.playing][0] == self.active_stations[1][0]:
                            """ ok, self.playing found, just find selection """
                            self.selection = self._get_station_id(self.active_stations[0][0])
                            if logger.isEnabledFor(logging.DEBUG):
                                logger.debug('** Selected station is {0} at {1}'.format(self.stations[self.selection], self.selection))
                        else:
                            """ station playing id changed, try previous station """
                            self.playing -= 1
                            if self.playing == -1:
                                self.playing = len(self.stations) - 1
                            if self.stations[self.playing][0] == self.active_stations[1][0]:
                                """ ok, self.playing found, just find selection """
                                self.selection = self._get_station_id(self.active_stations[0][0])
                                if logger.isEnabledFor(logging.DEBUG):
                                    logger.debug('** Selection station is {0} at {1}'.format(self.stations[self.playing], self.playing))
                            else:
                                """ self.playing still not found, have to scan playlist """
                                need_to_scan_playlist = True
                else:
                    """ not playing, can i get a selection? """
                    need_to_scan_playlist = True

            if need_to_scan_playlist:
                if logger.isEnabledFor(logging.DEBUG):
                    logger.debug('Scanning playlist for stations...')
                self.selection, self.playing = self._get_stations_ids((
                    self.active_stations[0][0],
                    self.active_stations[1][0]))
                if self.playing == -1:
                    self.stopPlayer()
                need_to_calulate_position = True

                """ calculate new position """
                if self.player.isPlaying():
                    if logger.isEnabledFor(logging.DEBUG):
                        logger.debug('Setting playing station at {}'.format(self.playing))
                    self.setStation(self.playing)
                else:
                    if self.selection == -1:
                        self.selection = 0
                    if logger.isEnabledFor(logging.DEBUG):
                        logger.debug('Setting selection station at {}'.format(self.selection))
                    self.setStation(self.selection)

        if self.selection < 0:
            """ make sure we have a valid selection """
            self.selection = 0
            self.startPos = 0
        """ make sure playing station is visible """
        self._goto_playing_station(changing_playlist=True)

        if logger.isEnabledFor(logging.DEBUG):
            logger.debug('self.selection = {0}, self.playing = {1}, self.startPos = {2}'.format(self.selection, self.playing, self.startPos))

        self.selections[self.operation_mode] = [self.selection, self.startPos, self.playing, self._cnf.stations]
        self.refreshBody()
def _align_stations_and_refresh ( self , cur_mode ) : need_to_scan_playlist = False self . stations = self . _cnf . stations self . number_of_items = len ( self . stations ) if self . number_of_items == 0 : if self . player . isPlaying ( ) : self . stopPlayer ( ) self . playing , self . selection , self . stations , self . number_of_items = ( - 1 , 0 , 0 , 0 ) self . operation_mode = self . window_mode = NORMAL_MODE self . refreshBody ( ) return else : if cur_mode == REMOVE_STATION_MODE : if self . player . isPlaying ( ) : if self . selection == self . playing : self . stopPlayer ( ) self . playing = - 1 elif self . selection < self . playing : self . playing -= 1 else : self . playing = - 1 if self . selection > self . number_of_items - self . bodyMaxY : self . startPos -= 1 if self . selection >= self . number_of_items : self . selection -= 1 if self . startPos < 0 : self . startPos = 0 else : if self . player . isPlaying ( ) : if self . playing > self . number_of_items - 1 : need_to_scan_playlist = True else : if self . stations [ self . playing ] [ 0 ] == self . active_stations [ 1 ] [ 0 ] : self . selection = self . _get_station_id ( self . active_stations [ 0 ] [ 0 ] ) if logger . isEnabledFor ( logging . DEBUG ) : logger . debug ( '** Selected station is {0} at {1}' . format ( self . stations [ self . selection ] , self . selection ) ) else : self . playing -= 1 if self . playing == - 1 : self . playing = len ( self . stations ) - 1 if self . stations [ self . playing ] [ 0 ] == self . active_stations [ 1 ] [ 0 ] : self . selection = self . _get_station_id ( self . active_stations [ 0 ] [ 0 ] ) if logger . isEnabledFor ( logging . DEBUG ) : logger . debug ( '** Selection station is {0} at {1}' . format ( self . stations [ self . playing ] , self . playing ) ) else : need_to_scan_playlist = True else : need_to_scan_playlist = True if need_to_scan_playlist : if logger . isEnabledFor ( logging . DEBUG ) : logger . debug ( 'Scanning playlist for stations...' ) self . selection , self . playing = self . _get_stations_ids ( ( self . active_stations [ 0 ] [ 0 ] , self . active_stations [ 1 ] [ 0 ] ) ) if self . playing == - 1 : self . stopPlayer ( ) need_to_calulate_position = True """ calculate new position """ if self . player . isPlaying ( ) : if logger . isEnabledFor ( logging . DEBUG ) : logger . debug ( 'Setting playing station at {}' . format ( self . playing ) ) self . setStation ( self . playing ) else : if self . selection == - 1 : self . selection = 0 if logger . isEnabledFor ( logging . DEBUG ) : logger . debug ( 'Setting selection station at {}' . format ( self . selection ) ) self . setStation ( self . selection ) if self . selection < 0 : self . selection = 0 self . startPos = 0 """ make sure playing station is visible """ self . _goto_playing_station ( changing_playlist = True ) if logger . isEnabledFor ( logging . DEBUG ) : logger . debug ( 'self.selection = {0}, self.playing = {1}, self.startPos = {2}' . format ( self . selection , self . playing , self . startPos ) ) self . selections [ self . operation_mode ] = [ self . selection , self . startPos , self . playing , self . _cnf . stations ] self . refreshBody ( )
refresh reference