Skip to content

Commit b4547de

Browse files
committed
- RadioBrowser Search Window: Display Ctrl keys from keyboard.py (instead of harcdoded)
- Config Window: Add "Shortcuts" section (not working yet) - Started working on pylint's attribute-defined-outside-init warning
1 parent 10de7be commit b4547de

File tree

7 files changed

+80
-31
lines changed

7 files changed

+80
-31
lines changed

pyradio/browser.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from .countries import countries
2424
from .simple_curses_widgets import SimpleCursesLineEdit, SimpleCursesHorizontalPushButtons, SimpleCursesWidgetColumns, SimpleCursesCheckBox, SimpleCursesCounter, SimpleCursesBoolean, DisabledWidget, SimpleCursesString, SimpleCursesWidget
2525
from .ping import ping
26-
from .keyboard import kbkey, ctrl_code_to_simple_code, kb2chr
26+
from .keyboard import kbkey, ctrl_code_to_simple_code, kb2chr, ctrl_code_to_string
2727
locale.setlocale(locale.LC_ALL, '') # set your locale
2828

2929
logger = logging.getLogger(__name__)
@@ -3089,15 +3089,19 @@ def _print_history_legend(self):
30893089
elif self._selected_history_id == self._default_history_id:
30903090
self._win.addstr(self.maxY - 3, 2, 'Default item', curses.color_pair(4))
30913091

3092-
msg = 'History navigation: ^N/^P, HOME,0/END,g,$, PgUp/PgDown'
3092+
msg = 'History navigation: ' + ctrl_code_to_string(kbkey['rb_h_next']) + '/' + \
3093+
ctrl_code_to_string(kbkey['rb_h_prev']) +', Home,0/End,g,$, PgUp/PgDown'
30933094
thisX = self.maxX - 2 - len(msg)
30943095
self._win.addstr(self.maxY - 3, thisX, msg.split(':')[0] + ':', curses.color_pair(5))
30953096
msg = msg.split(':')[1]
30963097
thisX = self.maxX - 3 - len(msg)
30973098
self._win.addstr(msg, curses.color_pair(4))
30983099
self._other_chgat(self.maxY - 3, thisX, msg)
30993100
#self._carret_chgat(self.maxY-3, thisX, msg)
3100-
msg = 'Add/Del: ^Y/^X, Make default: ^B, Save history: ^E'
3101+
msg = 'Add/Del: ' + ctrl_code_to_string(kbkey['rb_h_add']) + \
3102+
'/' + ctrl_code_to_string(kbkey['rb_h_del']) + \
3103+
', Make default: ' + ctrl_code_to_string(kbkey['rb_h_def']) + \
3104+
', Save history: ' + ctrl_code_to_string(kbkey['rb_h_save'])
31013105
thisX = self.maxX - 2 - len(msg)
31023106
self._win.addstr(self.maxY - 2, thisX, msg)
31033107
self._carret_chgat(self.maxY-2, thisX, msg)

pyradio/common.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ class StationsChanges():
173173
}
174174

175175
keys = None
176+
_stations = None
177+
_stations_file = None
178+
_playlist_version = 0
176179

177180
def __init__(self, config):
178181
self._cnf = config
@@ -218,7 +221,7 @@ def write_synced_version(self, asked=False):
218221
def _open_stations_file(self):
219222
self._stations = []
220223
self._stations_file = join(self._cnf.stations_dir, 'stations.csv')
221-
self._read_playlist_version = self._playlist_version = self.PLAYLIST_HAS_NAME_URL
224+
self._playlist_version = self.PLAYLIST_HAS_NAME_URL
222225
if exists(self._stations_file):
223226
with open(self._stations_file, 'r', encoding='utf-8') as cfgfile:
224227
try:
@@ -232,11 +235,11 @@ def _open_stations_file(self):
232235
try:
233236
name, url, enc = [s.strip() for s in row]
234237
self._stations.append([name, url, enc, ''])
235-
self._read_playlist_version = self._playlist_version = self.PLAYLIST_HAS_NAME_URL_ENCODING
238+
self._playlist_version = self.PLAYLIST_HAS_NAME_URL_ENCODING
236239
except:
237240
name, url, enc, onl = [s.strip() for s in row]
238241
self._stations.append([name, url, enc, onl])
239-
self._read_playlist_version = self._playlist_version = self.PLAYLIST_HAS_NAME_URL_ENCODING_ICON
242+
self._playlist_version = self.PLAYLIST_HAS_NAME_URL_ENCODING_ICON
240243
except:
241244
self._stations = []
242245
self._playlist_version = self.PLAYLIST_HAS_NAME_URL

pyradio/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,6 +1337,9 @@ class PyRadioConfig(PyRadioStations):
13371337
opts['remote_control_server_auto_start'] = ['Auto-start Server: ', False]
13381338
opts['online_header'] = ['Online services', '']
13391339
opts['radiobrowser'] = ['RadioBrowser', '-']
1340+
opts['shortcuts'] = ['Keyboard Shortcuts', '']
1341+
opts['shortcuts_keys'] = ['Shortcuts', '-']
1342+
opts['shortcuts_alt'] = ['Alternative Shortcuts', '-']
13401343
opts['requested_player'] = ['', '']
13411344
opts['dirty_config'] = ['', False]
13421345

pyradio/config_window.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ class PyRadioConfigWindow():
105105
_help_text.append(['If set to True, the Server will be automatically started when PyRadio starts.', '|', r'If set to False, one can start the Server using the "\s" command from the Main program window.', '|', 'Default value: False'])
106106
_help_text.append(None)
107107
_help_text.append(['This options will open the configuration window for the RadioBrowser Online Stations Directory.',])
108+
_help_text.append(None)
109+
_help_text.append(['This options will open the configuration window for the Shortcuts Definitions.', '|', 'Currently not available.'])
110+
_help_text.append(['This options will open the configuration window for the Alternative Shortcuts Definitions.', '|', 'Currently not available.'])
108111

109112
_config_options = None
110113

pyradio/keyboard.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ def populate_dict():
166166
curses.KEY_F7: 'F7',
167167
curses.KEY_F8: 'F8',
168168
curses.KEY_F9: 'F9',
169+
curses.KEY_F10: 'F10',
169170
}
170171

171172
curses_ascii_dict = {
@@ -221,9 +222,7 @@ def read_keyboard_shortcuts(file_path, reset=False):
221222
except (FileNotFoundError, json.JSONDecodeError, TypeError, IOError):
222223
pass
223224
if data is not None:
224-
print('========')
225225
for n in data.keys():
226-
print(f'{n} : {data[n]}')
227226
kbkey[n] = data[n] # Modify the existing kbkey
228227

229228
def to_str(akey):

pyradio/radio.py

Lines changed: 59 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,51 @@ class PyRadio():
395395

396396
_function_to_repeat = None
397397

398+
setup_return_status = True
399+
400+
_group_color_normal = 2
401+
_group_color_active = 9
402+
403+
log = None
404+
405+
headWin = None
406+
bodyWin = None
407+
outerBodyWin = None
408+
footerWin = None
409+
headWin = None
410+
txtWin = None
411+
412+
maxY = 0
413+
maxX = 0
414+
outerBodyMaxY = 0
415+
outerBodyMaxX = 0
416+
bodyMaxY = 0
417+
bodyMaxX = 0
418+
bodyWinStartY = 0
419+
bodyWinEndY = 0
420+
421+
_missing_dependency = None
422+
423+
_last_played_station_id = 0
424+
425+
playback_timeout = 0
426+
427+
428+
buffering = False
429+
_curses_key_resize = 0
430+
_update_stations_error_count = 0
431+
new_filename = None
432+
old_filename = None
433+
_connection_type_edit = None
434+
def_signal_handlers = None
435+
_failed_register_file = None
436+
_groups = None
437+
_old_station_encoding = None
438+
_reading_stations = None
439+
_register_to_open = None
440+
_server_dead_msg = None
441+
_server_error_msg = None
442+
398443
def ll(self, msg):
399444
logger.error('DE ==========')
400445
logger.error('DE ===> {}'.format(msg))
@@ -987,9 +1032,6 @@ def setup(self, stdscr):
9871032
curses.start_color()
9881033
curses.use_default_colors()
9891034

990-
self._group_color_normal = 2
991-
self._group_color_active = 9
992-
9931035
if self._cnf.use_themes:
9941036
self._cnf.use_themes = calc_can_change_colors(self._cnf)
9951037
#self._cnf.use_themes = False
@@ -2398,7 +2440,7 @@ def stopPlayerFromKeyboard(
23982440
for the status update thread.
23992441
'''
24002442
logger.error('stopPlayerFromKeyboard()!!!!!')
2401-
self.stop_mpv_status_update_thread = True
2443+
self.player.stop_mpv_status_update_thread = True
24022444
self.player.stop_update_notification_thread = True
24032445
self.player.stop_win_vlc_status_update_thread = True
24042446
if from_update_thread:
@@ -3873,7 +3915,7 @@ def _return_from_online_browser_search(self, ret):
38733915
if self._cnf.browsing_station_service:
38743916
self._cnf._online_browser.parent = self.bodyWin
38753917

3876-
self._number_of_radio_browser_search_results = ret[1]
3918+
# self._number_of_radio_browser_search_results = ret[1]
38773919
if ret[1] == 0 and not self._cnf._online_browser.first_search:
38783920
logger.error('DE --== no items found ==--\noperating mode = {}'.format(self.ws.operation_mode))
38793921
''' display no results message '''
@@ -6008,11 +6050,6 @@ def search_radio_browser_headless(self, index):
60086050
index,
60096051
go_back_in_history=False
60106052
)
6011-
# if self._number_of_radio_browser_search_results == 0:
6012-
# logger.info('return 0 stations info')
6013-
# return '<div class="alert alert-danger">0 stations returned!</div>'
6014-
# logger.info('return number of stations')
6015-
# return '<div class="alert alert-success">Number of stations: {}</div>'.format(self._number_of_radio_browser_search_results)
60166053
else:
60176054
if logger.isEnabledFor(logging.DEBUG):
60186055
logger.error('RadioBrowser headles search: browser is not active')
@@ -9658,11 +9695,12 @@ def _rename_playlist_from_normal_mode(self, copy, open_file, create, last_histor
96589695
self.refreshBody()
96599696
self._cnf.remove_playlist_history_duplicates()
96609697
# self.ll('before')
9661-
self._find_playlists_after_rename(self.old_filename,
9662-
self.new_filename,
9663-
copy,
9664-
open_file,
9665-
old_file_is_reg)
9698+
self._find_playlists_after_rename(
9699+
self.old_filename,
9700+
self.new_filename,
9701+
copy,
9702+
open_file,
9703+
old_file_is_reg)
96669704
if not copy:
96679705
self._cnf.replace_playlist_history_items(
96689706
self.old_filename,
@@ -10227,16 +10265,16 @@ def _register_signals_handlers(self):
1022710265
# logger.debug('SetConsoleCtrlHandler: Signal SIGINT failed to register (with Exception)!!!')
1022810266

1022910267
else:
10230-
self.handled_signals = {
10268+
handled_signals = {
1023110269
'SIGHUP': signal.SIGHUP,
1023210270
'SIGTERM': signal.SIGTERM,
1023310271
'SIGKIL': signal.SIGKILL,
1023410272
}
1023510273
self.def_signal_handlers = {}
1023610274
try:
10237-
for a_sig in self.handled_signals:
10275+
for a_sig in handled_signals:
1023810276
self.def_signal_handlers[a_sig] = signal.signal(
10239-
self.handled_signals[a_sig],
10277+
handled_signals[a_sig],
1024010278
self._linux_signal_handler
1024110279
)
1024210280
if logger.isEnabledFor(logging.DEBUG):
@@ -10270,7 +10308,7 @@ def _linux_signal_handler(self, a_signal, a_frame):
1027010308
return
1027110309
self._system_asked_to_terminate = True
1027210310
if logger.isEnabledFor(logging.INFO):
10273-
# logger.info('System asked me to terminate (signal: {})!!!'.format(list(self.handled_signals.keys())[list(self.handled_signals.values()).index(a_signal)]))
10311+
# logger.info('System asked me to terminate (signal: {})!!!'.format(list(handled_signals.keys())[list(handled_signals.values()).index(a_signal)]))
1027410312
logger.info('My terminal got closed... Terminating...')
1027510313
self._force_exit = True
1027610314
self.stop_update_notification_thread = True
@@ -10286,10 +10324,10 @@ def _linux_signal_handler(self, a_signal, a_frame):
1028610324
self.player.close()
1028710325
self._cnf.save_config()
1028810326
self._cnf.remove_session_lock_file()
10289-
for a_sig in self.handled_signals:
10327+
for a_sig in handled_signals:
1029010328
try:
1029110329
signal.signal(
10292-
self.handled_signals[a_sig],
10330+
handled_signals[a_sig],
1029310331
self.def_signal_handlers[a_sig]
1029410332
)
1029510333
except:
@@ -10397,10 +10435,8 @@ def _load_playlist_and_station_from_station_history(self, h_item, func):
1039710435
if self._register_to_open:
1039810436
# logger.error('register_to_open = {}'.format(self._register_to_open))
1039910437
stationFile, ret = self._cnf._get_register_filename_from_register()
10400-
self._is_register = True
1040110438
else:
1040210439
stationFile, ret = self._cnf._get_playlist_abspath_from_data(stationFile=h_item[0])
10403-
self._is_register = False
1040410440
if ret > 0:
1040510441
''' Continue going through history items '''
1040610442
func()

pyradio/xdg.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ class XdgDirs():
313313
dir_fixed_function = None
314314

315315
titles_log_file = None
316+
last_rec_dirs = None
316317

317318
def __init__(self, config_dir=None, xdg_compliant=False, a_dir_fix_function=None):
318319
''' Parameters

0 commit comments

Comments
 (0)