Skip to content

Commit d86e243

Browse files
committed
adding passive notification when reverting to default theme
1 parent 9ce85bf commit d86e243

File tree

8 files changed

+127
-40
lines changed

8 files changed

+127
-40
lines changed

Changelog

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
2019-06-23 s-n-g
1+
2019-06-26 s-n-g
2+
* Version 0.7.7
23
* mpv now uses a dedicated socket file. This way multiple instances of
34
PyRadio can be executed.
45
* Introducing session locking.
@@ -9,6 +10,7 @@
910
* Theme selection window reworked - themes are separated by location,
1011
theme selection is remembered when resizing, and loading default or
1112
saved theme (in config window).
13+
* PyRadio will report reverting to default theme.
1214
* PyRadio will check and report when a new release is available.
1315
* Added good bye message.
1416
* Theme editor implementation started (disabled for this release).

README.html

+3-1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ <h2 id="controls">Controls</h2>
9797
PgUp/PgDown Change station selection Change station playlist Change station theme
9898
g Jump to first station Jump to first playlist Jump to first theme
9999
&lt;n&gt;G Jump to n-th / last station Jump to n-th / last playlist Jump to n-th / last theme
100+
M Jump to the middle of the playlist Jump to the middle of the list -
100101
p Jump to playing station Jump to playing playlist -
101102
Enter/Right/l Play selected station Open selected playlist Apply selected theme
102103
r Select and play a random station Re-read playlists from disk -
@@ -106,6 +107,7 @@ <h2 id="controls">Controls</h2>
106107
m Mute / unmute player [Valid] [Valid]
107108
v Save volume (not applicable for vlc) [Valid] [Valid]
108109
o s R Open / Save / Reload playlist - -
110+
e Change station&#39;s encoding
109111
DEL,x Delete selected station - -
110112
t T Load theme / Toggle transparency [Valid] [Valid]
111113
c Open Configuration window. - -
@@ -250,7 +252,7 @@ <h2 id="session-locking">Session Locking</h2>
250252
<p><strong>PyRadio</strong> uses session locking, which actually means that only the first instance executed within a given session will be able to write to the configuration file.</p>
251253
<p>Subsequent instances will be “<em>locked</em>”. This means that the user can still play stations, load and edit playlists, load and test themes, but any changes will <strong>not</strong> be recorded in the configuration file.</p>
252254
<h3 id="seeeion-unlocking">Seeeion unlocking</h3>
253-
<p>If for any reason <strong>PyRadio</strong> always starts in <em>locked mode</em>, one can <strong>unclock</strong> the session, using the “<em>–unlock</em>” command line paremater.</p>
255+
<p>If for any reason <strong>PyRadio</strong> always starts in <em>locked mode</em>, one can <strong>unclock</strong> the session, using the “<em>–unlock</em>” command line paremater.</p>
254256
<h2 id="update-notification">Update notification</h2>
255257
<p><strong>PyRadio</strong> will periodically (once every 10 days) check whether a new version has been released.</p>
256258
<p>If so, a notification message will be displayed, informing the user about it.</p>

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ Up/Down/j/k/
8282
PgUp/PgDown Change station selection Change station playlist Change station theme
8383
g Jump to first station Jump to first playlist Jump to first theme
8484
<n>G Jump to n-th / last station Jump to n-th / last playlist Jump to n-th / last theme
85+
M Jump to the middle of the playlist Jump to the middle of the list -
8586
p Jump to playing station Jump to playing playlist -
8687
Enter/Right/l Play selected station Open selected playlist Apply selected theme
8788
r Select and play a random station Re-read playlists from disk -
@@ -91,6 +92,7 @@ Space - -
9192
m Mute / unmute player [Valid] [Valid]
9293
v Save volume (not applicable for vlc) [Valid] [Valid]
9394
o s R Open / Save / Reload playlist - -
95+
e Change station's encoding
9496
DEL,x Delete selected station - -
9597
t T Load theme / Toggle transparency [Valid] [Valid]
9698
c Open Configuration window. - -
@@ -364,7 +366,7 @@ Subsequent instances will be "*locked*". This means that the user can still play
364366

365367
### Seeeion unlocking
366368

367-
If for any reason **PyRadio** always starts in *locked mode*, one can **unclock** the session, using the "*--unlock*" command line paremater.
369+
If for any reason **PyRadio** always starts in "*locked mode*", one can **unclock** the session, using the "*--unlock*" command line paremater.
368370

369371
## Update notification
370372

pyradio/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
" pyradio -- Console radio player. "
22

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

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

pyradio/config.py

+3
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,9 @@ def current_playlist_index(self):
482482

483483
class PyRadioConfig(PyRadioStations):
484484

485+
theme_not_supported = False
486+
theme_not_supported_notification_shown = False
487+
485488
opts = collections.OrderedDict()
486489
opts[ 'general_title' ] = [ 'General Options', '' ]
487490
opts[ 'player' ] = [ 'Player: ', '' ]

pyradio/radio.py

+52-6
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ class PyRadio(object):
8484
_theme = PyRadioTheme()
8585
_theme_name = 'dark'
8686
_theme_selector = None
87+
_theme_not_supported_thread = None
88+
_theme_not_supported_notification_duration = 1.75
8789
theme_forced_selection = []
8890

8991
_config_win = None
@@ -163,8 +165,12 @@ def setup(self, stdscr):
163165
curses.use_default_colors()
164166
self._theme._transparent = self._cnf.use_transparency
165167
self._theme.config_dir = self._cnf.stations_dir
166-
self._theme.readAndApplyTheme(self._theme_name)
167-
self._theme_name = self._theme.applied_theme_name
168+
ret, ret_theme_name = self._theme.readAndApplyTheme(self._theme_name)
169+
if ret == 0:
170+
self._theme_name = self._theme.applied_theme_name
171+
else:
172+
self._theme_name = ret_theme_name
173+
self._cnf.theme_not_supported = True
168174

169175
self.log = Log()
170176
# For the time being, supported players are mpv, mplayer and vlc.
@@ -701,7 +707,7 @@ def _show_theme_selector(self, changed_from_config=False):
701707
self.jumpnr = ''
702708
self._random_requested = False
703709
self._theme_selector = None
704-
logger.error('DE\n\nself._theme = {0}\nself._theme_name = {1}\nself._cnf.theme = {2}\n\n'.format(self._theme, self._theme_name, self._cnf.theme))
710+
#logger.error('DE\n\nself._theme = {0}\nself._theme_name = {1}\nself._cnf.theme = {2}\n\n'.format(self._theme, self._theme_name, self._cnf.theme))
705711
self._theme_selector = PyRadioThemeSelector(self.bodyWin, self._cnf, self._theme,
706712
self._theme_name, self._theme._applied_theme_max_colors, self._cnf.theme,
707713
4, 3, 4, 5, 6, 9, self._theme.getTransparency())
@@ -950,6 +956,29 @@ def closeRecoveryNotification(self, *arg, **karg):
950956
#arg[1].release()
951957
self.refreshBody()
952958

959+
def _show_theme_not_supported(self):
960+
if self._cnf.theme_not_supported_notification_shown:
961+
return
962+
txt = 'Error loading selected theme!\n____Using default theme.'
963+
self._show_help(txt, mode_to_set=self.operation_mode, caption='',
964+
prompt='', is_message=True)
965+
# start 1750 ms counter
966+
if self._theme_not_supported_thread:
967+
if self._theme_not_supported_thread.is_alive:
968+
self._theme_not_supported_thread.cancel()
969+
self._theme_not_supported_thread = None
970+
self._theme_not_supported_thread = threading.Timer(self._theme_not_supported_notification_duration, self.closeThemeNotSupportedNotification)
971+
self._theme_not_supported_thread.start()
972+
curses.doupdate()
973+
974+
def closeThemeNotSupportedNotification(self, *arg, **karg):
975+
#arg[1].acquire()
976+
self._cnf.theme_not_supported = False
977+
self._cnf.theme_not_supported_notification_shown = True
978+
self._theme_not_supported_notification_duration = 0.75
979+
#arg[1].release()
980+
self.refreshBody()
981+
953982
def _show_theme_help(self):
954983
txt = """Up|/|j|/|PgUp
955984
Down|/|k|/|PgDown |Change theme selection.
@@ -1526,6 +1555,9 @@ def _redisplay_transient_window(self):
15261555
self._theme_selector.set_theme(self.theme_forced_selection)
15271556
self._print_ask_to_create_theme()
15281557

1558+
if self._cnf.theme_not_supported:
1559+
self._show_theme_not_supported()
1560+
15291561
def play_random(self):
15301562
# Pick a random radio station
15311563
if self.number_of_items > 0:
@@ -1896,8 +1928,12 @@ def keypress(self, char):
18961928
# restore theme, if necessary
18971929
if self._cnf.opts['theme'][1] != self._config_win._config_options['theme'][1]:
18981930
#self._config_win._apply_a_theme(self._cnf.opts['theme'][1])
1899-
self._theme.readAndApplyTheme(self._cnf.opts['theme'][1])
1900-
self._theme_name = self._cnf.theme
1931+
ret, ret_theme_name = self._theme.readAndApplyTheme(self._cnf.opts['theme'][1])
1932+
if ret == 0:
1933+
self._theme_name = self._cnf.theme
1934+
else:
1935+
self._theme_name = ret_theme_name
1936+
self._cnf.theme_not_supported = True
19011937
curses.doupdate()
19021938
# make sure config is not saved
19031939
self._config_win._saved_config_options['dirty_config'][1] = False
@@ -2039,6 +2075,8 @@ def keypress(self, char):
20392075
ord('?'), ord('#'), curses.KEY_RESIZE):
20402076
theme_id, save_theme = self._theme_selector.keypress(char)
20412077

2078+
#if self._cnf.theme_not_supported:
2079+
# self._show_theme_not_supported()
20422080
if theme_id == -1:
20432081
""" cancel or hide """
20442082
self._theme_name = self._theme_selector._applied_theme_name
@@ -2070,8 +2108,16 @@ def keypress(self, char):
20702108
self._config_win._saved_config_options['theme'][1] = self._theme_name
20712109
if logger.isEnabledFor(logging.INFO):
20722110
logger.info('Activating theme: {}'.format(self._theme_name))
2073-
self._theme.readAndApplyTheme(self._theme_name,
2111+
ret, ret_theme_name = self._theme.readAndApplyTheme(self._theme_name,
20742112
theme_path=self._theme_selector._themes[theme_id][1])
2113+
if isinstance(ret, tuple):
2114+
ret = ret[0]
2115+
if ret == -1:
2116+
self._theme_name = ret_theme_name
2117+
self._cnf.theme_not_supported = True
2118+
self._cnf.theme_not_supported_notification_shown = False
2119+
self._show_theme_not_supported()
2120+
#self.refreshBody()
20752121
curses.doupdate()
20762122
# update config window
20772123
if self._config_win:

0 commit comments

Comments
 (0)