Skip to content

Commit aff3c6c

Browse files
committed
- actually open RadioBrowser when a dirty playlist has been
successfully saved or when the user declines to save it - fixing #240 - adding "Color Factor" parameter to themes - updating system themes (adding "Color Factor")
1 parent 109113e commit aff3c6c

16 files changed

+207
-32
lines changed

pyradio/config.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,9 @@ def playlist_history_len(self):
891891
def get_playlist_history_item(self, item_id=-1):
892892
return self._ps.item(item_id)
893893

894+
def dup_to_playlist_history(self):
895+
self._ps.duplicate()
896+
894897
def add_to_playlist_history(self, station_path='',
895898
station_file_name='',
896899
station_title='',
@@ -1364,6 +1367,7 @@ class PyRadioConfig(PyRadioStations):
13641367
)
13651368

13661369
use_calculated_colors = False
1370+
enable_calculated_colors = True
13671371
has_border_background = False
13681372

13691373
start_colors_at = 0
@@ -2986,6 +2990,10 @@ def remove_duplicates(self):
29862990
return True
29872991
return False
29882992

2993+
def duplicate(self):
2994+
it = self._p[-1]
2995+
self._p.append(it)
2996+
29892997
def add(self, station_path='',
29902998
station_file_name='',
29912999
station_title='',

pyradio/radio.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,8 @@ class PyRadio(object):
402402

403403
_open_dir_win = None
404404

405+
_function_to_repeat = None
406+
405407
def ll(self, msg):
406408
logger.error('DE ==========')
407409
logger.error('DE ===> {}'.format(msg))
@@ -1481,8 +1483,10 @@ def _print_body_header(self):
14811483
''' show force http indication '''
14821484
w_header = self._cnf.station_title
14831485
if self._cnf.browsing_station_service:
1484-
if self._cnf._online_browser.page > 0:
1485-
w_header += ' - p. {}'.format(self._cnf._online_browser.page+1)
1486+
''' fix for #240 '''
1487+
if self._cnf._online_browser:
1488+
if self._cnf._online_browser.page > 0:
1489+
w_header += ' - p. {}'.format(self._cnf._online_browser.page+1)
14861490
w_conn = http_conn[self.player.force_http][0]
14871491
if self._cnf.dirty_playlist:
14881492
align += 1
@@ -4263,6 +4267,7 @@ def _toggle_transparency(
42634267
self._theme_selector.show()
42644268

42654269
def _toggle_claculated_colors(self):
4270+
self._cnf.enable_calculated_colors = not self._cnf.enable_calculated_colors
42664271
self._cnf.use_calculated_colors = not self._cnf.use_calculated_colors
42674272
self._update_calculated_colors()
42684273

@@ -5850,8 +5855,23 @@ def _read_first_station(self, a_playlist):
58505855
def _open_radio_browser(self):
58515856
self._reset_status_bar_right()
58525857
if not self._cnf.browsing_station_service:
5853-
self._cnf.browsing_station_service = True
5854-
self.playSelectionBrowser(a_url='api.radio-browser.info')
5858+
ret = 0
5859+
if self._cnf.dirty_playlist:
5860+
if self._cnf.auto_save_playlist:
5861+
''' save playlist and open playlist '''
5862+
ret = self.saveCurrentPlaylist()
5863+
if ret != 0:
5864+
if self._cnf.browsing_station_service:
5865+
self._cnf.removed_playlist_history_item()
5866+
else:
5867+
''' ask to save playlist '''
5868+
ret = 1
5869+
self._cnf.dup_to_playlist_history()
5870+
self._function_to_repeat = self._open_radio_browser
5871+
self._print_save_modified_playlist(self.ws.ASK_TO_SAVE_PLAYLIST_WHEN_OPENING_PLAYLIST_MODE)
5872+
if ret == 0:
5873+
self._cnf.browsing_station_service = True
5874+
self.playSelectionBrowser(a_url='api.radio-browser.info')
58555875

58565876
def search_radio_browser_headless(self, index):
58575877
#if self._cnf.headless and self._cnf.online_browser:
@@ -8086,6 +8106,8 @@ def keypress(self, char):
80868106
self._open_playlist()
80878107
else:
80888108
self._goto_history_back_handler()
8109+
if self._function_to_repeat:
8110+
self._function_to_repeat()
80898111
else:
80908112
if self._cnf.browsing_station_service:
80918113
self._cnf.removed_playlist_history_item()
@@ -8094,6 +8116,8 @@ def keypress(self, char):
80948116
self._open_playlist()
80958117
else:
80968118
self._goto_history_back_handler()
8119+
if self._function_to_repeat:
8120+
self._function_to_repeat()
80978121
elif char in (curses.KEY_EXIT, ord('q'), 27):
80988122
self.bodyWin.nodelay(True)
80998123
char = self.bodyWin.getch()
@@ -8103,6 +8127,7 @@ def keypress(self, char):
81038127
if self._cnf.browsing_station_service:
81048128
self._cnf.removed_playlist_history_item()
81058129
self.refreshBody()
8130+
self._function_to_repeat = None
81068131
return
81078132

81088133
elif self.ws.operation_mode == self.ws.PLAYLIST_DIRTY_RELOAD_CONFIRM_MODE:

pyradio/themes.py

Lines changed: 65 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,22 @@ def _do_init_pairs(
188188
transp = calculate_transparency_function()
189189

190190
border_color = 16 if curses.COLORS > 16 else 1
191+
if not self._cnf.use_calculated_colors and \
192+
self._colors['color_factor'] > 0:
193+
if logger.isEnabledFor(logging.INFO):
194+
logger.debug('Theme has a color_factor, setting use_calculated_colors = True')
195+
self._cnf.use_calculated_colors = True
196+
# if not self._cnf.enable_calculated_colors and \
197+
# self._cnf.use_calculated_colors:
198+
# if logger.isEnabledFor(logging.INFO):
199+
# logger.debug('Theme has a color_factor, setting use_calculated_colors = True')
200+
# self._cnf.use_calculated_colors = False
201+
if self._cnf.use_calculated_colors:
202+
self._cnf.use_calculated_colors = self._cnf.enable_calculated_colors
203+
if not self._cnf.enable_calculated_colors:
204+
if logger.isEnabledFor(logging.INFO):
205+
logger.debug(f'Setting use_calculated_colors = False due to enable_calculated_colors')
206+
191207
if self._cnf.use_calculated_colors or \
192208
self._cnf.has_border_background:
193209
if transp:
@@ -360,12 +376,18 @@ def recalculate_theme(self, inhibit_if_color15_exists=True):
360376
logger.debug('Recalculating color15...')
361377
logger.debug('Stations background color: {}'.format(self._colors['css'][2]))
362378
self._cnf.use_calculated_colors = False if self._cnf.opts['calculated_color_factor'][1] == '0' else True
379+
# logger.error('\n\nself._colors before recalculate\n{}\n\n'.format(self._colors))
380+
if self._colors['color_factor'] == 0:
381+
fact = self._cnf.opts['calculated_color_factor'][1]
382+
else:
383+
fact = self._colors['color_factor']
363384
self._colors['data'][15] = calculate_fifteenth_color(
364385
self._colors['data'],
365-
self._cnf.opts['calculated_color_factor'][1],
386+
fact,
366387
inhibit_if_color15_exists
367-
)
388+
)
368389
self._colors['css'][15] = rgb_to_hex(tuple(self._colors['data'][15]))
390+
# logger.error('\n\nself._colors after recalculate\n{}\n\n'.format(self._colors))
369391
self._do_init_pairs()
370392
self._update_colors()
371393

@@ -418,6 +440,7 @@ def open_theme(self, a_theme='', a_path='', print_errors=None, no_curses=False):
418440

419441
if a_theme == 'dark' or a_theme == 'default':
420442
self._colors['transparency'] = 2
443+
self._colors['color_factor'] = 0
421444
self._colors['data'] = {1: (192, 192, 192), 2: (0, 0, 0), 3: (0, 128, 0), 4: (0, 0, 0), 5: (135, 0, 135), 6: (0, 0, 0), 7: (0, 128, 0), 8: (0, 0, 0), 9: (0, 128, 0), 10: (128, 128, 0), 11: (95, 135, 255), 12: (0, 255, 255), 14: (192, 192, 192), 13: (0, 0, 0), 15: (26, 26, 26)}
422445
if not no_curses:
423446
if curses.COLORS > 16:
@@ -432,6 +455,7 @@ def open_theme(self, a_theme='', a_path='', print_errors=None, no_curses=False):
432455
elif a_theme == 'dark_16_colors':
433456
''' info '''
434457
self._colors['transparency'] = 2
458+
self._colors['color_factor'] = 0
435459
self._colors['Name'] = 'dark_16_colors'
436460
self._colors['Path'] = ''
437461
self.applied_theme_name = 'dark_16_colors'
@@ -445,6 +469,7 @@ def open_theme(self, a_theme='', a_path='', print_errors=None, no_curses=False):
445469
''' info '''
446470
self._colors['Name'] = 'light'
447471
self._colors['transparency'] = 0
472+
self._colors['color_factor'] = 0
448473
self._colors['Path'] = ''
449474
self.applied_theme_name = 'light'
450475
self._colors['data'] = {1: (0, 0, 0), 2: (255,255, 255), 3: (128, 0, 0), 8: (192, 192, 192), 9: (0, 0, 128), 4: (192, 192, 192), 5: (128, 0, 128), 6: (192, 192, 192), 7: (0, 0, 128), 12: (0, 0, 128), 11: (0, 0, 128), 10: (128, 0, 128), 13: (255, 255, 255), 14: (128, 0, 0), 15: (230, 230, 230)}
@@ -456,6 +481,7 @@ def open_theme(self, a_theme='', a_path='', print_errors=None, no_curses=False):
456481
''' info '''
457482
self._colors['Name'] = 'light_16_colors'
458483
self._colors['transparency'] = 0
484+
self._colors['color_factor'] = 0
459485
self._colors['Path'] = ''
460486
self.applied_theme_name = 'light_16_colors'
461487
self._colors['data'] = {1: (128, 128, 128), 2: (255, 255, 255), 3: (255, 0, 0), 8: (255, 255, 255), 9: (0, 0, 255), 4: (255, 255, 255), 5: (255, 0, 255), 6: (255, 255, 255), 7: (0, 0, 255), 12: (0, 0, 255), 11: (0, 0, 255), 10: (255, 0, 255), 13: (255, 255,255), 14: (255, 0, 0), 15: (230, 230, 230)}
@@ -468,6 +494,7 @@ def open_theme(self, a_theme='', a_path='', print_errors=None, no_curses=False):
468494
''' info '''
469495
self._colors['Name'] = 'black_on_white'
470496
self._colors['transparency'] = 0
497+
self._colors['color_factor'] = 0.2
471498
self._colors['Path'] = ''
472499
self.applied_theme_name = 'black_on_white'
473500
self._colors['data'] = {1: (128, 128, 128), 2: (255, 255, 255), 3: (0, 0, 0), 8: (255, 255, 255), 9: (138, 138, 138), 4: (255, 255, 255), 5: (128, 128, 128), 6: (0, 0, 0), 7: (128, 128, 128), 12: (0, 255, 255), 11: (138, 138, 138), 10: (138, 138, 138), 14: (0, 0, 0), 13: (255, 255, 255), 15: (229, 229, 229)}
@@ -479,6 +506,7 @@ def open_theme(self, a_theme='', a_path='', print_errors=None, no_curses=False):
479506
''' info '''
480507
self._colors['Name'] = 'white_on_black'
481508
self._colors['transparency'] = 2
509+
self._colors['color_factor'] = 0.2
482510
self._colors['Path'] = ''
483511
self.applied_theme_name = 'white_on_black'
484512
self._colors['data'] = {1: (158, 158, 158), 2: (38, 38, 38), 3: (238, 238, 238), 8: (28, 28, 28), 9: (218, 218, 218), 4: (38, 38, 38), 5: (158, 158, 158), 6: (38, 38, 38), 7: (218, 218, 218), 12: (218, 218, 218), 11: (138, 138, 138), 10: (158, 158, 158), 13: (0, 0, 0), 14: (169, 169, 169), 15: (52, 52, 52)}
@@ -529,6 +557,7 @@ def open_theme(self, a_theme='', a_path='', print_errors=None, no_curses=False):
529557
self._colors['css'] = {}
530558
for k in self._colors['data'].keys():
531559
self._colors['css'][k] = rgb_to_hex(self._colors['data'][k])
560+
# logger.error('colors\n{}'.format(self._colors))
532561

533562
self.applied_theme_name = self._colors['Name']
534563
return ret
@@ -650,9 +679,31 @@ def read_theme(self, theme_name, theme_path):
650679

651680
if logger.isEnabledFor(logging.DEBUG):
652681
logger.debug('theme names = {}'.format(names))
653-
self._temp_colors = { 'data': {}, 'css': {}, 'transparency': 2}
682+
self._temp_colors = { 'data': {}, 'css': {}, 'transparency': 2, 'color_factor': 0}
654683
for name in names.keys():
655-
if name != 'transparency':
684+
if name == 'transparency':
685+
self._temp_colors['transparency'] = 2
686+
try:
687+
self._temp_colors['transparency'] = int(names[name][0])
688+
except (ValueError, TypeError):
689+
self._temp_colors['transparency'] = 2
690+
if not self._temp_colors['transparency'] in range(0,3):
691+
self._temp_colors['transparency'] = 2
692+
# logger.error('\n\nset transparency: {}\n\n'.format(self._temp_colors['transparency']))
693+
elif name == 'Color Factor':
694+
try:
695+
num = float(names[name][0])
696+
if 0.00 <= num <= 0.20:
697+
self._temp_colors['color_factor'] = num
698+
else:
699+
if logger.isEnabledFor(logging.DEBUG):
700+
logger.debug(f'Theme Color Factor is off-limits: 0.0 <= {num} <= 0.20; reseting to 0.0')
701+
self._temp_colors['color_factor'] = 0.0
702+
except ValueError:
703+
if logger.isEnabledFor(logging.DEBUG):
704+
logger.debug(f'Theme Color Factor is invalid: {names[name][0]}; reseting to 0.0')
705+
self._temp_colors['color_factor'] = 0.0
706+
else:
656707
try:
657708
self._temp_colors['css'][self._param_to_color_id[name][0]] = names[name][0]
658709
except KeyError:
@@ -663,15 +714,6 @@ def read_theme(self, theme_name, theme_path):
663714
if len(self._param_to_color_id[name]) == 2:
664715
self._temp_colors['css'][self._param_to_color_id[name][1]] = names[name][1]
665716
self._temp_colors['data'][self._param_to_color_id[name][1]] = hex_to_rgb(names[name][1])
666-
elif name == 'transparency':
667-
self._temp_colors['transparency'] = 2
668-
try:
669-
self._temp_colors['transparency'] = int(names[name][0])
670-
except (ValueError, TypeError):
671-
self._temp_colors['transparency'] = 2
672-
if not self._temp_colors['transparency'] in range(0,3):
673-
self._temp_colors['transparency'] = 2
674-
# logger.error('\n\nset transparency: {}\n\n'.format(self._temp_colors['transparency']))
675717

676718
if self._theme_is_incomplete():
677719
if logger.isEnabledFor(logging.ERROR):
@@ -682,6 +724,7 @@ def read_theme(self, theme_name, theme_path):
682724
if len(names['Messages Border']) == 2:
683725
self._temp_colors['css'][15] = names['Messages Border'][-1]
684726
self._temp_colors['data'][15] = hex_to_rgb(self._temp_colors['css'][15])
727+
self._temp_colors['color_factor'] = 0
685728
self._cnf.has_border_background = True
686729
if logger.isEnabledFor(logging.INFO):
687730
logger.info('read_theme(): color15 = {}'.format(self._temp_colors['css'][15]))
@@ -703,7 +746,15 @@ def read_theme(self, theme_name, theme_path):
703746
def _calculate_fifteenth_color(self):
704747
if logger.isEnabledFor(logging.DEBUG):
705748
logger.debug('Stations background color: {}'.format(self._temp_colors['css'][2]))
706-
self._temp_colors['data'][15] = calculate_fifteenth_color(self._temp_colors['data'], self._cnf.opts['calculated_color_factor'][1])
749+
# logger.error('tmp_colors\n{}'.format(self._temp_colors))
750+
if self._temp_colors['color_factor'] == 0:
751+
fact = self._cnf.opts['calculated_color_factor'][1]
752+
else:
753+
fact = self._temp_colors['color_factor']
754+
self._temp_colors['data'][15] = calculate_fifteenth_color(
755+
self._temp_colors['data'],
756+
fact
757+
)
707758
self._temp_colors['css'][15] = rgb_to_hex(tuple(self._temp_colors['data'][15]))
708759

709760
def _theme_is_incomplete(self, some_colors=None):

pyradio/themes/AM_by_amski1.pyradio-theme

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,19 @@ Extra Func #102406
2828
# (background color will come from Stations)
2929
PyRadio URL #E3E3E3
3030

31+
# Luminance Color Factor
32+
# The factor to lighten or darken Stations background
33+
# color, to get a calculated color used as background
34+
# for secondary windows
35+
# Valid values: 0 - 0.2
36+
Color Factor 0.01
37+
3138
# Message window border foreground and background.
3239
# The background color can be left unset.
3340
# Please refer to the following link for more info
34-
# https://github.com/coderholic/pyradio#secondary-windows-background
41+
# https://github.com/coderholic/pyradio/blob/master/docs/themes.md#secondary-windows-background
3542
#
36-
Messages Border #CEFCC7
43+
Messages Border #CEFCC7
3744

3845
# Theme Transparency
3946
# Values are:

pyradio/themes/blue-by-boxer.pyradio-theme

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,17 @@ PyRadio URL #FD5902
3232
# Message window border foreground and background.
3333
# The background color can be left unset.
3434
# Please refer to the following link for more info
35-
# https://github.com/coderholic/pyradio#secondary-windows-background
35+
# https://github.com/coderholic/pyradio/blob/master/docs/themes.md#secondary-windows-background
3636
#
3737
Messages Border #FD5902
3838

39+
# Luminance Color Factor
40+
# The factor to lighten or darken Stations background
41+
# color, to get a calculated color used as background
42+
# for secondary windows
43+
# Valid values: 0 - 0.2
44+
Color Factor 0.05
45+
3946
# Theme Transparency
4047
# Values are:
4148
# 0: No transparency

pyradio/themes/catppuccin-frappe.pyradio-theme

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,17 @@ Extra Func #CA9EE6
2828
# (background color will come from Stations)
2929
PyRadio URL #CA9EE6
3030

31+
# Luminance Color Factor
32+
# The factor to lighten or darken Stations background
33+
# color, to get a calculated color used as background
34+
# for secondary windows
35+
# Valid values: 0 - 0.2
36+
Color Factor 0.16
37+
3138
# Message window border foreground and background.
3239
# The background color can be left unset.
3340
# Please refer to the following link for more info
34-
# https://github.com/coderholic/pyradio#secondary-windows-background
41+
# https://github.com/coderholic/pyradio/blob/master/docs/themes.md#secondary-windows-background
3542
#
3643
Messages Border #CA9EE6
3744

pyradio/themes/catppuccin-latte.pyradio-theme

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,17 @@ Extra Func #8839EF
2828
# (background color will come from Stations)
2929
PyRadio URL #8839EF
3030

31+
# Luminance Color Factor
32+
# The factor to lighten or darken Stations background
33+
# color, to get a calculated color used as background
34+
# for secondary windows
35+
# Valid values: 0 - 0.2
36+
Color Factor 0.03
37+
3138
# Message window border foreground and background.
3239
# The background color can be left unset.
3340
# Please refer to the following link for more info
34-
# https://github.com/coderholic/pyradio#secondary-windows-background
41+
# https://github.com/coderholic/pyradio/blob/master/docs/themes.md#secondary-windows-background
3542
#
3643
Messages Border #8839EF
3744

pyradio/themes/catppuccin-macchiato.pyradio-theme

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,17 @@ Extra Func #C6A0F6
2828
# (background color will come from Stations)
2929
PyRadio URL #C6A0F6
3030

31+
# Luminance Color Factor
32+
# The factor to lighten or darken Stations background
33+
# color, to get a calculated color used as background
34+
# for secondary windows
35+
# Valid values: 0 - 0.2
36+
Color Factor 0.04
37+
3138
# Message window border foreground and background.
3239
# The background color can be left unset.
3340
# Please refer to the following link for more info
34-
# https://github.com/coderholic/pyradio#secondary-windows-background
41+
# https://github.com/coderholic/pyradio/blob/master/docs/themes.md#secondary-windows-background
3542
#
3643
Messages Border #C6A0F6
3744

0 commit comments

Comments
 (0)