Skip to content

Commit

Permalink
Version 0.7.3
Browse files Browse the repository at this point in the history
  • Loading branch information
s-n-g committed Mar 4, 2019
1 parent 1a5bed0 commit 1294d44
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 59 deletions.
13 changes: 13 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
2019-02-04 s-n-g

* Version 0.7.3
* Added "p" command to jump to playing station / loaded playlist.
* Added two more themes (dark_16_colors and light_16_colors)
* Improved black_on_white theme
* On a 8 color terminal, the fall-back theme will be "light",
if "light_16_colors" is default.
* Exiting if terminal cannot display colors.
* Fixed player selection error screen.
* Fixed a regression which might appear when loading a playlist

2019-02-02 s-n-g

* Version 0.7.2
* Themes support added (4 hardcoded themes).
* Command line option -t (--theme) THEME added.
* Config option "theme" added.
* Key "t" will open the "Theme Selection Window".
* Key "T" will toggle transparency / use terminal's background color.
* Alt keyboard combinations will not be considered as ESCAPE char.
* Help / message windows use multiple colors.
Expand Down
2 changes: 1 addition & 1 deletion README.html
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ <h2 id="pyradio-themes">PyRadio Themes</h2>
</ol>
<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>
<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>
<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>
<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>
<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>
<p>The use of custom themes and theme editing is not implemented yet; theses are features for future releases.</p>
<h3 id="using-transparency">Using transparency</h3>
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ The visual result of an applied theme greatly depends on the terminal settings (

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

**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.
**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*").

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).

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

.IP \fBNote\fR
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.
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").

.PP
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).
Expand Down
2 changes: 1 addition & 1 deletion pyradio/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
" pyradio -- Console radio player. "

version_info = (0, 7, 2)
version_info = (0, 7, 3)

__version__ = version = '.'.join(map(str, version_info))
__project__ = __name__
Expand Down
2 changes: 2 additions & 0 deletions pyradio/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ def shell():
Refer to: https://stackoverflow.com/questions/27372068/why-does-the-escape-key-have-a-delay-in-python-curses"""
environ.setdefault('ESCDELAY', '25')
curses.wrapper(pyradio.setup)
if not pyradio.setup_return_status:
print('\nThis terminal can not display colors.\nPyRadio cannot function in such a terminal.\n')

def print_playlist_selection_error(a_selection, cnf, ret, exit_if_malformed=True):
if exit_if_malformed:
Expand Down
66 changes: 44 additions & 22 deletions pyradio/radio.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ def __del__(self):
self.transientWin = None

def setup(self, stdscr):
self.setup_return_status = True
if not curses.has_colors():
self.setup_return_status = False
return
if logger.isEnabledFor(logging.INFO):
logger.info("GUI initialization on python v. {0} on {1}".format(python_version.replace('\n', ' ').replace('\r', ' '), system()))
self.stdscr = stdscr
Expand Down Expand Up @@ -236,7 +240,7 @@ def initBody(self):
PyRadio currently supports three players: mpv, mplayer and vlc,
automatically detected in this order."""
else:
txt = """PyRadio is not able to detect any players."
txt = """PyRadio is not able to detect any players.
PyRadio currently supports three players: mpv, mplayer and vlc,
automatically detected in this order.
Expand Down Expand Up @@ -288,9 +292,13 @@ def refreshBody(self):

def refreshNoPlayerBody(self, a_string):
col = curses.color_pair(5)
self.bodyWin.bkgdset(' ', col)
self.bodyWin.erase()
self.bodyWin.box()
lines = a_string.split('\n')
lineNum = 0
self.txtWin.bkgdset(' ', col)
self.txtWin.erase()
self.txtWin.erase()
for line in lines:
try:
Expand Down Expand Up @@ -401,6 +409,23 @@ def ctrl_c_handler(self, signum, frame):
Do not check result!!! """
self.cnf._save_config()

def _goto_playing_station(self, changing_playlist=False):
""" make sure playing station is visible """
if self.player.isPlaying() and (self.selection != self.playing or changing_playlist):
if changing_playlist:
self.startPos = 0
max_lines = self.maxY - 4
if self.playing < self.startPos or \
self.playing > self.startPos + max_lines:
if self.playing < max_lines:
self.startPos = 0
elif self.playing > self.number_of_items - max_lines:
self.startPos = self.number_of_items - max_lines
else:
self.startPos = int(self.playing+1/max_lines) - int(max_lines/2)
self.selection = self.playing
self.refreshBody()

def setStation(self, number):
""" Select the given station number """
# If we press up at the first station, we go to the last one
Expand All @@ -413,7 +438,6 @@ def setStation(self, number):
self.selection = number

maxDisplayedItems = self.bodyMaxY - 2

if self.selection - self.startPos >= maxDisplayedItems:
self.startPos = self.selection - maxDisplayedItems + 1
elif self.selection < self.startPos:
Expand Down Expand Up @@ -547,10 +571,10 @@ def _format_player_string(self):

def _show_theme_selector(self):
self.jumpnr = ''
self._random_requested = False
self._random_requested = False
self._theme_slector = None
self._theme_slector = PyRadioThemeSelector(self.bodyWin,
self._theme_name, self.cnf.theme,
self._theme_name, self._theme._applied_theme_max_colors, self.cnf.theme,
4, 3, 4, 5, 6, 9, self._theme.getTransparency())
#'/home/spiros/edit.log')
self._theme_slector.show()
Expand All @@ -568,7 +592,7 @@ def _get_message_width_from_list(self, lines):
if llen > mwidth:
mwidth = llen
return mwidth

def _get_message_width_from_string(self, txt):
lines = txt.split('\n')
st_lines = [item.replace('\r','') for item in lines]
Expand Down Expand Up @@ -681,6 +705,7 @@ def _print_help(self):
Down|/|k|/|PgDown |Change playlist selection.
g |Jump to first playlist.
<n>G |Jump to n-th / last playlist.
p |Jump to loaded playlist.
Enter|/|Right|/|l |Open selected playlist.
r |Re-read playlists from disk.
-|/|+| or |,|/|. |Change volume.
Expand Down Expand Up @@ -711,6 +736,7 @@ def _print_help(self):
Down|/|k|/|PgDown |Change station selection.
g |Jump to first station.
<n>G |Jump to n-th / last station.
p |Jump to playing station.
Enter|/|Right|/|l |Play selected station.
r |Select and play a random station.
Space|/|Left|/|h |Stop/start playing selected station.
Expand Down Expand Up @@ -910,12 +936,6 @@ def _align_stations_and_refresh(self, cur_mode):
Need to scan playlist """
need_to_scan_playlist = True
else:
#if logger.isEnabledFor(logging.DEBUG):
# logger.debug('=================================')
# logger.debug('{}'.format(self.active_stations))
# logger.debug('self.playing = {}'.format(self.playing))
# logger.debug('self.stations[self.playing][0] = {}'.format(self.stations[self.playing][0]))
# logger.debug('=================================')
if self.stations[self.playing][0] == self.active_stations[1][0]:
""" ok, self.playing found, just find selection """
self.selection = self._get_station_id(self.active_stations[0][0])
Expand All @@ -926,13 +946,8 @@ def _align_stations_and_refresh(self, cur_mode):
self.playing -= 1
if self.playing == -1:
self.playing = len(self.stations) - 1
#if logger.isEnabledFor(logging.DEBUG):
# logger.debug('=================================')
# logger.debug('new self.playing = {}'.format(self.playing))
# logger.debug('{0} == {1}'.format(self.stations[self.playing][0] ,self.active_stations[1][0]))
if self.stations[self.playing][0] == self.active_stations[1][0]:
""" ok, self.playing found, just find selection """
#self.selection = self._get_station_id(self.active_stations[0][0])
self.selection = self._get_station_id(self.active_stations[0][0])
if logger.isEnabledFor(logging.DEBUG):
logger.debug('** Selection station is {0} at {1}'.format(self.stations[self.playing], self.playing))
Expand All @@ -959,18 +974,21 @@ def _align_stations_and_refresh(self, cur_mode):
logger.debug('Setting playing station at {}'.format(self.playing))
self.setStation(self.playing)
else:
if self.selection == -1:
self.selection = 0
if logger.isEnabledFor(logging.DEBUG):
logger.debug('Setting selection station at {}'.format(self.selection))
self.setStation(self.selection)

if self.selection < 0:
""" make sure we have a valid selection """
if self.selection < 0:
self.selection = 0
self.startPos = 0
self.selection = 0
self.startPos = 0
""" make sure playing station is visible """
self._goto_playing_station(changing_playlist=True)

#if logger.isEnabledFor(logging.DEBUG):
# logger.debug('self.selection = {}'.format(self.selection))
# logger.debug('self.playing = {}'.format(self.playing))
if logger.isEnabledFor(logging.DEBUG):
logger.debug('self.selection = {0}, self.playing = {1}, self.startPos = {2}'.format(self.selection, self.playing, self.startPos))

self.selections[self.operation_mode] = (self.selection, self.startPos, self.playing, self.cnf.stations)
self.refreshBody()
Expand Down Expand Up @@ -1121,6 +1139,10 @@ def keypress(self, char):
self._show_theme_selector()
return

if self.operation_mode <= PLAYLIST_MODE and char == ord('p'):
self._goto_playing_station()
return

if self.operation_mode == THEME_MODE:
if char not in (ord('m'), ord('v'), ord('.'),
ord(','), ord('+'), ord('-'), ord('T'),
Expand Down
Loading

0 comments on commit 1294d44

Please sign in to comment.