@@ -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 ):
0 commit comments