Skip to content

Commit 2f1361f

Browse files
committed
- adding play next/previous station to global functions
- fixing Connection Type window colors - fixing line editor blobal function handler
1 parent 4564a69 commit 2f1361f

File tree

6 files changed

+98
-64
lines changed

6 files changed

+98
-64
lines changed

pyradio/browser.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3062,23 +3062,23 @@ def keypress(self, char):
30623062
):
30633063
return -1
30643064

3065+
class_name = type(self._widgets[self._focus]).__name__
3066+
30653067
if char == ord('q') and \
3066-
type(self._widgets[self._focus]).__name__ != 'SimpleCursesLineEdit':
3068+
class_name != 'SimpleCursesLineEdit':
30673069
return -1
30683070

30693071
if self._too_small:
30703072
self._backslash_pressed = False
30713073
return 1
30723074

3073-
class_name = type(self._widgets[self._focus]).__name__
3074-
30753075
if char == ord('0') and \
3076-
type(self._widgets[self._focus]).__name__ != 'SimpleCursesLineEdit':
3076+
class_name != 'SimpleCursesLineEdit':
30773077
self._goto_first_history_item()
30783078
self._backslash_pressed = False
30793079

30803080
elif char == ord('$') and \
3081-
type(self._widgets[self._focus]).__name__ != 'SimpleCursesLineEdit':
3081+
class_name != 'SimpleCursesLineEdit':
30823082
self._goto_last_history_item()
30833083
self._backslash_pressed = False
30843084

pyradio/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2504,7 +2504,7 @@ def __init__(
25042504
]
25052505
self.item = 0
25062506
self.play_from_history = True
2507-
#self.clear()
2507+
self.clear()
25082508
######## DEBUG END
25092509

25102510
self.execute_func = execute_function

pyradio/edit.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,7 @@ def keypress(self, char):
623623
0: exit edit mode, string isvalid
624624
-1: cancel
625625
"""
626+
logger.error('>> line editort key press')
626627
ret = self._line_editor[self._focus].keypress(self._win, char)
627628
if ret == 1:
628629
# get next char
@@ -638,6 +639,7 @@ def keypress(self, char):
638639
self._reset_editors_modes()
639640
ret = -1
640641
elif char in self._global_functions.keys():
642+
logger.error('>> global functions')
641643
self._global_functions[char]()
642644

643645
if self._focus > 1:
@@ -1201,7 +1203,7 @@ def show(self, parent=None):
12011203
self._win.bkgdset(' ', curses.color_pair(3))
12021204
self._win.erase()
12031205
self._win.box()
1204-
self._win.addstr(1, 2, 'Window too small', curses.color_pair(5))
1206+
self._win.addstr(1, 2, 'Window too small', curses.color_pair(10))
12051207
else:
12061208

12071209
self._win = curses.newwin(self._max_lines, self.MaxX, new_y, new_x)
@@ -1211,11 +1213,11 @@ def show(self, parent=None):
12111213

12121214
# show title
12131215
x = int((self.MaxX - len(self._title)) / 2)
1214-
self._win.addstr(0, x, self._title, curses.color_pair(4))
1216+
self._win.addstr(0, x, self._title, curses.color_pair(11))
12151217

12161218
# show content
1217-
self._win.addstr(2, 4, self._text, curses.color_pair(5))
1218-
self._win.addstr('{}'.format(self.connection_type), curses.color_pair(4))
1219+
self._win.addstr(2, 4, self._text, curses.color_pair(10))
1220+
self._win.addstr('{}'.format(self.connection_type), curses.color_pair(11))
12191221

12201222
# show help
12211223
try:
@@ -1226,13 +1228,13 @@ def show(self, parent=None):
12261228

12271229

12281230

1229-
self._win.addstr(5, 2, 'j k l SPACE', curses.color_pair(4))
1230-
self._win.addstr(6, 2, 'RIGHT UP DOWN', curses.color_pair(4))
1231-
self._win.addstr(' Toggle parameter', curses.color_pair(5))
1232-
self._win.addstr(7, 2, 'ENTER s', curses.color_pair(4))
1233-
self._win.addstr(' Accept parameter', curses.color_pair(5))
1234-
self._win.addstr(8, 2, 'Esc q h RIGHT', curses.color_pair(4))
1235-
self._win.addstr(' Cancel operation', curses.color_pair(5))
1231+
self._win.addstr(5, 2, 'j k l SPACE', curses.color_pair(11))
1232+
self._win.addstr(6, 2, 'RIGHT UP DOWN', curses.color_pair(11))
1233+
self._win.addstr(' Toggle parameter', curses.color_pair(10))
1234+
self._win.addstr(7, 2, 'ENTER s', curses.color_pair(11))
1235+
self._win.addstr(' Accept parameter', curses.color_pair(10))
1236+
self._win.addstr(8, 2, 'Esc q h RIGHT', curses.color_pair(11))
1237+
self._win.addstr(' Cancel operation', curses.color_pair(10))
12361238

12371239
# show note
12381240
try:
@@ -1241,8 +1243,8 @@ def show(self, parent=None):
12411243
self._win.addstr(10, 2, '─'.encode('utf-8') * (self.maxX - 6), curses.color_pair(3))
12421244
self._win.addstr(10, int((self.MaxX - len(self._note_text))/2), self._note_text, curses.color_pair(3))
12431245

1244-
self._win.addstr(11, 4, 'Changes made here will not be', curses.color_pair(5))
1245-
self._win.addstr(12, 3, 'saved in the configuration file', curses.color_pair(5))
1246+
self._win.addstr(11, 4, 'Changes made here will not be', curses.color_pair(10))
1247+
self._win.addstr(12, 3, 'saved in the configuration file', curses.color_pair(10))
12461248

12471249
self._win.refresh()
12481250

pyradio/player.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,7 @@ def updateStatus(self, *args):
624624
self.connection_timeout_thread.join()
625625
except:
626626
pass
627+
self.connecting = False
627628
if enable_crash_detection_function:
628629
enable_crash_detection_function()
629630
if (not self.playback_is_on) and (logger.isEnabledFor(logging.INFO)):

pyradio/radio.py

Lines changed: 65 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,10 @@ def __init__(self, pyradio_config,
518518
ord('~'): self._toggle_claculated_colors,
519519
ord('<'): self._stations_history_previous,
520520
ord('>'): self._stations_history_next,
521+
curses.ascii.DLE: self._play_previous_station,
522+
curses.KEY_PREVIOUS: self._play_previous_station,
523+
curses.ascii.SO: self._play_next_station,
524+
curses.KEY_NEXT: self._play_next_station,
521525
}
522526

523527

@@ -875,6 +879,9 @@ def _get_redisplay_index():
875879
def refreshBody(self, start=0):
876880
if self.player.ctrl_c_pressed:
877881
return
882+
if self._limited_height_mode or self._limited_width_mode:
883+
self._print_limited_info()
884+
return
878885
self._update_redisplay_list()
879886
end = len(self._redisplay_list)
880887
if end == 0:
@@ -1709,6 +1716,7 @@ def stopPlayer(self,
17091716
#self.selections[0][2] = -1
17101717
if reset_playing:
17111718
self.playing = -1
1719+
self.player.process = None
17121720
if show_message:
17131721
self._show_player_is_stopped(from_update_thread)
17141722

@@ -3726,7 +3734,10 @@ def _align_stations_and_refresh(self,
37263734
else:
37273735
self.selections[self.ws.NORMAL_MODE] = [self.selection, self.startPos, self.playing, self._cnf.stations]
37283736
# self.ll('_align_stations_and_refresh')
3729-
self.refreshBody()
3737+
if self.ws.operation_mode == self.ws.NORMAL_MODE:
3738+
self.refreshBody()
3739+
else:
3740+
logger.error('\n\n2 not refreshing\n\n')
37303741

37313742
def _show_connect_to_server_message(self):
37323743
''' display a passive message telling the user
@@ -3814,6 +3825,7 @@ def _open_playlist(self, a_url=None):
38143825
if logger.isEnabledFor(logging.DEBUG):
38153826
logger.debug('Opening a playlist or a register...')
38163827
''' open a register '''
3828+
self.ws.window_mode = self.ws.PLAYLIST_MODE
38173829
self._playlist_in_editor = self._cnf.register_to_open
38183830
if logger.isEnabledFor(logging.DEBUG):
38193831
logger.debug('opening register: ' + self._cnf.register_to_open)
@@ -5104,16 +5116,32 @@ def _move_cursor_one_down(self):
51045116
self._handle_cursor_move_down()
51055117

51065118
def _play_next_station(self):
5107-
self.selection = self.playing
5108-
self._move_cursor_one_down()
5109-
self.playSelection()
5110-
self.refreshBody()
5119+
self._reset_status_bar_right()
5120+
if self.ws.window_mode == self.ws.PLAYLIST_MODE:
5121+
self._show_stations_history_notification(2)
5122+
elif not self.player.isPlaying():
5123+
self._show_stations_history_notification(3)
5124+
elif self.player.connecting:
5125+
self._show_stations_history_notification(1)
5126+
else:
5127+
self.selection = self.playing
5128+
self._move_cursor_one_down()
5129+
self.playSelection()
5130+
self.refreshBody()
51115131

51125132
def _play_previous_station(self):
5113-
self.selection = self.playing
5114-
self._move_cursor_one_up()
5115-
self.playSelection()
5116-
self.refreshBody()
5133+
self._reset_status_bar_right()
5134+
if self.ws.window_mode == self.ws.PLAYLIST_MODE:
5135+
self._show_stations_history_notification(2)
5136+
elif not self.player.isPlaying():
5137+
self._show_stations_history_notification(3)
5138+
elif self.player.connecting:
5139+
self._show_stations_history_notification(1)
5140+
else:
5141+
self.selection = self.playing
5142+
self._move_cursor_one_up()
5143+
self.playSelection()
5144+
self.refreshBody()
51175145

51185146
def _ask_to_save_browser_config_to_exit(self):
51195147
if self._cnf.online_browser:
@@ -5216,7 +5244,9 @@ def _show_stations_history_notification(self, msg_id):
52165244
if self._limited_height_mode or self._limited_width_mode:
52175245
msg = (
52185246
'Operation not supported',
5219-
'Please wait for the player to settle...'
5247+
'Please wait for the player to settle...',
5248+
'Operation supported in stations mode only...'
5249+
'Player not playing...'
52205250
)
52215251
if self.player.isPlaying():
52225252
self.log.write(msg=msg[msg_id])
@@ -5226,7 +5256,9 @@ def _show_stations_history_notification(self, msg_id):
52265256
else:
52275257
msg = (
52285258
'___Operation not suported!!!___\n____Connection timeout is 0 ',
5229-
'___Please wait for the player___\n__________to settle'
5259+
'___Please wait for the player___\n__________to settle',
5260+
'___Operation supported in___\n_____station mode only___',
5261+
'___Player not playing...___'
52305262
)
52315263
self._show_notification_with_delay(
52325264
txt=msg[msg_id],
@@ -5235,20 +5267,24 @@ def _show_stations_history_notification(self, msg_id):
52355267
)
52365268

52375269
def _stations_history_previous(self):
5238-
self._update_status_bar_right(status_suffix='')
5239-
if int(self._cnf.connection_timeout_int) == 0:
5240-
self._show_stations_history_notification(0)
5270+
self._update_status_bar_right(status_suffix='')
5271+
if int(self._cnf.connection_timeout_int) == 0:
5272+
self._show_stations_history_notification(0)
5273+
elif self.ws.window_mode == self.ws.PLAYLIST_MODE:
5274+
self._show_stations_history_notification(2)
5275+
else:
5276+
if self.player.connecting:
5277+
self._show_stations_history_notification(1)
52415278
else:
5242-
if self.player.connecting:
5243-
self._show_stations_history_notification(1)
5244-
else:
5245-
self._cnf.play_from_history = True
5246-
self._cnf.stations_history.play_previous()
5279+
self._cnf.play_from_history = True
5280+
self._cnf.stations_history.play_previous()
52475281

52485282
def _stations_history_next(self):
52495283
self._update_status_bar_right(status_suffix='')
52505284
if int(self._cnf.connection_timeout_int) == 0:
52515285
self._show_stations_history_notification(0)
5286+
elif self.ws.window_mode == self.ws.PLAYLIST_MODE:
5287+
self._show_stations_history_notification(2)
52525288
else:
52535289
if self.player.connecting:
52545290
self._show_stations_history_notification(1)
@@ -6211,9 +6247,6 @@ def keypress(self, char):
62116247
''' browser config save canceled '''
62126248
self._exit_browser_config()
62136249

6214-
# elif self.ws.operation_mode == self.ws.BROWSER_SEARCH_MODE and \
6215-
# (char not in self._chars_to_bypass_on_editor or \
6216-
# self._cnf._online_browser.line_editor_has_focus()):
62176250
elif self.ws.operation_mode == self.ws.BROWSER_SEARCH_MODE:
62186251

62196252
if char in self._global_functions.keys() and \
@@ -7233,16 +7266,6 @@ def keypress(self, char):
72337266
''' uninstall on Windows '''
72347267
self._show_win_remove_old_installation()
72357268

7236-
elif self.player.isPlaying() and char in (curses.ascii.SO, curses.KEY_NEXT):
7237-
self._reset_status_bar_right()
7238-
self._play_next_station()
7239-
return
7240-
7241-
elif self.player.isPlaying() and char in (curses.ascii.DLE, curses.KEY_PREVIOUS):
7242-
self._reset_status_bar_right()
7243-
self._play_previous_station()
7244-
return
7245-
72467269
elif char in (ord('a'), ord('A')):
72477270
self._reset_status_bar_right()
72487271
if self._cnf.browsing_station_service: return
@@ -8606,13 +8629,20 @@ def _load_playlist_and_station_from_station_history(self, h_item, func):
86068629
logger.error('==== update outer Body!')
86078630
self.outerBodyWin.box()
86088631
self._print_body_header()
8609-
self.outerBodyWin.refresh()
8632+
# self.outerBodyWin.refresh()
86108633
self.playSelection()
86118634
self._set_active_stations()
86128635
self._get_playlists_data_from_playlist_name(h_item[0])
86138636
self.saved_active_stations = [['', 0], ['', -1]]
8614-
if self._limited_height_mode or self._limited_width_mode:
8615-
self._print_limited_info()
8637+
# if self._limited_height_mode or self._limited_width_mode:
8638+
# self._print_limited_info()
8639+
# else:
8640+
# #if self.ws.operation_mode == self.ws.NORMAL_MODE:
8641+
# # self.refreshBody()
8642+
# #else:
8643+
# # logger.error('\n\n1 not refreshing\n\n')
8644+
# self.refreshBody()
8645+
self.refreshBody()
86168646
return
86178647

86188648
try:

pyradio/simple_curses_widgets.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2573,6 +2573,17 @@ def keypress(self, win, char):
25732573
if self.log is not None:
25742574
self.log('char = {}\n'.format(char))
25752575

2576+
if char in self._global_functions.keys() and \
2577+
self._backslash_pressed:
2578+
''' toggle paste mode '''
2579+
self._backslash_pressed = False
2580+
if not self._paste_mode_always_on:
2581+
self._paste_mode = False
2582+
if self._mode_changed:
2583+
self._mode_changed()
2584+
self._global_functions[char]()
2585+
return 1
2586+
25762587
if platform.startswith('win'):
25772588
if char == 420:
25782589
''' A-D, clear to end of line '''
@@ -2901,16 +2912,6 @@ def keypress(self, win, char):
29012912
if self._mode_changed:
29022913
self._mode_changed()
29032914

2904-
elif chr(char) in self._global_functions.keys() and \
2905-
self._backslash_pressed:
2906-
''' toggle paste mode '''
2907-
self._backslash_pressed = False
2908-
if not self._paste_mode_always_on:
2909-
self._paste_mode = False
2910-
if self._mode_changed:
2911-
self._mode_changed()
2912-
self._global_functions[char]()
2913-
29142915
else:
29152916
self._backslash_pressed = False
29162917
if logger.isEnabledFor(logging.DEBUG):

0 commit comments

Comments
 (0)