Skip to content

Commit 6721daa

Browse files
committed
- Calculated colorfactor is now in the config
- Toggling calculated colors by pressing ~ (tilde)
1 parent c37cd52 commit 6721daa

13 files changed

+190
-103
lines changed

README.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1314,7 +1314,7 @@ <h2 id="pyradio-themes">PyRadio Themes <span style="padding-left: 10px;"><sup st
13141314
# Message window border foreground and background.
13151315
# The background color can be left unset.
13161316
# Please refer to the following link for more info
1317-
# https://github.com/coderholic/pyradio#calculated_colors
1317+
# https://github.com/coderholic/pyradio#calculated-colors
13181318
#
13191319
Messages Border #a3b367
13201320

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ PyRadio URL #a3b367
794794
# Message window border foreground and background.
795795
# The background color can be left unset.
796796
# Please refer to the following link for more info
797-
# https://github.com/coderholic/pyradio#calculated_colors
797+
# https://github.com/coderholic/pyradio#calculated-colors
798798
#
799799
Messages Border #a3b367
800800

pyradio/config.py

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -515,11 +515,9 @@ def read_playlist_file(
515515

516516
ret = 0
517517
if self._register_to_open:
518-
logger.error('register_to_open = {}'.format(self._register_to_open))
519518
stationFile, ret = self._get_register_filename_from_register()
520519
self._is_register = True
521520
else:
522-
logger.error('stationFile = {}'.format(stationFile))
523521
stationFile, ret = self._get_playlist_abspath_from_data(stationFile=stationFile)
524522
self._is_register = False
525523
read_file = True
@@ -1141,6 +1139,7 @@ class PyRadioConfig(PyRadioStations):
11411139
opts['theme_title'] = ['Theme Options', '']
11421140
opts['theme'] = ['Theme: ', 'dark']
11431141
opts['use_transparency'] = ['Use transparency: ', False]
1142+
opts['calculated_color_factor'] = ['Calculated color: ', '0']
11441143
opts['playlist_manngement_title'] = ['Playlist Management Options', '']
11451144
opts['confirm_station_deletion'] = ['Confirm station deletion: ', True]
11461145
opts['confirm_playlist_reload'] = ['Confirm playlist reload: ', True]
@@ -1377,6 +1376,19 @@ def use_transparency(self, val):
13771376
self.opts['use_transparency'][1] = val
13781377
self.opts['dirty_config'][1] = True
13791378

1379+
@property
1380+
def calculated_color_factor(self):
1381+
return float(self.opts['calculated_color_factor'][1])
1382+
1383+
@calculated_color_factor.setter
1384+
def calculated_color_factor(self, value):
1385+
try:
1386+
test = float(str(value))
1387+
self.opts['calculated_color_factor'][1] = str(value)
1388+
except (ValueError, TypeError, NameError):
1389+
self.opts['calculated_color_factor'][1] = '0'
1390+
self.opts['dirty_config'][1] = True
1391+
13801392
@property
13811393
def default_encoding(self):
13821394
return self.opts['default_encoding'][1]
@@ -1788,6 +1800,16 @@ def read_config(self):
17881800
self.opts['use_transparency'][1] = True
17891801
else:
17901802
self.opts['use_transparency'][1] = False
1803+
elif sp[0] == 'calculated_color_factor':
1804+
try:
1805+
t = round(float(sp[1]), 2)
1806+
s_t = str(t)[:4]
1807+
if s_t == '0.0':
1808+
s_t = '0'
1809+
self.opts['calculated_color_factor'][1] = s_t
1810+
except (ValueError, TypeError):
1811+
self.opts['calculated_color_factor'][1] = '0'
1812+
self.use_calculated_colors = False if self.opts['calculated_color_factor'][1] == '0' else True
17911813
elif sp[0] == 'force_http':
17921814
if sp[1].lower() == 'true':
17931815
self.opts['force_http'][1] = True
@@ -2068,27 +2090,31 @@ def save_config(self, from_command_line=False):
20682090
# Default value: False
20692091
use_transparency = {9}
20702092
2093+
# Calculated color factor
2094+
# Valid values: 0-0.2
2095+
# Default value: 0
2096+
calculated_color_factor = {10}
20712097
20722098
# Playlist management
20732099
#
20742100
# Specify whether you will be asked to confirm
20752101
# every station deletion action
20762102
# Valid values: True, true, False, false
20772103
# Default value: True
2078-
confirm_station_deletion = {10}
2104+
confirm_station_deletion = {11}
20792105
20802106
# Specify whether you will be asked to confirm
20812107
# playlist reloading, when the playlist has not
20822108
# been modified within PyRadio
20832109
# Valid values: True, true, False, false
20842110
# Default value: True
2085-
confirm_playlist_reload = {11}
2111+
confirm_playlist_reload = {12}
20862112
20872113
# Specify whether you will be asked to save a
20882114
# modified playlist whenever it needs saving
20892115
# Valid values: True, true, False, false
20902116
# Default value: False
2091-
auto_save_playlist = {12}
2117+
auto_save_playlist = {13}
20922118
20932119
'''
20942120
copyfile(self.config_file, self.config_file + '.restore')
@@ -2107,6 +2133,7 @@ def save_config(self, from_command_line=False):
21072133
self.opts['force_http'][1],
21082134
self.opts['theme'][1] if not self.opts['auto_update_theme'][1] else '*' + self.opts['theme'][1],
21092135
self.opts['use_transparency'][1],
2136+
self.opts['calculated_color_factor'][1],
21102137
self.opts['confirm_station_deletion'][1],
21112138
self.opts['confirm_playlist_reload'][1],
21122139
self.opts['auto_save_playlist'][1]))
@@ -2825,7 +2852,7 @@ def download(self, a_theme=None, a_path=None, print_errors=None):
28252852
# Message window border foreground and background.
28262853
# The background color can be left unset.
28272854
# Please refer to the following link for more info
2828-
# https://github.com/coderholic/pyradio#calculated_colors
2855+
# https://github.com/coderholic/pyradio#calculated-colors
28292856
#
28302857
Messages Border {color4}
28312858
@@ -2868,7 +2895,7 @@ def download(self, a_theme=None, a_path=None, print_errors=None):
28682895
# Message window border foreground and background.
28692896
# The background color can be left unset.
28702897
# Please refer to the following link for more info
2871-
# https://github.com/coderholic/pyradio#calculated_colors
2898+
# https://github.com/coderholic/pyradio#calculated-colors
28722899
#
28732900
Messages Border {color2}
28742901
@@ -3014,7 +3041,7 @@ def download(self, a_theme=None, a_path=None, print_errors=None):
30143041
# Message window border foreground and background.
30153042
# The background color can be left unset.
30163043
# Please refer to the following link for more info
3017-
# https://github.com/coderholic/pyradio#calculated_colors
3044+
# https://github.com/coderholic/pyradio#calculated-colors
30183045
#
30193046
Messages Border {color8}
30203047
@@ -3057,7 +3084,7 @@ def download(self, a_theme=None, a_path=None, print_errors=None):
30573084
# Message window border foreground and background.
30583085
# The background color can be left unset.
30593086
# Please refer to the following link for more info
3060-
# https://github.com/coderholic/pyradio#calculated_colors
3087+
# https://github.com/coderholic/pyradio#calculated-colors
30613088
#
30623089
Messages Border {color8}
30633090
@@ -3100,7 +3127,7 @@ def download(self, a_theme=None, a_path=None, print_errors=None):
31003127
# Message window border foreground and background.
31013128
# The background color can be left unset.
31023129
# Please refer to the following link for more info
3103-
# https://github.com/coderholic/pyradio#calculated_colors
3130+
# https://github.com/coderholic/pyradio#calculated-colors
31043131
#
31053132
Messages Border {color8}
31063133
@@ -3143,7 +3170,7 @@ def download(self, a_theme=None, a_path=None, print_errors=None):
31433170
# Message window border foreground and background.
31443171
# The background color can be left unset.
31453172
# Please refer to the following link for more info
3146-
# https://github.com/coderholic/pyradio#calculated_colors
3173+
# https://github.com/coderholic/pyradio#calculated-colors
31473174
#
31483175
Messages Border {color8}
31493176

pyradio/config_window.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class PyRadioConfigWindow(object):
7979
'|', 'Default value = dark'])
8080
_help_text.append(['If False, theme colors will be used.', '|',
8181
"If True and a compositor is running, the stations' window background will be transparent.", '|', "If True and a compositor is not running, the terminal's background color will be used.", '|', 'Default value: False'])
82+
_help_text.append(['Pyradio can calculate and use an alternative color for secondary windows.', '|', 'This option will determine if this color will be used (value > 0) or not (value = 0), provided that the theme used does not already provide it.', '|', 'The value of this option is actually the factor to darken or lighten the main (stations) background color.', '|', 'You can get more info on this at https://github.com/coderholic/pyradio#calculated-colors' , '|', 'Valid Values: 0-0.2', 'Default value: 0'])
8283
_help_text.append(None)
8384
_help_text.append(['Specify whether you will be asked to confirm every station deletion action.',
8485
'|', 'Default value: True'])
@@ -324,6 +325,7 @@ def _load_default_values(self):
324325
''' Transparency '''
325326
#self._old_use_transparency = self._config_options['use_transparency'][1]
326327
self._config_options['use_transparency'][1] = False
328+
self._config_options['calculated_color_factor'][1] = '0'
327329
self._config_options['force_http'][1] = False
328330
self._toggle_transparency_function(changed_from_config_window=True, force_value=False)
329331
self._config_options['playlist_manngement_title'][1] = ''
@@ -362,13 +364,55 @@ def keypress(self, char):
362364
if self.too_small:
363365
return 1, []
364366
val = list(self._config_options.items())[self.selection]
367+
logger.error('val = {}'.format(val))
365368
if char in self._global_functions.keys():
366369
self._global_functions[char]()
367370
elif val[0] == 'radiobrowser':
368371
if char in (curses.KEY_RIGHT, ord('l'),
369372
ord(' '), curses.KEY_ENTER, ord('\n')):
370373
return 2, []
371374

375+
elif val[0] == 'calculated_color_factor':
376+
if char in (curses.KEY_RIGHT, ord('l')):
377+
t = float(val[1][1])
378+
if t < .2:
379+
t = round(t + .01, 2)
380+
logger.error('t = {}'.format(t))
381+
s_t = str(t)[:4]
382+
if s_t == '0.0':
383+
s_t = '0'
384+
logger.error('s_t = ' + s_t)
385+
self._config_options[val[0]][1] = s_t
386+
self._win.addstr(
387+
self.selection+1,
388+
3 + len(val[1][0]),
389+
s_t + ' ', curses.color_pair(6))
390+
self._print_title()
391+
self._win.refresh()
392+
# att = PyRadioThemeReadWrite(self._cnf)
393+
# att._calculate_fifteenth_color()
394+
return -1, []
395+
396+
elif char in (curses.KEY_LEFT, ord('h')):
397+
t = float(val[1][1])
398+
if t > 0:
399+
t = round(t - .01, 2)
400+
logger.error('t = {}'.format(t))
401+
s_t = str(t)[:4]
402+
if s_t == '0.0':
403+
s_t = '0'
404+
logger.error('s_t = ' + s_t)
405+
self._config_options[val[0]][1] = s_t
406+
self._win.addstr(
407+
self.selection+1,
408+
3 + len(val[1][0]),
409+
s_t + ' ', curses.color_pair(6))
410+
self._print_title()
411+
self._win.refresh()
412+
# att = PyRadioThemeReadWrite(self._cnf)
413+
# att._calculate_fifteenth_color()
414+
return -1, []
415+
372416
elif val[0] == 'connection_timeout':
373417
if char in (curses.KEY_RIGHT, ord('l')):
374418
t = int(val[1][1])
@@ -467,6 +511,10 @@ def keypress(self, char):
467511
self.mouse_support_option_changed = False
468512
else:
469513
self.mouse_support_option_changed = True
514+
if self._saved_config_options['calculated_color_factor'][1] == self._config_options['calculated_color_factor'][1]:
515+
self.need_to_update_theme = False
516+
else:
517+
self.need_to_update_theme = True
470518
self._saved_config_options = deepcopy(self._config_options)
471519
if self._cnf.opts != self._saved_config_options:
472520
''' check if player has changed '''

pyradio/radio.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2280,7 +2280,7 @@ def _show_main_help(self, from_keyboard=False):
22802280
m| / |v ||M|ute player / Save |v|olume (not in vlc).
22812281
!Misc
22822282
o| / |s| / |R ||O|pen / |S|ave / |R|eload playlist.
2283-
t| / |T |Load |t|heme / |T|oggle transparency.
2283+
t| / |T| / |~ |Change |t|heme / |T|ransparency / Calc. Background.
22842284
c |Open Configuration window.'''
22852285
self._show_help(txt,
22862286
mode_to_set=self.ws.MAIN_HELP_MODE,
@@ -5752,6 +5752,8 @@ def keypress(self, char):
57525752
self.player.playback_timeout = int(self._cnf.connection_timeout)
57535753
if self._config_win.mouse_support_option_changed:
57545754
self._print_mouse_restart_info()
5755+
if self._config_win.need_to_update_theme:
5756+
self._theme.recalculate_theme()
57555757
elif ret == 1:
57565758
''' config not modified '''
57575759
self._show_notification_with_delay(
@@ -8410,7 +8412,6 @@ def _load_playlist_and_station_from_station_history(self, h_item, func):
84108412
self._is_register = True
84118413
else:
84128414
stationFile, ret = self._cnf._get_playlist_abspath_from_data(stationFile=h_item[0])
8413-
logger.error('stationFile = {}'.format(stationFile))
84148415
self._is_register = False
84158416
if ret > 0:
84168417
''' Continue going through history items '''

0 commit comments

Comments
 (0)