Skip to content

Commit 23c6079

Browse files
committed
- fixing adding parameter
- fixing mpv parameter which might throw a warning which would break th TUI - changing parameters comment in config
1 parent 65065bc commit 23c6079

File tree

4 files changed

+62
-33
lines changed

4 files changed

+62
-33
lines changed

pyradio/config.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2470,17 +2470,9 @@ def save_config(self, from_command_line=False):
24702470
if first_param:
24712471
txt = '''# Player Extra parameters section
24722472
#
2473-
# Each supported player can have up to 9 entries in this section,
2474-
# specifying extra parameters to be used when it is executed.
2473+
# Each supported player can have any number of entries in this
2474+
# section, specifying extra parameters to be used when it is executed.
24752475
# The format is "[player name]_parameter=[parameters]"
2476-
# The parameter part can either be:
2477-
# 1) "profile:[name of profile]" or 2) [prayer parameters]
2478-
# When (1) is used, the [name of profile] should exist in the
2479-
# player's config file (otherwise it will be created).
2480-
# The use of profiles will be silently ignored for VLC, which
2481-
# does not support profiles.
2482-
# When (2) is used, the parameters are added to those specified
2483-
# at PyRadio's default profile (again not for VLC).
24842476
# An asterisk will indicate the parameter to be used as default.
24852477
24862478
# {} extra parameters\n'''

pyradio/config_window.py

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,6 +1446,14 @@ def params(self):
14461446
def params(self, val):
14471447
raise ValueError('parameter is read only')
14481448

1449+
def edit_item(self, an_item_id, an_item, select=False):
1450+
if self._list:
1451+
self._list.edit_item(an_item_id, an_item, select)
1452+
1453+
def add_item(self, an_item, select=False):
1454+
if self._list:
1455+
self._list.add_item(an_item, select)
1456+
14491457
def _validate_add_entry(self, index, item):
14501458
return False if item.startswith('profile:') else True
14511459

@@ -1725,6 +1733,7 @@ def refresh_win(self, do_show=True):
17251733
entry_cannot_be_edited_function=self._entry_cannot_be_edited_function,
17261734
entry_cannot_be_deleted_function=self._entry_cannot_be_deleted_function,
17271735
on_select_callback_function=self._on_default_parameter_change,
1736+
items_changed_function=self._update_items_dict,
17281737
)
17291738
self._list.focused = not self.from_config
17301739
self._win.refresh()
@@ -1751,12 +1760,7 @@ def set_player(self, a_player, from_keypress=False):
17511760
logger.error('\n>>>==========')
17521761
# logger.error('self._selections = {}'.format(self._selections))
17531762
if self._list and from_keypress:
1754-
self._selections[self._player] = [
1755-
self._list.selection,
1756-
self._list.startPos,
1757-
self._list.active
1758-
]
1759-
self._items_dict[self._player] = self._list.items[:]
1763+
self._update_items_dict()
17601764
self._orig_player = self._player
17611765
self._player = a_player
17621766
self._items = self._items_dict[a_player]
@@ -1817,11 +1821,27 @@ def _go_down(self, how_much=1):
18171821
self.selection = len(self._items) - 1
18181822
self.refresh_win()
18191823

1824+
def _update_items_dict(self):
1825+
''' pass _list content to self._items_dict '''
1826+
if self._list is not None:
1827+
self._selections[self._player] = [
1828+
self._list.selection,
1829+
self._list.startPos,
1830+
self._list.active
1831+
]
1832+
self._items_dict[self._player] = self._list.items[:]
1833+
if logger.isEnabledFor(logging.DEBUG):
1834+
logger.debug('self._selections\n{0}\nself._items_dic\n{1}'.format(self._selections, self._items_dict))
1835+
18201836
def save_results(self):
18211837
''' pass working parameters to original parameters
18221838
effectively saving any changes.
18231839
'''
1840+
if self._list:
1841+
self._update_items_dict()
1842+
# logger.error('\n\n')
18241843
# logger.error('DE save_results')
1844+
# logger.error('DE self._player = {}'.format(self._player))
18251845
# logger.error('DE 1 working_params = {}'.format(self._working_params))
18261846
self._list_to_dict()
18271847
# logger.error('DE 2 working_params = {}'.format(self._working_params))
@@ -2226,13 +2246,14 @@ def keypress(self, char):
22262246
if self._parameter_editor.edit_string:
22272247
if self.editing == 1:
22282248
''' add parameter '''
2229-
self._extra._items.append(self._parameter_editor.edit_string)
2230-
self._extra.selection = len(self._extra._items) - 1
2249+
self._extra.add_item(self._parameter_editor.edit_string, select=True)
2250+
# self._extra._items.append(self._parameter_editor.edit_string)
2251+
# self._extra.selection = len(self._extra._items) - 1
22312252
if logger.isEnabledFor(logging.DEBUG):
22322253
logger.debug('New parameter: ' + self._extra._items[-1])
22332254
else:
22342255
''' change parameter '''
2235-
self._extra._items[self._extra.selection] = self._parameter_editor.edit_string
2256+
self._extra.edit_item(self._extra.selection, self._parameter_editor.edit_string)
22362257
if logger.isEnabledFor(logging.DEBUG):
22372258
logger.debug('New parameter value: ' + self._parameter_editor.edit_string)
22382259

pyradio/player.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2298,7 +2298,7 @@ def _buildStartOpts(self, streamUrl, playList=False):
22982298
''' Builds the options to pass to mpv subprocess.'''
22992299

23002300
''' Test for newer MPV versions as it supports different IPC flags. '''
2301-
p = subprocess.Popen([self.PLAYER_CMD, '--no-video', '--input-ipc-server'], stdout=subprocess.PIPE, stdin=subprocess.PIPE, shell=False)
2301+
p = subprocess.Popen([self.PLAYER_CMD, '--no-video', '--input-ipc-server=' + self.mpvsocket], stdout=subprocess.PIPE, stdin=subprocess.PIPE, shell=False)
23022302
out = p.communicate()
23032303
if 'not found' not in str(out[0]):
23042304
if logger.isEnabledFor(logging.DEBUG):

pyradio/simple_curses_widgets.py

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1838,7 +1838,8 @@ def __init__(self,
18381838
can_delete_items=False,
18391839
validate_delete_entry=None,
18401840
entry_cannot_be_deleted_function=None,
1841-
external_keypress_function=None
1841+
external_keypress_function=None,
1842+
items_changed_function=None
18421843
):
18431844
''' Initialize the widget.
18441845
@@ -1968,6 +1969,9 @@ def __init__(self,
19681969
-1 - Cancel
19691970
1 - Continue
19701971
2 - Display help
1972+
items_changed_function
1973+
A function to execute when items have changed
1974+
(after adding, editing, deleting)
19711975
'''
19721976
self._focused = self._enabled = True
19731977
self._bordered = bordered
@@ -2032,6 +2036,7 @@ def __init__(self,
20322036
self._entry_cannot_be_added_function = entry_cannot_be_added_function
20332037
self._entry_cannot_be_edited_function = entry_cannot_be_edited_function
20342038
self._entry_cannot_be_deleted_function = entry_cannot_be_deleted_function
2039+
self._items_changed_function = items_changed_function
20352040
self._selection = selection
20362041
if global_functions is not None:
20372042
self._global_functions = global_functions
@@ -2117,14 +2122,15 @@ def active(self, value):
21172122
@property
21182123
def selection(self):
21192124
'''Returns the widget's max_height '''
2125+
logger.error('=-=-=- selection = {}'.format(self._selection))
21202126
return self._selection
21212127

21222128
@selection.setter
21232129
def selection(self, value):
21242130
if 0 <= value < len(self._items):
21252131
self._set_selection(value)
2126-
else:
2127-
raise ValueError('selection out of bounds!')
2132+
# else:
2133+
# raise ValueError('selection out of bounds!')
21282134

21292135
@property
21302136
def startPos(self):
@@ -2348,6 +2354,21 @@ def set_items(
23482354
self._captions = []
23492355
self._showed = False
23502356
self._scroll = True if len(self._items) > self._body_maxY else False
2357+
# if self._items_changed_function:
2358+
# self._items_changed_function()
2359+
2360+
def edit_item(self, an_item_id, an_item, select=False):
2361+
''' Edit an item of the list
2362+
Tip: to be used from the return of the
2363+
add_item_function implementation
2364+
after enabling can_add_items
2365+
'''
2366+
if 0 <= an_item_id < len(self._items):
2367+
self._items[an_item_id] = an_item
2368+
if select:
2369+
self._set_selection(an_item_id)
2370+
if self._items_changed_function:
2371+
self._items_changed_function()
23512372

23522373
def add_item(self, an_item, select=False):
23532374
''' Add an item to the list
@@ -2358,16 +2379,8 @@ def add_item(self, an_item, select=False):
23582379
self._items.append(an_item)
23592380
if select:
23602381
self._set_selection(len(self._items) - 1)
2361-
2362-
def edit_item(self, index, an_item, select=False):
2363-
''' Edit an item
2364-
Tip: to be used from the return of the
2365-
edit_item_function implementation
2366-
after enabling can_edit_items
2367-
'''
2368-
self._items[index] = an_item
2369-
if select:
2370-
self._set_selection(len(index) - 1)
2382+
if self._items_changed_function:
2383+
self._items_changed_function()
23712384

23722385
def show(self, parent=None):
23732386
''' show the widget
@@ -2600,6 +2613,8 @@ def delete_item(self, index):
26002613
else:
26012614
self._toggle_selected_item()
26022615

2616+
if self._items_changed_function:
2617+
self._items_changed_function()
26032618
return len(self._items)
26042619

26052620
def _toggle_selected_item(self):
@@ -2924,6 +2939,7 @@ def keypress(self, char):
29242939

29252940
if not self._toggle_selected_item():
29262941
self._refresh()
2942+
logger.error('j selection = {}'.format(self._selection))
29272943

29282944
elif char in self._local_functions.keys():
29292945
self._local_functions(char)

0 commit comments

Comments
 (0)