diff --git a/Changelog b/Changelog index 84535c14..641baf45 100644 --- a/Changelog +++ b/Changelog @@ -1,5 +1,7 @@ -2022-08-14 s-n-g +2022-08-28 s-n-g * version 0.8.9.26 (0.9-beta23) + * adding calculated messages windows color + * adding "Calculated Color" config option * Windows installation will try to install 7-Zip, if not already installed diff --git a/README.html b/README.html index 342b8f67..c3f3045e 100644 --- a/README.html +++ b/README.html @@ -101,6 +101,11 @@

Table of Contents <
  • PyRadio Themes
    • CSS color themes restrictions
    • +
    • Secondary windows background +
    • User themes
      • Converting old themes
      • @@ -174,8 +179,10 @@

        Requirements Changelog Top

         
        -2022-08-14 s-n-g
        +2022-08-28 s-n-g
             * version 0.8.9.26 (0.9-beta23)
        +    * adding calculated messages windows color
        +    * adding "Calculated Color" config option
             * Windows installation will try to install 7-Zip, if not
               already installed
         
        @@ -1314,7 +1321,7 @@ 

        PyRadio Themes CSS color themes restrictions


        This means that, in order for a theme change to take full effect, PyRadio will have to be restarted.

        +

        Secondary windows background

        +

        Secondary windows (such as messages, questions, the “Theme Selection window” the “Encoding Selection window”, etc.) originally use the same background color as the “Main window”.

        +

        It is now possible to use a different background color for these windows, to get better visual result.

        +

        There are two way to do that:

        +
          +
        1. Defined in a theme

        2. +
        3. Using a calculated color

        4. +
        +

        Theme defined secondary windows color

        +

        Themes have the following entry

        +
        # Message window border foreground and background.
        +# The background color can be left unset.
        +# Please refer to the following link for more info
        +# https://github.com/coderholic/pyradio#secondary-windows-background
        +#
        +Messages Border     #a3b367
        +

        It is possible to define a background color as well, like so

        +
        Messages Border     #a3b367 #F5DBDE
        +

        In this case, this color will be used as the Secondary Windows background color.

        +

        Although one can use any color here, it is recommended to follow these guidelines for best visual result:

        +
          +
        1. The color should be 1-20% lighter or darker than the “Stations Background” color setting of the theme.
          +
          +One can use this page (or a similar one) to insert the base color and adjust the “L” component as needed.
          +
          +A terminal alternative is pastel, which can be used like so:
        2. +
        +
        pastel color '#fbf1f2'              # show color info
        +pastel lighten .1 '#fbf1f2'         # color lightened by 10%
        +pastel darken .1 '#fbf1f2'          # color darkened by 10%
        +
          +
        1. If the “Stations Background” color is dark, create a lighter version of it; if it’s light, create a darker version of it.
          +
          +This is just a recomenration, though; just get a color that combines well with existing ones (border foreground, stations foreground and active station).
        2. +
        +

        This information is actually relevant to creating a new PyRadio theme, but it’s very important in order to understand how the calculated background color works.

        +

        Calculated secondary windows color

        +

        PyRadio will use the same background color for all windows by default, provided that the theme used does not define a “Messages Border” background color.

        +

        In order to use a “Messages Border” background color different than the “Stations background” color, when “Messages Border” background color is not defined in the selected theme, a config option is available; “Calculated color”.

        +

        This config option takes a value that’s between 0 and 0.2.

        +

        If it is 0, no color change will occur.

        +

        Otherwise, the value acts as a percentage (a factor), which indicates how much the luminance of the “Stations background” color will change to produce the new background color.

        +

        This is how this works: PyRadio will calculate the “Stations background” color perceived brightness, which will indicate whether the color is dark or light. Then depending on that, will add or subtract factor percent from its luminance value.

        +

        Finally, a check will be made to see if this color is close to “Messages Border” foreground color, and re-adjusted as possible.

        +

        Note: When a calculated background color is used, pressing “~” (tilde) will toggle it on and off. This setting will be valid until PyRadio terminates, or a new theme is loaded.

        User themes

        Users can easiliy create their own themes, using for example CSS color names as a resource, and

          diff --git a/README.md b/README.md index 33563407..c3ca6f46 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,9 @@ Ben Dowling - [https://github.com/coderholic](https://github.com/coderholic) * [Copying and pasting - Registers](#copying-and-pasting---registers) * [PyRadio Themes](#pyradio-themes) * [CSS color themes restrictions](#css-color-themes-restrictions) + * [Secondary windows background](#secondary-windows-background) + * [Theme defined secondary windows color](#theme-defined-secondary-windows-color) + * [Calculated secondary windows color](#calculated-secondary-windows-color) * [User themes](#user-themes) * [Converting old themes](#converting-old-themes) * [Using transparency](#using-transparency) @@ -794,7 +797,7 @@ PyRadio URL #a3b367 # Message window border foreground and background. # The background color can be left unset. # Please refer to the following link for more info -# https://github.com/coderholic/pyradio#calculated-colors +# https://github.com/coderholic/pyradio#secondary-windows-background # Messages Border #a3b367 @@ -832,6 +835,79 @@ These terminal will default to the old "**dark**" theme, displaying whatever col \ This means that, in order for a theme change to take full effect, **PyRadio** will have to be restarted. +### Secondary windows background + +Secondary windows (such as messages, questions, the "*Theme Selection window*" the "*Encoding Selection window*", etc.) originally use the same background color as the "*Main window*". + +It is now possible to use a different background color for these windows, to get better visual result. + +There are two way to do that: + +1. Defined in a theme + +2. Using a calculated color + +#### Theme defined secondary windows color + +Themes have the following entry + +``` +# Message window border foreground and background. +# The background color can be left unset. +# Please refer to the following link for more info +# https://github.com/coderholic/pyradio#secondary-windows-background +# +Messages Border #a3b367 +``` + +It is possible to define a background color as well, like so + + +``` +Messages Border #a3b367 #F5DBDE +``` + +In this case, this color will be used as the Secondary Windows background color. + +Although one can use any color here, it is recommended to follow these guidelines for best visual result: + +1. The color should be 1-20% lighter or darker than the "*Stations Background*" color setting of the theme. \ +\ +One can use [this page](http://www.workwithcolor.com/hsl-color-picker-01.htm) (or a similar one) to insert the base color and adjust the "*L*" component as needed. \ +\ +A terminal alternative is [pastel](https://github.com/sharkdp/pastel), which can be used like so: + +``` +pastel color '#fbf1f2' # show color info +pastel lighten .1 '#fbf1f2' # color lightened by 10% +pastel darken .1 '#fbf1f2' # color darkened by 10% +``` + + +2. If the "*Stations Background*" color is dark, create a lighter version of it; if it's light, create a darker version of it. \ +\ +This is just a recomenration, though; just get a color that combines well with existing ones (border foreground, stations foreground and active station). + +This information is actually relevant to creating a new **PyRadio** theme, but it's very important in order to understand how the calculated background color works. + +#### Calculated secondary windows color + +**PyRadio** will use the same background color for all windows by default, provided that the theme used does not define a "*Messages Border*" background color. + +In order to use a "*Messages Border*" background color different than the "*Stations background*" color, when "*Messages Border*" background color is not defined in the selected theme, a config option is available; "**Calculated color**". + +This config option takes a value that's between 0 and 0.2. + +If it is 0, no color change will occur. + +Otherwise, the value acts as a percentage (a **factor**), which indicates how much the luminance of the "*Stations background*" color will change to produce the new background color. + +This is how this works: **PyRadio** will calculate the "*Stations background*" color perceived brightness, which will indicate whether the color is dark or light. Then depending on that, will add or subtract **factor** percent from its luminance value. + +Finally, a check will be made to see if this color is close to "*Messages Border*" foreground color, and re-adjusted as possible. + +**Note:** When a calculated background color is used, pressing "**~**" (**tilde**) will toggle it on and off. This setting will be valid until **PyRadio** terminates, or a new theme is loaded. + ### User themes Users can easiliy create their own themes, using for example [CSS color names](https://www.cssportal.com/css3-color-names/) as a resource, and diff --git a/pyradio.1 b/pyradio.1 index 2e69e433..922e13f5 100644 --- a/pyradio.1 +++ b/pyradio.1 @@ -879,6 +879,104 @@ There are a couple of terminals (that I know of) which will permit changing thei This means that, in order for a theme change to take full effect, \fBpyradio\fR will have to be restarted. +.RE +.PP +\fBSecondary windows background\fR + +Secondary windows (such as messages, questions, the \fITheme Selection window\fR the \fIEncoding Selection window\fR, etc.) originally use the same background color as the \fIMain window\fR. + +It is now possible to use a different background color for these windows, to get better visual result. + +There are two way to do that: + +.RS 3 +.IP 1. 3 +Defined in a theme + +.IP 2. 3 +Using a calculated color + +.PP +\fBTheme defined secondary windows color \fR + +.RS 3 +Themes have the following entry + +.RS 3 +\fI# Message window border foreground and background. +.br +# The background color can be left unset. +.br +# Please refer to the following link for more info +.br +# https://github.com/coderholic/pyradio#secondary-windows-background +.br +# +.br +Messages Border #a3b367\fR +.RE + +It is possible to define a background color as well, like so + +.RS 3 +\fIMessages Border #a3b367 #F5DBDE\fR +.RE + +In this case, this color will be used as the \fISecondary Windows\fR background color. + +Although one can use any color here, it is recommended to follow these guidelines for best visual result: + +.RS 3 +.IP 1. 3 +The color should be 1-20% lighter or darker than the "*Stations Background*" color setting of the theme. + +One can use this page \fIhttp://www.workwithcolor.com/hsl-color-picker-01.htm\fR (or a similar one) to insert the base color and adjust the \fBL\fR component as needed. + +A terminal alternative is \fBpastel\fR (\fIhttps://github.com/sharkdp/pastel\fR), which can be used like so: + + +.RS 6 +\fIpastel color '#fbf1f2'\fR # show color info +.br +\fIpastel lighten .1 '#fbf1f2'\fR # color lightened by 10% +.br +\fIpastel darken .1 '#fbf1f2'\fR # color darkened by 10%\fR +.RE + +.IP 2. 3 +If the \fIStations Background\fR color is dark, create a lighter version of it; if it's light, create a darker version of it. + +This is just a recomenration, though; just get a color that combines well with existing ones (border foreground, stations foreground and active station). + +This information is actually relevant to creating a new \fBpyradio\fR theme, but it's very important in order to understand how the calculated background color works. + + +.RE +.RE +\fBCalculated secondary windows color\fR +.RS 3 + + +\fBpyradio\fR will use the same background color for all windows by default, provided that the theme used does not define a \fIMessages Border\fR background color. + +In order to use a \fIMessages Border\fR background color different than the \fIStations background\fR color, when \fIMessages Border\fR background color is not defined in the selected theme, a config option is available; \fBCalculated color\fR". + +This config option takes a value that's between 0 and 0.2. + +If it is 0, no color change will occur. + +Otherwise, the value acts as a percentage (a \fBfactor\fR), which indicates how much the luminance of the \fIStations background\fR color will change to produce the new background color. + +This is how this works: \fBpyradio\fR will calculate the \fIStations background\fR color perceived brightness, which will indicate whether the color is dark or light. Then depending on that, will add or subtract \fBfactor\fR percent from its luminance value. + +Finally, a check will be made to see if this color is close to \fIMessages Border\fR foreground color, and re-adjusted as possible. + + +.IP \fBNote\fR +When a calculated background color is used, pressing \fI~\fR (\fItilde\fR) will toggle it on and off. This setting will be valid until \fBPyRadio\fR terminates, or a new theme is loaded. + +.RE + .RE .PP \fBUser themes\fR @@ -891,11 +989,15 @@ Copy (and rename) one of the \fISystem Themes\fR to the user's \fBthemes\fR fold To gain access to the \fISystem Themes\fR, execute the following commands +.RS 6 \fIcd `python -c 'import site; print(site.getusersitepackages())'`\fR -.BR +.br \fIcd pyradio/themes\fR +.RE +.RS 3 (you may have to use \fIpython2\fR or \fIpython3\fR instead of plain \fIpython\fR, depending on your OS and distribution). +.RE .IP 2. 3 Customize it as desired diff --git a/pyradio/__init__.py b/pyradio/__init__.py index d27bd7c3..1e735b12 100644 --- a/pyradio/__init__.py +++ b/pyradio/__init__.py @@ -1,6 +1,6 @@ " pyradio -- Console radio player. " -version_info = (0, 8, 9, 25) +version_info = (0, 8, 9, 26) # Set it to True if new stations have been # added to the package's stations.csv diff --git a/pyradio/config.py b/pyradio/config.py index a1c0ffc8..476e13b2 100644 --- a/pyradio/config.py +++ b/pyradio/config.py @@ -2852,7 +2852,7 @@ def download(self, a_theme=None, a_path=None, print_errors=None): # Message window border foreground and background. # The background color can be left unset. # Please refer to the following link for more info -# https://github.com/coderholic/pyradio#calculated-colors +# https://github.com/coderholic/pyradio#secondary-windows-background # Messages Border {color4} @@ -2895,7 +2895,7 @@ def download(self, a_theme=None, a_path=None, print_errors=None): # Message window border foreground and background. # The background color can be left unset. # Please refer to the following link for more info -# https://github.com/coderholic/pyradio#calculated-colors +# https://github.com/coderholic/pyradio#secondary-windows-background # Messages Border {color2} @@ -3041,7 +3041,7 @@ def download(self, a_theme=None, a_path=None, print_errors=None): # Message window border foreground and background. # The background color can be left unset. # Please refer to the following link for more info -# https://github.com/coderholic/pyradio#calculated-colors +# https://github.com/coderholic/pyradio#secondary-windows-background # Messages Border {color8} @@ -3084,7 +3084,7 @@ def download(self, a_theme=None, a_path=None, print_errors=None): # Message window border foreground and background. # The background color can be left unset. # Please refer to the following link for more info -# https://github.com/coderholic/pyradio#calculated-colors +# https://github.com/coderholic/pyradio#secondary-windows-background # Messages Border {color8} @@ -3127,7 +3127,7 @@ def download(self, a_theme=None, a_path=None, print_errors=None): # Message window border foreground and background. # The background color can be left unset. # Please refer to the following link for more info -# https://github.com/coderholic/pyradio#calculated-colors +# https://github.com/coderholic/pyradio#secondary-windows-background # Messages Border {color8} @@ -3170,7 +3170,7 @@ def download(self, a_theme=None, a_path=None, print_errors=None): # Message window border foreground and background. # The background color can be left unset. # Please refer to the following link for more info -# https://github.com/coderholic/pyradio#calculated-colors +# https://github.com/coderholic/pyradio#secondary-windows-background # Messages Border {color8} diff --git a/pyradio/config_window.py b/pyradio/config_window.py index ae23cc20..f6f01ef0 100644 --- a/pyradio/config_window.py +++ b/pyradio/config_window.py @@ -79,7 +79,7 @@ class PyRadioConfigWindow(object): '|', 'Default value = dark']) _help_text.append(['If False, theme colors will be used.', '|', "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']) - _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']) + _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#secondary-windows-background', '|', 'Valid Values: 0-0.2', 'Default value: 0']) _help_text.append(None) _help_text.append(['Specify whether you will be asked to confirm every station deletion action.', '|', 'Default value: True']) @@ -350,6 +350,8 @@ def _check_if_config_is_dirty(self): def _apply_a_theme(self, a_theme, use_transparency=None): theme = PyRadioTheme(self._cnf) theme.readAndApplyTheme(a_theme, use_transparency=use_transparency) + self._cnf.use_calculated_colors = False if self._cnf.opts['calculated_color_factor'][1] == '0' else True + self._cnf.update_calculated_colors() theme = None curses.doupdate() diff --git a/pyradio/radio.py b/pyradio/radio.py index 5d3f5652..8502ac3a 100644 --- a/pyradio/radio.py +++ b/pyradio/radio.py @@ -258,6 +258,7 @@ def __init__(self, pyradio_config, self._force_print_all_lines = False self._system_asked_to_terminate = False self._cnf = pyradio_config + self._cnf.update_calculated_colors = self._update_calculated_colors self._theme = PyRadioTheme(self._cnf) self._force_update = force_update if theme: @@ -587,6 +588,8 @@ def setup(self, stdscr): ret, ret_theme_name = self._theme.readAndApplyTheme(self._theme_name, print_errors=stdscr) if ret == 0: self._theme_name = self._theme.applied_theme_name + self._cnf.use_calculated_colors = False if self._cnf.opts['calculated_color_factor'][1] == '0' else True + self._update_calculated_colors() else: self._theme_name = ret_theme_name self._cnf.theme_not_supported = True @@ -1136,6 +1139,8 @@ def _auto_update_theme(self): ret, ret_theme_name = self._theme.readAndApplyTheme(self._cnf.theme) if ret == 0: self._theme_name = self._cnf.theme + self._cnf.use_calculated_colors = False if self._cnf.opts['calculated_color_factor'][1] == '0' else True + self._update_calculated_colors() else: self._theme_name = ret_theme_name self._cnf.theme_has_error = True if ret == -1 else False @@ -4178,12 +4183,18 @@ def _toggle_transparency(self, changed_from_config_window=False, force_value=Non def _toggle_claculated_colors(self): self._cnf.use_calculated_colors = not self._cnf.use_calculated_colors + self._update_calculated_colors() + + def _update_calculated_colors(self): self._theme._do_init_pairs() self._theme._update_colors() - self.headWin.refresh() - self.outerBodyWin.refresh() - self.bodyWin.refresh() - self.footerWin.refresh() + try: + self.headWin.refresh() + self.outerBodyWin.refresh() + self.bodyWin.refresh() + self.footerWin.refresh() + except AttributeError: + pass def _save_parameters(self): if self._player_select_win is not None: @@ -5753,8 +5764,7 @@ def keypress(self, char): if self._config_win.mouse_support_option_changed: self._print_mouse_restart_info() if self._config_win.need_to_update_theme: - self._cnf.use_calculated_colors = False if self._cnf.opts['calculated_color_factor'][1] == '0' else True - self._theme.recalculate_theme() + self._theme.recalculate_theme(False) elif ret == 1: ''' config not modified ''' self._show_notification_with_delay( @@ -5778,6 +5788,8 @@ def keypress(self, char): ret, ret_theme_name = self._theme.readAndApplyTheme(self._cnf.opts['theme'][1]) if ret == 0: self._theme_name = self._cnf.theme + self._cnf.use_calculated_colors = False if self._cnf.opts['calculated_color_factor'][1] == '0' else True + self._update_calculated_colors() else: self._theme_name = ret_theme_name self._cnf.theme_has_error = True if ret == -1 else False @@ -6318,7 +6330,10 @@ def keypress(self, char): ) if isinstance(ret, tuple): ret = ret[0] - if ret < 0: + if ret == 0: + self._cnf.use_calculated_colors = False if self._cnf.opts['calculated_color_factor'][1] == '0' else True + self._update_calculated_colors() + elif ret < 0: ch_ret, _ = self._cnf.is_project_theme(self._theme_name) if ch_ret is None and \ not self._cnf.auto_update_theme: @@ -7099,6 +7114,7 @@ def keypress(self, char): if self.ws.operation_mode == self.ws.NORMAL_MODE: if char == ord('<'): + return self._update_status_bar_right(status_suffix='') if int(self._cnf.connection_timeout_int) == 0: self._show_stations_history_notification(0) @@ -7109,6 +7125,7 @@ def keypress(self, char): self._cnf.play_from_history = True self._cnf.stations_history.play_previous() elif char == ord('>'): + return self._update_status_bar_right(status_suffix='') if int(self._cnf.connection_timeout_int) == 0: self._show_stations_history_notification(0) diff --git a/pyradio/themes.py b/pyradio/themes.py index e5aa0db1..3eb6ef97 100644 --- a/pyradio/themes.py +++ b/pyradio/themes.py @@ -27,10 +27,11 @@ def isLightOrDark(rgbColor=[0,128,255]): # return False # return 'dark' - ''' https://stackoverflow.com/questions/12043187/how-to-check-if-hex-color-is-too-black + ''' + https://stackoverflow.com/questions/12043187/how-to-check-if-hex-color-is-too-black ''' hsp = sqrt(0.241 * (r * r) + 0.691 * (g * g) + 0.068 * (b * b)) - logger.error('hsp = {}'.format(hsp)) + # logger.error('hsp = {}'.format(hsp)) if (hsp>130): return True @@ -39,19 +40,29 @@ def isLightOrDark(rgbColor=[0,128,255]): return False return 'dark' -def calculate_fifteenth_color(colors, an_amount): - if an_amount == '0': +def calculate_fifteenth_color(colors, an_amount, inhibit_if_color15_exists=True): + if an_amount == '0' or \ + (15 in colors.keys() and \ + inhibit_if_color15_exists + ): + if logger.isEnabledFor(logging.INFO): + logger.info('Cannot calculating color15...') return colors[2] + if logger.isEnabledFor(logging.INFO): + logger.info('Calculating color15...') amount = round(float(an_amount) ,2) - logger.error('color2 = {}'.format(colors[2])) + if logger.isEnabledFor(logging.DEBUG): + logger.debug('Luminance color factor = {}'.format(amount)) + if logger.isEnabledFor(logging.DEBUG): + logger.debug('color2: {}'.format(colors[2])) x = list(colorsys.rgb_to_hls( - colors[2][0] / 255, - colors[2][1] / 255, - colors[2][2] / 255 + float(colors[2][0] / 255.0), + float(colors[2][1] / 255.0), + float(colors[2][2] / 255.0) )) if logger.isEnabledFor(logging.DEBUG): - logger.debug('backbround color: {}'.format(x)) + logger.debug('hls: {}'.format(x)) #logger.error('x = {}'.format(x)) start_x1 = x[1] @@ -61,10 +72,17 @@ def calculate_fifteenth_color(colors, an_amount): # logger.error('luma = {}'.format(luma)) action = not isLightOrDark(colors[2]) - logger.error('action = {}'.format(action)) + if logger.isEnabledFor(logging.DEBUG): + logger.debug('color is dark = {}'.format(action)) count = 0 + + y = list(x) + if action: + y = list(colorsys.hls_to_rgb(x[0], x[1] + amount, x[2])) + else: + y = list(colorsys.hls_to_rgb(x[0], x[1] - amount, x[2])) + for count in range(0, 15): - logger.error('count = {}'.format(count)) if action: x[1] += amount else: @@ -72,10 +90,10 @@ def calculate_fifteenth_color(colors, an_amount): if 0 < x[1] < 1: # x[1] = amount * (1 - x[1]) - logger.error(' x = {}'.format(x)) y = list(colorsys.hls_to_rgb(x[0], x[1], x[2])) - logger.error(' y = {}'.format(y)) + if logger.isEnabledFor(logging.DEBUG): + logger.debug(' luminance {0}: {1}'.format(count, x[1])) if abs(y[0] - colors[10][0]) > 15 and \ abs(y[1] - colors[11][1]) > 15 and \ @@ -84,6 +102,8 @@ def calculate_fifteenth_color(colors, an_amount): if count == 8: action = not action + if logger.isEnabledFor(logging.DEBUG): + logger.debug('flipping algorithm...') x[1] = start_x1 else: break @@ -93,7 +113,7 @@ def calculate_fifteenth_color(colors, an_amount): y[n] = round(y[n] * 255) if logger.isEnabledFor(logging.DEBUG): - logger.debug('calculated backbround color: {}'.format(y)) + logger.debug('color15: {}'.format(y)) return tuple(y) class PyRadioTheme(object): @@ -131,8 +151,8 @@ def _do_init_pairs(self, transparency=None): if self._cnf.use_calculated_colors or \ self._cnf.has_border_background: if self._cnf.use_transparency: - if logger.isEnabledFor(logging.INFO): - logger.info('--> transparency: ON') + if logger.isEnabledFor(logging.DEBUG): + logger.debug('--> transparency: ON (use_calculated_colors: {0}, has_border_background: {1})'.format(self._cnf.use_calculated_colors, self._cnf.has_border_background)) colors = { 1: (12, -1), 2: (11, -1), @@ -148,8 +168,8 @@ def _do_init_pairs(self, transparency=None): 12: (10, -1) } else: - if logger.isEnabledFor(logging.INFO): - logger.info('--> transparency: OFF') + if logger.isEnabledFor(logging.DEBUG): + logger.debug('--> transparency: OFF (use_calculated_colors: {0}, has_border_background: {1})'.format(self._cnf.use_calculated_colors, self._cnf.has_border_background)) colors = { 1: (12, 2), 2: (11, 2), @@ -166,8 +186,8 @@ def _do_init_pairs(self, transparency=None): } else: if self._cnf.use_transparency: - if logger.isEnabledFor(logging.INFO): - logger.info('--> transparency: ON') + if logger.isEnabledFor(logging.DEBUG): + logger.debug('--> transparency: ON (use_calculated_colors: {0}, has_border_background: {1})'.format(self._cnf.use_calculated_colors, self._cnf.has_border_background)) colors = { 1: (12, -1), 2: (11, -1), @@ -183,8 +203,8 @@ def _do_init_pairs(self, transparency=None): 12: (10, -1) } else: - if logger.isEnabledFor(logging.INFO): - logger.info('--> transparency: OFF') + if logger.isEnabledFor(logging.DEBUG): + logger.debug('--> transparency: OFF (use_calculated_colors: {0}, has_border_background: {1})'.format(self._cnf.use_calculated_colors, self._cnf.has_border_background)) colors = { 1: (12, 2), 2: (11, 2), @@ -207,6 +227,9 @@ def restoreActiveTheme(self): self._active_colors = deepcopy(self._read_colors) self._do_init_pairs() self._update_colors() + self.outerBodyWin.refresh() + self.bodyWin.refresh() + self.footerWin.refresh() # curses.start_color() def readAndApplyTheme(self, a_theme, print_errors=None, **kwargs): @@ -272,6 +295,9 @@ def _load_default_theme(self, a_theme): logger.info('Applying fallback theme: "{0}" instead of: "{1}"'.format(self.applied_theme_name, a_theme)) self.open_theme(self.applied_theme_name) self._update_colors() + self.outerBodyWin.refresh() + self.bodyWin.refresh() + self.footerWin.refresh() def _update_colors(self): if curses.can_change_color(): @@ -284,9 +310,15 @@ def _update_colors(self): curse_rgb[2], ) - def recalculate_theme(self): + def recalculate_theme(self, inhibit_if_color15_exists=True): + if logger.isEnabledFor(logging.DEBUG): + logger.debug('Recalculating color15...') + logger.debug('Stations background color: {}'.format(self._colors['css'][2])) + self._cnf.use_calculated_colors = False if self._cnf.opts['calculated_color_factor'][1] == '0' else True self._colors['data'][15] = calculate_fifteenth_color( - self._colors['data'], self._cnf.opts['calculated_color_factor'][1] + self._colors['data'], + self._cnf.opts['calculated_color_factor'][1], + inhibit_if_color15_exists ) self._colors['css'][15] = rgb_to_hex(tuple(self._colors['data'][15])) self._do_init_pairs() @@ -502,10 +534,12 @@ def read_theme(self, theme_name, theme_path): # logger.error('read_theme(): theme_name = "{0}", theme_path = "{1}"'.format(theme_name, theme_path)) self._temp_colors = None if not path.isfile(theme_path): - logger.error('read_theme(): file not found: {}'.format(theme_path)) + if logger.isEnabledFor(logging.ERROR): + logger.error('read_theme(): file not found: {}'.format(theme_path)) return 1, None if not access(theme_path, R_OK): - logger.error('read_theme(): file not readable: {}'.format(theme_path)) + if logger.isEnabledFor(logging.ERROR): + logger.error('read_theme(): file not readable: {}'.format(theme_path)) return 2, None try: @@ -513,7 +547,8 @@ def read_theme(self, theme_name, theme_path): lines = [line.strip() for line in thmfile if line.strip() and not line.startswith('#')] except: - logger.error('read_theme(): read error on: {}'.format(theme_path)) + if logger.isEnabledFor(logging.ERROR): + logger.error('read_theme(): read error on: {}'.format(theme_path)) return 3, None names = {} @@ -521,22 +556,23 @@ def read_theme(self, theme_name, theme_path): if ',' in line: ''' old theme format ''' # return 5, None - logger.error('read_theme(): old format theme: {}'.format(theme_path)) + if logger.isEnabledFor(logging.ERROR): + logger.error('read_theme(): old format theme: {}'.format(theme_path)) return 4, None raw = line.split(' ') if raw[-1].startswith('#') and len(raw[-1]) != 7: ''' corrupt: not valid color ''' - logger.error('read_theme(): {0} - invalid color in line: ""{1}: - value: {2}'.format(theme_path, line, raw[-1])) + if logger.isEnabledFor(logging.ERROR): + logger.error('read_theme(): {0} - invalid color in line: ""{1}: - value: {2}'.format(theme_path, line, raw[-1])) return 4, None sp = [raw[-1]] - logger.error('sp = {}'.format(sp)) raw.pop() - logger.error('raw = {}'.format(raw)) try: if raw[-1]: if raw[-1].startswith('#') and len(raw[-1]) != 7: ''' corrupt: not valid color ''' - logger.error('read_theme(): {0} - invalid color in line: ""{1}: - value: {2}'.format(theme_path, line, raw[-1])) + if logger.isEnabledFor(logging.ERROR): + logger.error('read_theme(): {0} - invalid color in line: ""{1}: - value: {2}'.format(theme_path, line, raw[-1])) return 4, None sp.append(raw[-1]) raw.pop() @@ -546,7 +582,8 @@ def read_theme(self, theme_name, theme_path): return 4, None sp.reverse() except IndexError: - logger.error('read_theme(): file is corrupt: {}'.format(theme_path)) + if logger.isEnabledFor(logging.ERROR): + logger.error('read_theme(): file is corrupt: {}'.format(theme_path)) return 4, None # logger.error('sp = {}'.format(sp)) # logger.error('names = {}'.format(names)) @@ -566,7 +603,8 @@ def read_theme(self, theme_name, theme_path): try: self._temp_colors['css'][self._param_to_color_id[name][0]] = names[name][0] except KeyError: - logger.error('read_theme(): file is corrupt: {}'.format(theme_path)) + if logger.isEnabledFor(logging.ERROR): + logger.error('read_theme(): file is corrupt: {}'.format(theme_path)) return 4, None self._temp_colors['data'][self._param_to_color_id[name][0]] = hex_to_rgb(names[name][0]) if len(self._param_to_color_id[name]) == 2: @@ -581,7 +619,8 @@ def read_theme(self, theme_name, theme_path): pass if self._theme_is_incomplete(): - logger.error('read_theme(): file is incomplete: {}'.format(theme_path)) + if logger.isEnabledFor(logging.ERROR): + logger.error('read_theme(): file is incomplete: {}'.format(theme_path)) return 4, None return 5, None @@ -589,20 +628,23 @@ def read_theme(self, theme_name, theme_path): self._temp_colors['css'][15] = names['Messages Border'][-1] self._temp_colors['data'][15] = hex_to_rgb(self._temp_colors['css'][15]) self._cnf.has_border_background = True - logger.error('read_theme(): color15 = {}'.format(self._temp_colors['css'][15])) + if logger.isEnabledFor(logging.INFO): + logger.info('read_theme(): color15 = {}'.format(self._temp_colors['css'][15])) else: self._cnf.has_border_background = False self._calculate_fifteenth_color() - logger.error('read_theme(): calculated color15 = {}'.format(self._temp_colors['css'][15])) + if logger.isEnabledFor(logging.INFO): + logger.info('read_theme(): calculated color15 = {}'.format(self._temp_colors['css'][15])) self._theme_name = theme_name self._theme_path = theme_path self._temp_colors['Name'] = theme_name self._temp_colors['Path'] = theme_path - logger.error('\n\nself._temp_colors\n{}\n\n'.format(self._temp_colors)) + # logger.error('\n\nself._temp_colors\n{}\n\n'.format(self._temp_colors)) return 0, self._temp_colors def _calculate_fifteenth_color(self): + logger.debug('Stations background color: {}'.format(self._temp_colors['css'][2])) self._temp_colors['data'][15] = calculate_fifteenth_color(self._temp_colors['data'], self._cnf.opts['calculated_color_factor'][1]) self._temp_colors['css'][15] = rgb_to_hex(tuple(self._temp_colors['data'][15])) @@ -1299,6 +1341,8 @@ def keypress(self, char): self._applied_theme = self._config_theme if ret == 0: self._applied_theme_name = self._config_theme_name + self._cnf.use_calculated_colors = False if self._cnf.opts['calculated_color_factor'][1] == '0' else True + self._cnf.update_calculated_colors() else: self._applied_theme_name = ret_theme_name self._cnf.theme_not_supported = True diff --git a/pyradio/themes/classic_by_obsdg.pyradio-theme b/pyradio/themes/classic_by_obsdg.pyradio-theme index 2ad279b9..7866f745 100644 --- a/pyradio/themes/classic_by_obsdg.pyradio-theme +++ b/pyradio/themes/classic_by_obsdg.pyradio-theme @@ -31,7 +31,7 @@ PyRadio URL #80a2be # Message window border foreground and background. # The background color can be left unset. # Please refer to the following link for more info -# https://github.com/coderholic/pyradio#calculated-colors +# https://github.com/coderholic/pyradio#secondary-windows-background # Messages Border #b3b4b6 diff --git a/pyradio/themes/cupcake_by_edunfelt.pyradio-theme b/pyradio/themes/cupcake_by_edunfelt.pyradio-theme index 99de6db9..ea0ea40e 100644 --- a/pyradio/themes/cupcake_by_edunfelt.pyradio-theme +++ b/pyradio/themes/cupcake_by_edunfelt.pyradio-theme @@ -31,7 +31,7 @@ PyRadio URL #a3b367 # Message window border foreground and background. # The background color can be left unset. # Please refer to the following link for more info -# https://github.com/coderholic/pyradio#calculated-colors +# https://github.com/coderholic/pyradio#secondary-windows-background # Messages Border #a3b367 diff --git a/pyradio/themes/fairyflossy_by_edunfelt.pyradio-theme b/pyradio/themes/fairyflossy_by_edunfelt.pyradio-theme index 028a44c0..ee18a7f8 100644 --- a/pyradio/themes/fairyflossy_by_edunfelt.pyradio-theme +++ b/pyradio/themes/fairyflossy_by_edunfelt.pyradio-theme @@ -31,7 +31,7 @@ PyRadio URL #b8a2ce # Message window border foreground and background. # The background color can be left unset. # Please refer to the following link for more info -# https://github.com/coderholic/pyradio#calculated-colors +# https://github.com/coderholic/pyradio#secondary-windows-background # Messages Border #9673d3 diff --git a/pyradio/themes/gruvbox_light_by_sng.pyradio-theme b/pyradio/themes/gruvbox_light_by_sng.pyradio-theme index 03f88e9a..4b7572ee 100644 --- a/pyradio/themes/gruvbox_light_by_sng.pyradio-theme +++ b/pyradio/themes/gruvbox_light_by_sng.pyradio-theme @@ -27,7 +27,7 @@ PyRadio URL #c23827 # Message window border foreground and background. # The background color can be left unset. # Please refer to the following link for more info -# https://github.com/coderholic/pyradio#calculated-colors +# https://github.com/coderholic/pyradio#secondary-windows-background # Messages Border #c23827 diff --git a/pyradio/themes/minima_by_ben_chile.pyradio-theme b/pyradio/themes/minima_by_ben_chile.pyradio-theme index df29e7cb..72020ed6 100644 --- a/pyradio/themes/minima_by_ben_chile.pyradio-theme +++ b/pyradio/themes/minima_by_ben_chile.pyradio-theme @@ -31,7 +31,7 @@ PyRadio URL #1AA085 # Message window border foreground and background. # The background color can be left unset. # Please refer to the following link for more info -# https://github.com/coderholic/pyradio#calculated-colors +# https://github.com/coderholic/pyradio#secondary-windows-background # Messages Border #1AA085 diff --git a/pyradio/themes/pastel_based_by_sng.pyradio-theme b/pyradio/themes/pastel_based_by_sng.pyradio-theme index b442692f..9d6a9c2c 100644 --- a/pyradio/themes/pastel_based_by_sng.pyradio-theme +++ b/pyradio/themes/pastel_based_by_sng.pyradio-theme @@ -31,7 +31,7 @@ PyRadio URL #ada2bf # Message window border foreground and background. # The background color can be left unset. # Please refer to the following link for more info -# https://github.com/coderholic/pyradio#calculated-colors +# https://github.com/coderholic/pyradio#secondary-windows-background # Messages Border #8ceb76