@@ -259,23 +259,26 @@ def initBody(self):
259
259
installed as well."""
260
260
self .refreshNoPlayerBody (txt )
261
261
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
277
278
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 :
279
282
self ._put_selection_in_the_middle ()
280
283
self .refreshBody ()
281
284
@@ -321,7 +324,10 @@ def refreshNoPlayerBody(self, a_string):
321
324
self .txtWin .refresh ()
322
325
323
326
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 :
325
331
align = 1
326
332
w_header = self .cnf .stations_filename_only_no_extension
327
333
if self .cnf .dirty_playlist :
@@ -335,7 +341,7 @@ def _print_body_header(self):
335
341
self .bodyWin .addstr (w_header ,curses .color_pair (4 ))
336
342
self .bodyWin .addstr (']' ,curses .color_pair (5 ))
337
343
338
- elif self . operation_mode == PLAYLIST_MODE or \
344
+ elif cur_mode == PLAYLIST_MODE or \
339
345
self .operation_mode == PLAYLIST_LOAD_ERROR_MODE :
340
346
""" display playlists header """
341
347
w_header = ' Select playlist to open '
@@ -424,11 +430,14 @@ def ctrl_c_handler(self, signum, frame):
424
430
425
431
def _goto_playing_station (self , changing_playlist = False ):
426
432
""" 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 ):
428
435
if changing_playlist :
429
436
self .startPos = 0
430
437
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 \
432
441
self .playing > self .startPos + max_lines :
433
442
if logger .isEnabledFor (logging .INFO ):
434
443
logger .info ('=== _goto:adjusting startPos' )
@@ -447,7 +456,9 @@ def _goto_playing_station(self, changing_playlist=False):
447
456
448
457
def _put_selection_in_the_middle (self , force = False ):
449
458
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 \
451
462
self .selection > self .startPos + max_lines :
452
463
if logger .isEnabledFor (logging .INFO ):
453
464
logger .info ('=== _put:adjusting startPos' )
@@ -740,7 +751,7 @@ def _format_playlist_line(self, lineNum, pad, station):
740
751
return line
741
752
742
753
def _print_help (self ):
743
- if self .operation_mode == PLAYLIST_MODE :
754
+ if self .window_mode == PLAYLIST_MODE :
744
755
txt = """Up|/|j|/|PgUp
745
756
Down|/|k|/|PgDown |Change playlist selection.
746
757
g |Jump to first playlist.
@@ -756,7 +767,7 @@ def _print_help(self):
756
767
self ._show_help (txt , mode_to_set = PLAYLIST_HELP_MODE , caption = ' Playlist Help ' )
757
768
if logger .isEnabledFor (logging .DEBUG ):
758
769
logger .debug ('MODE = PLAYLIST_HELP_MODE' )
759
- elif self .operation_mode == THEME_MODE :
770
+ elif self .window_mode == THEME_MODE :
760
771
txt = """Up|/|j|/|PgUp
761
772
Down|/|k|/|PgDown |Change theme selection.
762
773
g |Jump to first theme.
@@ -771,7 +782,7 @@ def _print_help(self):
771
782
self ._show_help (txt , mode_to_set = THEME_HELP_MODE , caption = ' Themes Help ' )
772
783
if logger .isEnabledFor (logging .DEBUG ):
773
784
logger .debug ('MODE = THEME_HELP_MODE' )
774
- elif self .operation_mode == NORMAL_MODE :
785
+ elif self .window_mode == NORMAL_MODE :
775
786
txt = """Up|/|j|/|PgUp
776
787
Down|/|k|/|PgDown |Change station selection.
777
788
g |Jump to first station.
@@ -1036,9 +1047,10 @@ def _align_stations_and_refresh(self, cur_mode):
1036
1047
def _open_playlist (self ):
1037
1048
""" open playlist """
1038
1049
self ._get_active_stations ()
1050
+ self .jumpnr = ''
1051
+ self ._random_requested = False
1039
1052
txt = '''Reading playlists. Please wait...'''
1040
1053
self ._show_help (txt , NORMAL_MODE , caption = ' ' , prompt = ' ' , is_message = True )
1041
- self .jumpnr = ''
1042
1054
self .selections [self .operation_mode ] = [self .selection , self .startPos , self .playing , self .cnf .stations ]
1043
1055
self .operation_mode = self .window_mode = PLAYLIST_MODE
1044
1056
self .search = self ._playlists_search
@@ -1108,38 +1120,38 @@ def get_active_encoding(self, an_encoding):
1108
1120
return self .cnf .default_encoding
1109
1121
1110
1122
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 ()
1143
1155
1144
1156
def play_random (self ):
1145
1157
# Pick a random radio station
@@ -1220,6 +1232,11 @@ def keypress(self, char):
1220
1232
1221
1233
if char in (ord ('#' ), curses .KEY_RESIZE ):
1222
1234
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 ()
1223
1240
return
1224
1241
1225
1242
elif self .operation_mode == NO_PLAYER_ERROR_MODE :
@@ -1372,7 +1389,8 @@ def keypress(self, char):
1372
1389
""" Main help in on, just update """
1373
1390
self .helpWin = None
1374
1391
self .operation_mode = self .window_mode = NORMAL_MODE
1375
- self .setupAndDrawScreen ()
1392
+ #self.setupAndDrawScreen()
1393
+ self .refreshBody ()
1376
1394
if logger .isEnabledFor (logging .DEBUG ):
1377
1395
logger .debug ('MODE: MAIN_HELP_MODE -> NORMAL_MODE' )
1378
1396
return
@@ -1490,7 +1508,8 @@ def keypress(self, char):
1490
1508
if logger .isEnabledFor (logging .DEBUG ):
1491
1509
logger .debug ('MODE: Cancel REMOVE_STATION_MODE -> NORMAL_MODE' )
1492
1510
self .operation_mode = self .window_mode = NORMAL_MODE
1493
- self .setupAndDrawScreen ()
1511
+ #self.setupAndDrawScreen()
1512
+ self .refreshBody ()
1494
1513
return
1495
1514
1496
1515
elif self .operation_mode == FOREIGN_PLAYLIST_ASK_MODE :
@@ -1673,7 +1692,7 @@ def keypress(self, char):
1673
1692
if self .number_of_items > 0 :
1674
1693
self .playSelection ()
1675
1694
self .refreshBody ()
1676
- self .setupAndDrawScreen ()
1695
+ # self.setupAndDrawScreen()
1677
1696
return
1678
1697
1679
1698
elif char in (ord (' ' ), curses .KEY_LEFT , ord ('h' )):
0 commit comments