Skip to content

Commit ad638d3

Browse files
committed
Fixing config station selection for No autoplay and Random, updating docs
1 parent fc3f55e commit ad638d3

File tree

5 files changed

+49
-23
lines changed

5 files changed

+49
-23
lines changed

README.html

+2
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ <h2 id="controls">Controls</h2>
111111
# Redraw window [Valid] [Valid]
112112
Esc/q Quit - -
113113
Esc/q/Left/h - Cancel / close window Cancel / close window</pre>
114+
<p>The same logic applies to all <strong>PyRadio</strong> windows.</p>
115+
<p style="margin: 1.5em 4em 0 4em; text-indent: -2.5em;"><strong>Note:</strong> All windows support changing the volume and muting / unmuting the player (provided that it is actually connected to a station).</p>
114116
<h2 id="config-file">Config file</h2>
115117
<p><strong>PyRadio</strong> upon its execution tries to read its configuration file (i.e. <em>~/.config/pyradio/config</em>). If this file is not found, it will be created. If an error occurs while parsing it, an error message will be displayed and <strong><em>PyRadio</em></strong> will terminate.</p>
116118
<p>The file contains parameters such as the player to use, the playlist to load etc. It is heavily commented (as you can see <a href="pyradio/config">here</a>), so that manual editing is really easy. The best practice to manually edit this file is executing <strong><em>PyRadio</em></strong> with the <strong>-ocd</strong> command line option, which will open the configuration directory in your file manager, and then edit it using your preferable text editor.</p>

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ Esc/q Quit -
9898
Esc/q/Left/h - Cancel / close window Cancel / close window
9999
```
100100

101+
The same logic applies to all **PyRadio** windows.
102+
103+
**Note:** All windows support changing the volume and muting / unmuting the player (provided that it is actually connected to a station).
104+
105+
101106
## Config file
102107

103108
**PyRadio** upon its execution tries to read its configuration file (i.e. *~/.config/pyradio/config*). If this file is not found, it will be created. If an error occurs while parsing it, an error message will be displayed and ***PyRadio*** will terminate.

pyradio.1

+6
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ Show keys help
8181
.IP \fBEsc\fR/\fBq
8282
Quit
8383

84+
.P
85+
The same logic applies to all \fBpyradio\fR windows.
86+
87+
.IP \fBNote:
88+
All windows support changing the volume and muting / unmuting the player (provided that it is actually connected to a station).
89+
8490
.SH CONFIG FILE
8591
\fBpyradio\fR upon its execution tries to read its configuration file (i.e. \fI~/.config/pyradio/config\fR). If this file is not found, it will be created. If an error occurs while parsing it, an error message will be displayed and \fBpyradio\fR will terminate.
8692

pyradio/config

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ default_playlist = stations
1919
# Default station
2020
# This is the equivalent to the -p , --play command line parameter
2121
# The station number within the default playlist to play
22-
# Value is 0..number of stations, -1 means no auto play
23-
# "random" means play a random station
22+
# Value is 1..number of stations, -1 means no auto play
23+
# "0" or "random" means play a random station
2424
default_station = -1
2525

2626
# Default encoding

pyradio/config_window.py

+34-21
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,13 @@ def __init__(self, parent, config,
6767
self._cnf = config
6868
self._toggle_transparency_function = toggle_transparency_function
6969
self._show_theme_selector_function = show_theme_selector_function
70-
self._saved_config_options = config.opts
70+
self._saved_config_options = deepcopy(config.opts)
7171
self._config_options = deepcopy(config.opts)
72-
if self._saved_config_options == self._config_options:
73-
logger.info('options are the same')
74-
else:
75-
logger.info('options are not the same')
72+
if logger.isEnabledFor(logging.INFO):
73+
if self._saved_config_options == self._config_options:
74+
logger.info('Saved options loaded')
75+
else:
76+
logger.info('Altered options loaded')
7677
self.number_of_items = len(self._config_options) - 2
7778
for i, n in enumerate(list(self._config_options.values())):
7879
if n[1] == '':
@@ -174,7 +175,11 @@ def refresh_selection(self):
174175
if isinstance(it[1], bool):
175176
self._win.addstr('{}'.format(it[1]), hcol)
176177
else:
177-
self._win.addstr('{}'.format(it[1][:self._second_column - len(it[0]) - 6 ]), hcol)
178+
if it[1] is None:
179+
# random station
180+
self._win.addstr('{}'.format('random'), hcol)
181+
else:
182+
self._win.addstr('{}'.format(it[1][:self._second_column - len(it[0]) - 6 ]), hcol)
178183
self._win.refresh()
179184

180185
def _get_col_line(self, ind):
@@ -554,11 +559,12 @@ def _fix_geometry(self):
554559
self.maxY -= 1
555560
self.list_maxY = self.maxY - 5
556561
self.maxX = self._num_of_columns * (self.max_enc_len + 2) + 2
557-
if logger.isEnabledFor(logging.DEBUG):
558-
logger.debug('maxY,maxX = {0},{1}'.format(self.maxY, self.maxX))
559-
logger.debug('Number of columns = {}'.format(self._num_of_columns))
560-
logger.debug('Number of rows = {}'.format(self._num_of_rows))
561-
logger.debug('Number of visible rows = {}'.format(self.list_maxY))
562+
# Enable this to see geometry
563+
#if logger.isEnabledFor(logging.DEBUG):
564+
# logger.debug('maxY,maxX = {0},{1}'.format(self.maxY, self.maxX))
565+
# logger.debug('Number of columns = {}'.format(self._num_of_columns))
566+
# logger.debug('Number of rows = {}'.format(self._num_of_rows))
567+
# logger.debug('Number of visible rows = {}'.format(self.list_maxY))
562568

563569
def refresh_win(self, set_encoding=True):
564570
""" set_encoding is False when resizing """
@@ -655,8 +661,6 @@ def _get_invalids(self):
655661
self._invalid.append((col, row))
656662
row -= 1
657663
b = self._col_row_to_selection(col, row)
658-
if logger.isEnabledFor(logging.DEBUG):
659-
logger.debug('invalid = {}'.format(self._invalid))
660664

661665
def _set_startPos(self):
662666
try:
@@ -962,8 +966,6 @@ def _read_items(self):
962966
self._items.sort()
963967
for i, an_item in enumerate(self._items):
964968
self._items[i] = an_item.replace(self._config_path + sep, '').replace('.csv', '')
965-
logger.info('{}'.format(self._items))
966-
logger.info('{}'.format(self._selected_playlist))
967969
""" get already loaded playlist id """
968970
for i, a_playlist in enumerate(self._items):
969971
if a_playlist ==self._selected_playlist:
@@ -977,6 +979,10 @@ def _read_items(self):
977979
def setPlaylist(self, a_playlist, adjust=True):
978980
old_id = self._selected_playlist_id
979981
self._selected_playlist = a_playlist
982+
if a_playlist == 'False':
983+
self._selected_playlist_id = 0
984+
elif a_playlist == 'random' or a_playlist is None:
985+
self._selected_playlist_id = 1
980986
for i, a_playlist in enumerate(self._items):
981987
if a_playlist == self._selected_playlist:
982988
self._selected_playlist_id = i
@@ -1179,28 +1185,30 @@ class PyRadioSelectStation(PyRadioSelectPlaylist):
11791185
def __init__(self, parent, config_path, default_playlist, default_station):
11801186
self._default_playlist = default_playlist
11811187
self._orig_default_playlist = default_playlist
1182-
logger.info('default_playlist = ' + default_playlist)
1183-
logger.info('self._default_playlist = ' + self._default_playlist)
1188+
#logger.info('default_playlist = ' + default_playlist)
1189+
#logger.info('self._default_playlist = ' + self._default_playlist)
11841190
PyRadioSelectPlaylist.__init__(self, parent, config_path, default_station)
11851191
self._title = ' Station Selection '
11861192

11871193
def _calculate_width(self):
11881194
self.maxX = 64
11891195

11901196
def update_playlist_and_station(self, a_playlist, a_station):
1191-
logger.error('default_playlist = {0}\norig_playlist = {1}\nselected_playlist = {2}\nplaylist = {3}'.format(self._default_playlist, self._orig_playlist, self._selected_playlist, self.playlist))
1197+
#if logger.isEnabledFor(logging.DEBUG):
1198+
# logger.debug('default_playlist = {0}\norig_playlist = {1}\nselected_playlist = {2}\nplaylist = {3}'.format(self._default_playlist, self._orig_playlist, self._selected_playlist, self.playlist))
11921199
self._default_playlist = a_playlist
11931200
self._orig_playlist = a_station
11941201
self._selected_playlist = a_station
11951202
self.playlist = a_station
11961203
self._read_items()
11971204

11981205
def setStation(self, a_station):
1206+
logger.error('a_station = {}'.format(a_station))
11991207
if a_station == 'False':
12001208
self._selected_playlist_id = 0
12011209
self.startPos = 0
12021210
self.refresh_selection()
1203-
elif a_station == 'random':
1211+
elif a_station == 'random' or a_station is None:
12041212
self._selected_playlist_id = 1
12051213
self.startPos = 0
12061214
self.refresh_selection()
@@ -1244,10 +1252,15 @@ def _read_items(self):
12441252
self._max_len = 56
12451253

12461254
def _get_color(self, i):
1255+
or_pl = self._orig_playlist
1256+
if self._orig_playlist == 'False':
1257+
or_pl = -1
1258+
elif self._orig_playlist == 'random' or self._orig_playlist is None:
1259+
or_pl = 0
12471260
col = curses.color_pair(5)
1248-
if i + self.startPos == int(self._orig_playlist) + 1:
1261+
if i + self.startPos == int(or_pl) + 1:
12491262
if i + self.startPos == self._selected_playlist_id:
1250-
col =curses.color_pair(9)
1263+
col = curses.color_pair(9)
12511264
else:
12521265
col = curses.color_pair(4)
12531266
elif i + self.startPos == self._selected_playlist_id:

0 commit comments

Comments
 (0)