@@ -127,9 +127,6 @@ class PyRadioTheme(object):
127
127
_read_colors = {}
128
128
_temp_colors = {}
129
129
130
- transparent = False
131
- _transparent = False
132
-
133
130
applied_theme_name = 'dark'
134
131
135
132
config_dir = ''
@@ -145,22 +142,34 @@ def __del__(self):
145
142
self ._read_colors = None
146
143
self ._temp_colors = None
147
144
145
+ def calculate_transparency (self , transparency = None ):
146
+ transp = False
147
+ if transparency is None :
148
+ if self ._active_colors ['transparency' ] == 0 :
149
+ transp = False
150
+ elif self ._active_colors ['transparency' ] == 1 :
151
+ transp = True
152
+ else :
153
+ transp = self ._cnf .use_transparency
154
+ else :
155
+ if transparency == 0 :
156
+ transp = False
157
+ elif transparency == 1 :
158
+ transp = True
159
+ else :
160
+ transp = self ._cnf .use_transparency
161
+ return transp
162
+
148
163
def _do_init_pairs (self , transparency = None ):
149
164
if self ._cnf .use_themes :
150
- if transparency is not None :
151
- logger .error ('before self._cnf.use_transparency = {}' .format ( self ._cnf .use_transparency ))
152
- self ._cnf .use_transparency = transparency
153
- logger .error ('after self._cnf.use_transparency = {}' .format ( self ._cnf .use_transparency ))
154
- else :
155
- logger .error ('self._transparent = {}' .format (self ._transparent ))
156
- logger .error ('self._cnf.use_transparency = {}' .format ( self ._cnf .use_transparency ))
157
- self ._cnf .use_transparency = self ._transparent
158
- # transp = self._transparent if self._cnf.use_transparency else False
159
- # logger.error('transp = {}'.format(transp))
165
+ transp = self .calculate_transparency (transparency )
166
+ logger .info ('=============' )
167
+ logger .info ('transp = {}' .format (transp ))
168
+
160
169
border_color = 16 if curses .COLORS > 16 else 1
161
170
if self ._cnf .use_calculated_colors or \
162
171
self ._cnf .has_border_background :
163
- if self . _cnf . use_transparency :
172
+ if transp :
164
173
if logger .isEnabledFor (logging .DEBUG ):
165
174
logger .debug ('--> 1 transparency: ON (use_calculated_colors: {0}, has_border_background: {1})' .format (self ._cnf .use_calculated_colors , self ._cnf .has_border_background ))
166
175
colors = {
@@ -199,7 +208,7 @@ def _do_init_pairs(self, transparency=None):
199
208
14 : (9 + self ._cnf .start_colors_at , 2 + self ._cnf .start_colors_at )
200
209
}
201
210
else :
202
- if self . _cnf . use_transparency :
211
+ if transp :
203
212
if logger .isEnabledFor (logging .DEBUG ):
204
213
logger .debug ('--> 2 transparency: ON (use_calculated_colors: {0}, has_border_background: {1})' .format (self ._cnf .use_calculated_colors , self ._cnf .has_border_background ))
205
214
colors = {
@@ -281,23 +290,7 @@ def readAndApplyTheme(self, a_theme, print_errors=None, **kwargs):
281
290
282
291
self ._active_colors = None
283
292
self ._active_colors = deepcopy (self ._colors )
284
- transp = False
285
- if self ._colors ['transparency' ] == 0 :
286
- transp = False
287
- elif self ._colors ['transparency' ] == 1 :
288
- transp = True
289
- else :
290
- logger .info ('use_transparency = {}' .format (use_transparency ))
291
- logger .info ('self.transparent = {}' .format (self .transparent ))
292
- if use_transparency is None and \
293
- self ._transparent :
294
- transp = True
295
- elif use_transparency :
296
- self ._transparent = transp = True
297
- logger .info ('=============' )
298
- logger .info ('transp = {}' .format (transp ))
299
- logger .info ('self.transparent = {}' .format (self ._transparent ))
300
- self ._do_init_pairs (transparency = transp )
293
+ self ._do_init_pairs (transparency = self ._colors ['transparency' ])
301
294
302
295
self ._read_colors = deepcopy (self ._colors )
303
296
# logger.error('colors\n{}'.format(self._read_colors))
@@ -524,25 +517,6 @@ def _get_theme_path(self, a_theme):
524
517
return a_file
525
518
return ''
526
519
527
- def toggleTransparency (self , force_value = None ):
528
- """ Toggles theme transparency.
529
-
530
- force_value will set transparency if True or False,
531
- or toggle transparency if None
532
- """
533
- # logger.error(' 1 self._transparent = {}'.format(self._transparent))
534
- # logger.error(' 1 force_value = {}'.format(force_value))
535
- if force_value is None :
536
- self ._transparent = not self ._transparent
537
- else :
538
- self ._transparent = force_value
539
- logger .error ('=== restoring active theme' )
540
- self .restoreActiveTheme ()
541
- return True
542
-
543
- def getTransparency (self ):
544
- return self ._transparent
545
-
546
520
547
521
class PyRadioThemeReadWrite (object ):
548
522
@@ -646,7 +620,7 @@ def read_theme(self, theme_name, theme_path):
646
620
names ['Border' ] = [names ['Stations' ][0 ]]
647
621
648
622
logger .error ('\n \n names = {}\n \n ' .format (names ))
649
- self ._temp_colors = { 'data' : {}, 'css' : {}, 'transparency' : 0 }
623
+ self ._temp_colors = { 'data' : {}, 'css' : {}, 'transparency' : 2 }
650
624
for name in names .keys ():
651
625
if name != 'transparency' :
652
626
try :
@@ -659,13 +633,15 @@ def read_theme(self, theme_name, theme_path):
659
633
if len (self ._param_to_color_id [name ]) == 2 :
660
634
self ._temp_colors ['css' ][self ._param_to_color_id [name ][1 ]] = names [name ][1 ]
661
635
self ._temp_colors ['data' ][self ._param_to_color_id [name ][1 ]] = hex_to_rgb (names [name ][1 ])
662
- else :
663
- try :
664
- self ._temp_colors ['transparency' ] = int (names [name ][0 ])
665
- if not self ._temp_colors ['transparency' ] in range (0 ,3 ):
666
- self ._temp_colors ['transparency' ] = 0
667
- except ValueError :
668
- self ._temp_colors ['transparency' ] = 0
636
+ elif name == 'transparency' :
637
+ self ._temp_colors ['transparency' ] = 2
638
+ try :
639
+ self ._temp_colors ['transparency' ] = int (names [name ][0 ])
640
+ except (ValueError , TypeError ):
641
+ self ._temp_colors ['transparency' ] = 2
642
+ if not self ._temp_colors ['transparency' ] in range (0 ,3 ):
643
+ self ._temp_colors ['transparency' ] = 2
644
+ logger .error ('\n \n set transparency: {}\n \n ' .format (self ._temp_colors ['transparency' ]))
669
645
670
646
if self ._theme_is_incomplete ():
671
647
if logger .isEnabledFor (logging .ERROR ):
@@ -780,9 +756,9 @@ def write_theme(self, out_theme, base_theme=None, colors=None):
780
756
781
757
# Theme Transparency
782
758
# Values are:
783
- # 0: No transparency (default)
759
+ # 0: No transparency
784
760
# 1: Theme is transparent
785
- # 2: Obey config setting
761
+ # 2: Obey config setting (default)
786
762
transparency 0
787
763
'''
788
764
with open (out_theme , 'w' , encoding = 'utf-8' ) as f :
0 commit comments