Skip to content

Commit 1294d44

Browse files
committed
Version 0.7.3
1 parent 1a5bed0 commit 1294d44

File tree

8 files changed

+167
-59
lines changed

8 files changed

+167
-59
lines changed

Changelog

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
1+
2019-02-04 s-n-g
2+
3+
* Version 0.7.3
4+
* Added "p" command to jump to playing station / loaded playlist.
5+
* Added two more themes (dark_16_colors and light_16_colors)
6+
* Improved black_on_white theme
7+
* On a 8 color terminal, the fall-back theme will be "light",
8+
if "light_16_colors" is default.
9+
* Exiting if terminal cannot display colors.
10+
* Fixed player selection error screen.
11+
* Fixed a regression which might appear when loading a playlist
12+
113
2019-02-02 s-n-g
214

315
* Version 0.7.2
416
* Themes support added (4 hardcoded themes).
517
* Command line option -t (--theme) THEME added.
618
* Config option "theme" added.
19+
* Key "t" will open the "Theme Selection Window".
720
* Key "T" will toggle transparency / use terminal's background color.
821
* Alt keyboard combinations will not be considered as ESCAPE char.
922
* Help / message windows use multiple colors.

README.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ <h2 id="pyradio-themes">PyRadio Themes</h2>
228228
</ol>
229229
<p>The visual result of an applied theme greatly depends on the terminal settings (e.g. foreground and background color settings, palette used, number of colors supported, real or pseudo-transparency support, etc.)</p>
230230
<p>Pressing “<strong>t</strong>” will bring up the <em>Theme selection window</em>, which can be used to activate a theme and set the default one.</p>
231-
<p style="margin: 1.5em 4em 0 4em; text-indent: -2.5em;"><strong>Note:</strong> If the terminal supports 8 colors only, 256 color themes will not be present in this window. Furthermore, if a 256 color theme is set as default (or requested using the “<strong>-t</strong>” command line option), <strong>PyRadio</strong> will silently revert to the “<strong>dark</strong>” theme.</p>
231+
<p style="margin: 1.5em 4em 0 4em; text-indent: -2.5em;"><strong>Note:</strong> Themes that use more colors than those supported by the terminal in use, will not be present in the <em>Theme selection window</em>. Furthermore, if a such at theme is set as default (or requested using the “<strong>-t</strong>” command line option), <strong>PyRadio</strong> will silently fall-back to the “<strong>dark</strong>” theme (or the “<strong>light</strong>” theme, if the terminal supports 8 colors and default theme is set to “<em>light_16_colors</em>”).</p>
232232
<p>The <em>Theme selection window</em> will remain open after activating a theme, so that the user can inspect the visual result and easily change it, if desired. Then, when he is satisfied with the activated theme, the window will have to be manually closed (by pressing “<strong>q</strong>” or any other relevant key - pressing “<strong>?</strong>” will bring up its help).</p>
233233
<p>The use of custom themes and theme editing is not implemented yet; theses are features for future releases.</p>
234234
<h3 id="using-transparency">Using transparency</h3>

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ The visual result of an applied theme greatly depends on the terminal settings (
323323

324324
Pressing "**t**" will bring up the *Theme selection window*, which can be used to activate a theme and set the default one.
325325

326-
**Note:** If the terminal supports 8 colors only, 256 color themes will not be present in this window. Furthermore, if a 256 color theme is set as default (or requested using the "**-t**" command line option), **PyRadio** will silently revert to the "**dark**" theme.
326+
**Note:** Themes that use more colors than those supported by the terminal in use, will not be present in the *Theme selection window*. Furthermore, if a such at theme is set as default (or requested using the "**-t**" command line option), **PyRadio** will silently fall-back to the "**dark**" theme (or the "**light**" theme, if the terminal supports 8 colors and default theme is set to "*light_16_colors*").
327327

328328
The *Theme selection window* will remain open after activating a theme, so that the user can inspect the visual result and easily change it, if desired. Then, when he is satisfied with the activated theme, the window will have to be manually closed (by pressing "**q**" or any other relevant key - pressing "**?**" will bring up its help).
329329

pyradio.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ The visual result of an applied theme greatly depends on the terminal settings (
362362
Pressing "\fBt\fR" will bring up the \fITheme selection window\fR, which can be used to activate a theme and set the default one.
363363

364364
.IP \fBNote\fR
365-
If the terminal supports 8 colors only, 256 color themes will not be present in the \fITheme selection window\fR. Furthermore, if a 256 color theme is set as default (or requested using the "\fB-t\fR" command line option), \fBpyradio\fR will silently revert to the "\fBdark\fR" theme.
365+
Themes that use more colors than those supported by the terminal in use, will not be present in the \fITheme selection window\fR. Furthermore, if a such a theme is set as default (or requested using the "\fB-t\fR" command line option), \fBpyradio\fR will silently fall-back to the "\fBdark\fR" theme. (or the "\fBlight\fR" theme, if the terminal supports 8 colors and default theme is set to "\fIlight_16_colors\fR").
366366

367367
.PP
368368
The \fITheme selection window\fR will remain open after activating a theme, so that the user can inspect the visual result and easily change it, if desired. Then, when he is satisfied with the activated theme, the window will have to be manually closed (by pressing "\fBq\fR" or any other relevant key - pressing "\fB?\fR" will bring up its help).

pyradio/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
" pyradio -- Console radio player. "
22

3-
version_info = (0, 7, 2)
3+
version_info = (0, 7, 3)
44

55
__version__ = version = '.'.join(map(str, version_info))
66
__project__ = __name__

pyradio/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ def shell():
161161
Refer to: https://stackoverflow.com/questions/27372068/why-does-the-escape-key-have-a-delay-in-python-curses"""
162162
environ.setdefault('ESCDELAY', '25')
163163
curses.wrapper(pyradio.setup)
164+
if not pyradio.setup_return_status:
165+
print('\nThis terminal can not display colors.\nPyRadio cannot function in such a terminal.\n')
164166

165167
def print_playlist_selection_error(a_selection, cnf, ret, exit_if_malformed=True):
166168
if exit_if_malformed:

pyradio/radio.py

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ def __del__(self):
111111
self.transientWin = None
112112

113113
def setup(self, stdscr):
114+
self.setup_return_status = True
115+
if not curses.has_colors():
116+
self.setup_return_status = False
117+
return
114118
if logger.isEnabledFor(logging.INFO):
115119
logger.info("GUI initialization on python v. {0} on {1}".format(python_version.replace('\n', ' ').replace('\r', ' '), system()))
116120
self.stdscr = stdscr
@@ -236,7 +240,7 @@ def initBody(self):
236240
PyRadio currently supports three players: mpv, mplayer and vlc,
237241
automatically detected in this order."""
238242
else:
239-
txt = """PyRadio is not able to detect any players."
243+
txt = """PyRadio is not able to detect any players.
240244
241245
PyRadio currently supports three players: mpv, mplayer and vlc,
242246
automatically detected in this order.
@@ -288,9 +292,13 @@ def refreshBody(self):
288292

289293
def refreshNoPlayerBody(self, a_string):
290294
col = curses.color_pair(5)
295+
self.bodyWin.bkgdset(' ', col)
296+
self.bodyWin.erase()
291297
self.bodyWin.box()
292298
lines = a_string.split('\n')
293299
lineNum = 0
300+
self.txtWin.bkgdset(' ', col)
301+
self.txtWin.erase()
294302
self.txtWin.erase()
295303
for line in lines:
296304
try:
@@ -401,6 +409,23 @@ def ctrl_c_handler(self, signum, frame):
401409
Do not check result!!! """
402410
self.cnf._save_config()
403411

412+
def _goto_playing_station(self, changing_playlist=False):
413+
""" make sure playing station is visible """
414+
if self.player.isPlaying() and (self.selection != self.playing or changing_playlist):
415+
if changing_playlist:
416+
self.startPos = 0
417+
max_lines = self.maxY - 4
418+
if self.playing < self.startPos or \
419+
self.playing > self.startPos + max_lines:
420+
if self.playing < max_lines:
421+
self.startPos = 0
422+
elif self.playing > self.number_of_items - max_lines:
423+
self.startPos = self.number_of_items - max_lines
424+
else:
425+
self.startPos = int(self.playing+1/max_lines) - int(max_lines/2)
426+
self.selection = self.playing
427+
self.refreshBody()
428+
404429
def setStation(self, number):
405430
""" Select the given station number """
406431
# If we press up at the first station, we go to the last one
@@ -413,7 +438,6 @@ def setStation(self, number):
413438
self.selection = number
414439

415440
maxDisplayedItems = self.bodyMaxY - 2
416-
417441
if self.selection - self.startPos >= maxDisplayedItems:
418442
self.startPos = self.selection - maxDisplayedItems + 1
419443
elif self.selection < self.startPos:
@@ -547,10 +571,10 @@ def _format_player_string(self):
547571

548572
def _show_theme_selector(self):
549573
self.jumpnr = ''
550-
self._random_requested = False
574+
self._random_requested = False
551575
self._theme_slector = None
552576
self._theme_slector = PyRadioThemeSelector(self.bodyWin,
553-
self._theme_name, self.cnf.theme,
577+
self._theme_name, self._theme._applied_theme_max_colors, self.cnf.theme,
554578
4, 3, 4, 5, 6, 9, self._theme.getTransparency())
555579
#'/home/spiros/edit.log')
556580
self._theme_slector.show()
@@ -568,7 +592,7 @@ def _get_message_width_from_list(self, lines):
568592
if llen > mwidth:
569593
mwidth = llen
570594
return mwidth
571-
595+
572596
def _get_message_width_from_string(self, txt):
573597
lines = txt.split('\n')
574598
st_lines = [item.replace('\r','') for item in lines]
@@ -681,6 +705,7 @@ def _print_help(self):
681705
Down|/|k|/|PgDown |Change playlist selection.
682706
g |Jump to first playlist.
683707
<n>G |Jump to n-th / last playlist.
708+
p |Jump to loaded playlist.
684709
Enter|/|Right|/|l |Open selected playlist.
685710
r |Re-read playlists from disk.
686711
-|/|+| or |,|/|. |Change volume.
@@ -711,6 +736,7 @@ def _print_help(self):
711736
Down|/|k|/|PgDown |Change station selection.
712737
g |Jump to first station.
713738
<n>G |Jump to n-th / last station.
739+
p |Jump to playing station.
714740
Enter|/|Right|/|l |Play selected station.
715741
r |Select and play a random station.
716742
Space|/|Left|/|h |Stop/start playing selected station.
@@ -910,12 +936,6 @@ def _align_stations_and_refresh(self, cur_mode):
910936
Need to scan playlist """
911937
need_to_scan_playlist = True
912938
else:
913-
#if logger.isEnabledFor(logging.DEBUG):
914-
# logger.debug('=================================')
915-
# logger.debug('{}'.format(self.active_stations))
916-
# logger.debug('self.playing = {}'.format(self.playing))
917-
# logger.debug('self.stations[self.playing][0] = {}'.format(self.stations[self.playing][0]))
918-
# logger.debug('=================================')
919939
if self.stations[self.playing][0] == self.active_stations[1][0]:
920940
""" ok, self.playing found, just find selection """
921941
self.selection = self._get_station_id(self.active_stations[0][0])
@@ -926,13 +946,8 @@ def _align_stations_and_refresh(self, cur_mode):
926946
self.playing -= 1
927947
if self.playing == -1:
928948
self.playing = len(self.stations) - 1
929-
#if logger.isEnabledFor(logging.DEBUG):
930-
# logger.debug('=================================')
931-
# logger.debug('new self.playing = {}'.format(self.playing))
932-
# logger.debug('{0} == {1}'.format(self.stations[self.playing][0] ,self.active_stations[1][0]))
933949
if self.stations[self.playing][0] == self.active_stations[1][0]:
934950
""" ok, self.playing found, just find selection """
935-
#self.selection = self._get_station_id(self.active_stations[0][0])
936951
self.selection = self._get_station_id(self.active_stations[0][0])
937952
if logger.isEnabledFor(logging.DEBUG):
938953
logger.debug('** Selection station is {0} at {1}'.format(self.stations[self.playing], self.playing))
@@ -959,18 +974,21 @@ def _align_stations_and_refresh(self, cur_mode):
959974
logger.debug('Setting playing station at {}'.format(self.playing))
960975
self.setStation(self.playing)
961976
else:
977+
if self.selection == -1:
978+
self.selection = 0
962979
if logger.isEnabledFor(logging.DEBUG):
963980
logger.debug('Setting selection station at {}'.format(self.selection))
964981
self.setStation(self.selection)
965982

983+
if self.selection < 0:
966984
""" make sure we have a valid selection """
967-
if self.selection < 0:
968-
self.selection = 0
969-
self.startPos = 0
985+
self.selection = 0
986+
self.startPos = 0
987+
""" make sure playing station is visible """
988+
self._goto_playing_station(changing_playlist=True)
970989

971-
#if logger.isEnabledFor(logging.DEBUG):
972-
# logger.debug('self.selection = {}'.format(self.selection))
973-
# logger.debug('self.playing = {}'.format(self.playing))
990+
if logger.isEnabledFor(logging.DEBUG):
991+
logger.debug('self.selection = {0}, self.playing = {1}, self.startPos = {2}'.format(self.selection, self.playing, self.startPos))
974992

975993
self.selections[self.operation_mode] = (self.selection, self.startPos, self.playing, self.cnf.stations)
976994
self.refreshBody()
@@ -1121,6 +1139,10 @@ def keypress(self, char):
11211139
self._show_theme_selector()
11221140
return
11231141

1142+
if self.operation_mode <= PLAYLIST_MODE and char == ord('p'):
1143+
self._goto_playing_station()
1144+
return
1145+
11241146
if self.operation_mode == THEME_MODE:
11251147
if char not in (ord('m'), ord('v'), ord('.'),
11261148
ord(','), ord('+'), ord('-'), ord('T'),

0 commit comments

Comments
 (0)