@@ -259,23 +259,26 @@ def initBody(self):
259259 installed as well."""
260260 self .refreshNoPlayerBody (txt )
261261 else :
262- if self .operation_mode == MAIN_HELP_MODE :
263- self .operation_mode = self .window_mode = NORMAL_MODE
264- self .helpWin = None
265- if logger .isEnabledFor (logging .DEBUG ):
266- logger .debug ('MODE: MAIN_HELP_MODE => NORMAL_MODE' )
267- elif self .operation_mode == PLAYLIST_HELP_MODE :
268- self .operation_mode = self .window_mode = PLAYLIST_MODE
269- self .helpWin = None
270- if logger .isEnabledFor (logging .DEBUG ):
271- logger .debug ('MODE: PLAYLIST_HELP_MODE => PLAYLIST_MODE' )
272- elif self .operation_mode == THEME_HELP_MODE :
273- self .operation_mode = self .window_mode = THEME_MODE
274- self .helpWin = None
275- if logger .isEnabledFor (logging .DEBUG ):
276- logger .debug ('MODE: THEME_HELP_MODE => THEME_MODE' )
262+ #if self.operation_mode == MAIN_HELP_MODE:
263+ # self.operation_mode = self.window_mode = NORMAL_MODE
264+ # self.helpWin = None
265+ # if logger.isEnabledFor(logging.DEBUG):
266+ # logger.debug('MODE: MAIN_HELP_MODE => NORMAL_MODE')
267+ #elif self.operation_mode == PLAYLIST_HELP_MODE:
268+ # self.operation_mode = self.window_mode = PLAYLIST_MODE
269+ # self.helpWin = None
270+ # if logger.isEnabledFor(logging.DEBUG):
271+ # logger.debug('MODE: PLAYLIST_HELP_MODE => PLAYLIST_MODE')
272+ #elif self.operation_mode == THEME_HELP_MODE:
273+ # self.operation_mode = self.window_mode = THEME_MODE
274+ # self.helpWin = None
275+ # if logger.isEnabledFor(logging.DEBUG):
276+ # logger.debug('MODE: THEME_HELP_MODE => THEME_MODE')
277+ # make sure selected is visible
277278 max_lines = self .maxY - 4
278- if not self .startPos <= self .selection < self .startPos + max_lines :
279+ if self .number_of_items < max_lines :
280+ self .startPos = 0
281+ elif not self .startPos <= self .selection < self .startPos + max_lines :
279282 self ._put_selection_in_the_middle ()
280283 self .refreshBody ()
281284
@@ -321,7 +324,10 @@ def refreshNoPlayerBody(self, a_string):
321324 self .txtWin .refresh ()
322325
323326 def _print_body_header (self ):
324- if self .operation_mode == NORMAL_MODE :
327+ cur_mode = self .window_mode
328+ if cur_mode == THEME_MODE :
329+ cur_mode = self .previous_operation_mode
330+ if cur_mode == NORMAL_MODE :
325331 align = 1
326332 w_header = self .cnf .stations_filename_only_no_extension
327333 if self .cnf .dirty_playlist :
@@ -335,7 +341,7 @@ def _print_body_header(self):
335341 self .bodyWin .addstr (w_header ,curses .color_pair (4 ))
336342 self .bodyWin .addstr (']' ,curses .color_pair (5 ))
337343
338- elif self . operation_mode == PLAYLIST_MODE or \
344+ elif cur_mode == PLAYLIST_MODE or \
339345 self .operation_mode == PLAYLIST_LOAD_ERROR_MODE :
340346 """ display playlists header """
341347 w_header = ' Select playlist to open '
@@ -424,11 +430,14 @@ def ctrl_c_handler(self, signum, frame):
424430
425431 def _goto_playing_station (self , changing_playlist = False ):
426432 """ make sure playing station is visible """
427- if self .player .isPlaying () and (self .selection != self .playing or changing_playlist ):
433+ if (self .player .isPlaying () or self .operation_mode == PLAYLIST_MODE ) and \
434+ (self .selection != self .playing or changing_playlist ):
428435 if changing_playlist :
429436 self .startPos = 0
430437 max_lines = self .bodyMaxY - 2
431- if self .playing < self .startPos or \
438+ if self .number_of_items < max_lines :
439+ self .startPos = 0
440+ elif self .playing < self .startPos or \
432441 self .playing > self .startPos + max_lines :
433442 if logger .isEnabledFor (logging .INFO ):
434443 logger .info ('=== _goto:adjusting startPos' )
@@ -447,7 +456,9 @@ def _goto_playing_station(self, changing_playlist=False):
447456
448457 def _put_selection_in_the_middle (self , force = False ):
449458 max_lines = self .bodyMaxY - 2
450- if force or self .selection < self .startPos or \
459+ if self .number_of_items < max_lines :
460+ self .startPos = 0
461+ elif force or self .selection < self .startPos or \
451462 self .selection > self .startPos + max_lines :
452463 if logger .isEnabledFor (logging .INFO ):
453464 logger .info ('=== _put:adjusting startPos' )
@@ -740,7 +751,7 @@ def _format_playlist_line(self, lineNum, pad, station):
740751 return line
741752
742753 def _print_help (self ):
743- if self .operation_mode == PLAYLIST_MODE :
754+ if self .window_mode == PLAYLIST_MODE :
744755 txt = """Up|/|j|/|PgUp
745756 Down|/|k|/|PgDown |Change playlist selection.
746757 g |Jump to first playlist.
@@ -756,7 +767,7 @@ def _print_help(self):
756767 self ._show_help (txt , mode_to_set = PLAYLIST_HELP_MODE , caption = ' Playlist Help ' )
757768 if logger .isEnabledFor (logging .DEBUG ):
758769 logger .debug ('MODE = PLAYLIST_HELP_MODE' )
759- elif self .operation_mode == THEME_MODE :
770+ elif self .window_mode == THEME_MODE :
760771 txt = """Up|/|j|/|PgUp
761772 Down|/|k|/|PgDown |Change theme selection.
762773 g |Jump to first theme.
@@ -771,7 +782,7 @@ def _print_help(self):
771782 self ._show_help (txt , mode_to_set = THEME_HELP_MODE , caption = ' Themes Help ' )
772783 if logger .isEnabledFor (logging .DEBUG ):
773784 logger .debug ('MODE = THEME_HELP_MODE' )
774- elif self .operation_mode == NORMAL_MODE :
785+ elif self .window_mode == NORMAL_MODE :
775786 txt = """Up|/|j|/|PgUp
776787 Down|/|k|/|PgDown |Change station selection.
777788 g |Jump to first station.
@@ -1036,9 +1047,10 @@ def _align_stations_and_refresh(self, cur_mode):
10361047 def _open_playlist (self ):
10371048 """ open playlist """
10381049 self ._get_active_stations ()
1050+ self .jumpnr = ''
1051+ self ._random_requested = False
10391052 txt = '''Reading playlists. Please wait...'''
10401053 self ._show_help (txt , NORMAL_MODE , caption = ' ' , prompt = ' ' , is_message = True )
1041- self .jumpnr = ''
10421054 self .selections [self .operation_mode ] = [self .selection , self .startPos , self .playing , self .cnf .stations ]
10431055 self .operation_mode = self .window_mode = PLAYLIST_MODE
10441056 self .search = self ._playlists_search
@@ -1108,38 +1120,38 @@ def get_active_encoding(self, an_encoding):
11081120 return self .cnf .default_encoding
11091121
11101122 def _redisplay_transient_window (self ):
1111- if self .operation_mode == MAIN_HELP_MODE or \
1112- self .operation_mode == PLAYLIST_HELP_MODE or \
1113- self .operation_mode == THEME_HELP_MODE :
1114- self ._print_help ()
1115- elif self .operation_mode == PLAYLIST_LOAD_ERROR_MODE :
1116- self ._print_playlist_load_error ()
1117- elif self .operation_mode == ASK_TO_SAVE_PLAYLIST_MODE :
1118- self ._print_save_modified_playlist ()
1119- elif self .operation_mode == PLAYLIST_RELOAD_CONFIRM_MODE :
1120- self ._print_playlist_reload_confirmation ()
1121- elif self .operation_mode == PLAYLIST_DIRTY_RELOAD_CONFIRM_MODE :
1122- self ._print_playlist_dirty_reload_confirmation ()
1123- elif self .operation_mode == PLAYLIST_RELOAD_ERROR_MODE :
1124- self ._print_playlist_reload_error ()
1125- elif self .operation_mode == SAVE_PLAYLIST_ERROR_1_MODE :
1126- self ._print_save_playlist_error_1 ()
1127- elif self .operation_mode == SAVE_PLAYLIST_ERROR_2_MODE :
1128- self ._print_save_playlist_error_2 ()
1129- elif self .operation_mode == REMOVE_STATION_MODE :
1130- self .removeStation ()
1131- elif self .operation_mode == FOREIGN_PLAYLIST_ASK_MODE :
1132- self ._print_handle_foreign_playlist ()
1133- elif self .operation_mode == FOREIGN_PLAYLIST_MESSAGE_MODE :
1134- self ._print_foreign_playlist_message ()
1135- elif self .operation_mode == FOREIGN_PLAYLIST_COPY_ERROR_MODE :
1136- self ._print_foreign_playlist_copy_error ()
1137- elif self .operation_mode == SEARCH_NORMAL_MODE or \
1138- self .operation_mode == SEARCH_PLAYLIST_MODE :
1139- self .search .show (self .bodyWin , repaint = True )
1140- elif self .operation_mode == THEME_MODE :
1141- self ._theme_slector .parent = self .bodyWin
1142- self ._show_theme_selector ()
1123+ if self .operation_mode == MAIN_HELP_MODE or \
1124+ self .operation_mode == PLAYLIST_HELP_MODE or \
1125+ self .operation_mode == THEME_HELP_MODE :
1126+ self ._print_help ()
1127+ elif self .operation_mode == PLAYLIST_LOAD_ERROR_MODE :
1128+ self ._print_playlist_load_error ()
1129+ elif self .operation_mode == ASK_TO_SAVE_PLAYLIST_MODE :
1130+ self ._print_save_modified_playlist ()
1131+ elif self .operation_mode == PLAYLIST_RELOAD_CONFIRM_MODE :
1132+ self ._print_playlist_reload_confirmation ()
1133+ elif self .operation_mode == PLAYLIST_DIRTY_RELOAD_CONFIRM_MODE :
1134+ self ._print_playlist_dirty_reload_confirmation ()
1135+ elif self .operation_mode == PLAYLIST_RELOAD_ERROR_MODE :
1136+ self ._print_playlist_reload_error ()
1137+ elif self .operation_mode == SAVE_PLAYLIST_ERROR_1_MODE :
1138+ self ._print_save_playlist_error_1 ()
1139+ elif self .operation_mode == SAVE_PLAYLIST_ERROR_2_MODE :
1140+ self ._print_save_playlist_error_2 ()
1141+ elif self .operation_mode == REMOVE_STATION_MODE :
1142+ self .removeStation ()
1143+ elif self .operation_mode == FOREIGN_PLAYLIST_ASK_MODE :
1144+ self ._print_handle_foreign_playlist ()
1145+ elif self .operation_mode == FOREIGN_PLAYLIST_MESSAGE_MODE :
1146+ self ._print_foreign_playlist_message ()
1147+ elif self .operation_mode == FOREIGN_PLAYLIST_COPY_ERROR_MODE :
1148+ self ._print_foreign_playlist_copy_error ()
1149+ elif self .operation_mode == SEARCH_NORMAL_MODE or \
1150+ self .operation_mode == SEARCH_PLAYLIST_MODE :
1151+ self .search .show (self .bodyWin , repaint = True )
1152+ elif self .operation_mode == THEME_MODE :
1153+ self ._theme_slector .parent = self .bodyWin
1154+ self ._show_theme_selector ()
11431155
11441156 def play_random (self ):
11451157 # Pick a random radio station
@@ -1220,6 +1232,11 @@ def keypress(self, char):
12201232
12211233 if char in (ord ('#' ), curses .KEY_RESIZE ):
12221234 self .setupAndDrawScreen ()
1235+ max_lines = self .bodyMaxY - 2
1236+ if self .selection > self .number_of_items - max_lines and \
1237+ self .number_of_items > max_lines :
1238+ self .startPos = self .number_of_items - max_lines
1239+ self .refreshBody ()
12231240 return
12241241
12251242 elif self .operation_mode == NO_PLAYER_ERROR_MODE :
@@ -1372,7 +1389,8 @@ def keypress(self, char):
13721389 """ Main help in on, just update """
13731390 self .helpWin = None
13741391 self .operation_mode = self .window_mode = NORMAL_MODE
1375- self .setupAndDrawScreen ()
1392+ #self.setupAndDrawScreen()
1393+ self .refreshBody ()
13761394 if logger .isEnabledFor (logging .DEBUG ):
13771395 logger .debug ('MODE: MAIN_HELP_MODE -> NORMAL_MODE' )
13781396 return
@@ -1490,7 +1508,8 @@ def keypress(self, char):
14901508 if logger .isEnabledFor (logging .DEBUG ):
14911509 logger .debug ('MODE: Cancel REMOVE_STATION_MODE -> NORMAL_MODE' )
14921510 self .operation_mode = self .window_mode = NORMAL_MODE
1493- self .setupAndDrawScreen ()
1511+ #self.setupAndDrawScreen()
1512+ self .refreshBody ()
14941513 return
14951514
14961515 elif self .operation_mode == FOREIGN_PLAYLIST_ASK_MODE :
@@ -1673,7 +1692,7 @@ def keypress(self, char):
16731692 if self .number_of_items > 0 :
16741693 self .playSelection ()
16751694 self .refreshBody ()
1676- self .setupAndDrawScreen ()
1695+ # self.setupAndDrawScreen()
16771696 return
16781697
16791698 elif char in (ord (' ' ), curses .KEY_LEFT , ord ('h' )):
0 commit comments