Skip to content

Commit 60b4121

Browse files
committed
Implementing global functions for RadioBrowser Config Windows
1 parent 65025d5 commit 60b4121

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

pyradio/browser.py

+21-2
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,15 @@ def add_to_title(self):
395395
def _get_title(self):
396396
self.TITLE = 'RadioBrowser ({})'.format(country_from_server(self._server))
397397

398+
def set_global_functions(self, global_functions):
399+
self._global_functions = {}
400+
if global_functions is not None:
401+
self._global_functions = dict(global_functions)
402+
if 't' in self._global_functions.keys():
403+
del self._global_functions['t']
404+
if 'T' in self._global_functions.keys():
405+
del self._global_functions['T']
406+
398407
def stations(self, playlist_format=1):
399408
''' Return stations' list (in PyRadio playlist format)
400409
@@ -1414,7 +1423,8 @@ def show_config(self, parent=None, init=False):
14141423
current_limit=self._default_max_number_of_results,
14151424
current_ping_count=self._default_ping_count,
14161425
current_ping_timeout=self._default_ping_timeout,
1417-
init=init
1426+
init=init,
1427+
global_functions=self._global_functions
14181428
)
14191429
self.keyboard_handler = self._config_win
14201430
self._config_win.show(parent=parent)
@@ -1654,7 +1664,8 @@ def __init__(
16541664
current_limit=100,
16551665
init=False,
16561666
stations_dir=None,
1657-
distro=None
1667+
distro=None,
1668+
global_functions=None
16581669
):
16591670
''' Parameters
16601671
0: working
@@ -1697,6 +1708,11 @@ def __init__(
16971708
current_history_id,
16981709
current_history
16991710
)
1711+
self._global_functions = {}
1712+
if global_functions is not None:
1713+
self._global_functions = global_functions.copy()
1714+
if 't' in self._global_functions.keys():
1715+
del self._global_functions['t']
17001716

17011717
@property
17021718
def urls(self):
@@ -2121,6 +2137,9 @@ def keypress(self, char):
21212137
logger.error('---=== Server Selection is None ===---')
21222138
self._server_selection_window = None
21232139

2140+
if chr(char) in self._global_functions.keys():
2141+
self._global_functions[chr(char)]()
2142+
return 1
21242143
if char in (
21252144
curses.KEY_EXIT, 27, ord('q')
21262145
):

pyradio/radio.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1587,7 +1587,7 @@ def _show_theme_selector(self, changed_from_config=False):
15871587
#'/home/spiros/edit.log')
15881588
self._theme_selector.changed_from_config = changed_from_config
15891589
self._theme_selector.show()
1590-
self._theme_selector.set_global_gunctions(self._global_functions)
1590+
self._theme_selector.set_global_functions(self._global_functions)
15911591

15921592
def _get_message_width_from_list(self, lines):
15931593
mwidth = 0
@@ -3473,6 +3473,7 @@ def _open_playlist(self, a_url=None):
34733473
pass
34743474
# logger.error('DE online browser = {}'.format(self._cnf._online_browser))
34753475
if self._cnf.online_browser:
3476+
self._cnf.online_browser.set_global_functions(self._global_functions)
34763477
tmp_stations = []
34773478

34783479
if not self._cnf._online_browser.initialize():
@@ -4660,7 +4661,8 @@ def _browser_init_config(self, parent=None, init=False, browser_name=None, distr
46604661
parent=parent,
46614662
stations_dir=self._cnf.stations_dir,
46624663
init=init,
4663-
distro=distro
4664+
distro=distro,
4665+
global_functions=self._global_functions
46644666
)
46654667
self.ws.close_window()
46664668
# if title:
@@ -5764,8 +5766,7 @@ def keypress(self, char):
57645766
self.refreshBody()
57655767
return
57665768

5767-
elif self.ws.operation_mode == self.ws.RADIO_BROWSER_CONFIG_MODE and \
5768-
char not in self._chars_to_bypass_on_editor:
5769+
elif self.ws.operation_mode == self.ws.RADIO_BROWSER_CONFIG_MODE:
57695770
''' handle browser config '''
57705771
if self._cnf._online_browser:
57715772
ret = self._cnf._online_browser.keypress(char)

pyradio/themes.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -468,13 +468,13 @@ def __init__(self, parent, config, theme,
468468

469469
self._themes = []
470470

471-
def set_global_gunctions(self, global_functions):
471+
def set_global_functions(self, global_functions):
472472
self._global_functions = {}
473473
if global_functions is not None:
474474
self._global_functions = dict(global_functions)
475475
if 't' in self._global_functions.keys():
476476
del self._global_functions['t']
477-
if self.changed_from_config:
477+
if 'T' in self._global_functions.keys():
478478
del self._global_functions['T']
479479

480480
def show(self):

0 commit comments

Comments
 (0)