Skip to content

Commit b62f895

Browse files
committed
- themes will respect their transparency setting (regardless of config
transparency value). Default transparency is now 2 (Obey config), though - fixing a potential theme download crash
1 parent f08406e commit b62f895

16 files changed

+70
-91
lines changed

pyradio/config.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3275,9 +3275,12 @@ def download(self, a_theme=None, a_path=None, print_errors=None):
32753275
self.theme = self._last_used_theme
32763276
self.theme_file_name = w_path
32773277
self.theme_url = url
3278-
self.status = requests_response.status_code
3278+
try:
3279+
self.status = requests_response.status_code
3280+
except AttributeError:
3281+
self.status = 404
32793282

3280-
ret = requests_response.status_code == 200 and written
3283+
ret = self.status == 200 and written
32813284
if not ret:
32823285
try:
32833286
remove(w_path)

pyradio/install.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1428,7 +1428,7 @@ def _do_it(self, mode='update'):
14281428
print_no_python2()
14291429
sys.exit(1)
14301430

1431-
if use_logo and not args.get_cache:
1431+
if use_logo and not args.open_cache:
14321432
print_pyradio_on()
14331433
if PY3 and not args.python2:
14341434
print_python3()

pyradio/radio.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2363,7 +2363,7 @@ def _show_theme_selector(self, changed_from_config=False):
23632363
self._theme_name,
23642364
self._cnf.theme,
23652365
11, 3, 11, 10, 6, 9,
2366-
self._theme.getTransparency(),
2366+
self._theme.calculate_transparency(),
23672367
self._cnf.auto_update_theme,
23682368
self._watch_theme_lock
23692369
)
@@ -4884,8 +4884,8 @@ def _toggle_transparency(self, changed_from_config_window=False, force_value=Non
48844884
return
48854885
logger.error('\n==========================\nself._cnf.use_transparency = {}'.format(self._cnf.use_transparency))
48864886
logger.error('force_value = {}'.format(force_value))
4887-
self._theme.toggleTransparency(force_value)
4888-
self._cnf.use_transparency = self._theme.getTransparency()
4887+
self._cnf.use_transparency = not self._cnf.use_transparency
4888+
self._theme.restoreActiveTheme()
48894889
logger.error('self._cnf.use_transparency = {}'.format(self._cnf.use_transparency))
48904890
if self.ws.operation_mode == self.ws.THEME_MODE:
48914891
self._theme_selector.transparent = self._cnf.use_transparency

pyradio/themes.py

Lines changed: 37 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,6 @@ class PyRadioTheme(object):
127127
_read_colors = {}
128128
_temp_colors = {}
129129

130-
transparent = False
131-
_transparent = False
132-
133130
applied_theme_name = 'dark'
134131

135132
config_dir = ''
@@ -145,22 +142,34 @@ def __del__(self):
145142
self._read_colors = None
146143
self._temp_colors = None
147144

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+
148163
def _do_init_pairs(self, transparency=None):
149164
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+
160169
border_color = 16 if curses.COLORS > 16 else 1
161170
if self._cnf.use_calculated_colors or \
162171
self._cnf.has_border_background:
163-
if self._cnf.use_transparency:
172+
if transp:
164173
if logger.isEnabledFor(logging.DEBUG):
165174
logger.debug('--> 1 transparency: ON (use_calculated_colors: {0}, has_border_background: {1})'.format(self._cnf.use_calculated_colors, self._cnf.has_border_background))
166175
colors = {
@@ -199,7 +208,7 @@ def _do_init_pairs(self, transparency=None):
199208
14: (9 + self._cnf.start_colors_at, 2 + self._cnf.start_colors_at)
200209
}
201210
else:
202-
if self._cnf.use_transparency:
211+
if transp:
203212
if logger.isEnabledFor(logging.DEBUG):
204213
logger.debug('--> 2 transparency: ON (use_calculated_colors: {0}, has_border_background: {1})'.format(self._cnf.use_calculated_colors, self._cnf.has_border_background))
205214
colors = {
@@ -281,23 +290,7 @@ def readAndApplyTheme(self, a_theme, print_errors=None, **kwargs):
281290

282291
self._active_colors = None
283292
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'])
301294

302295
self._read_colors = deepcopy(self._colors)
303296
# logger.error('colors\n{}'.format(self._read_colors))
@@ -524,25 +517,6 @@ def _get_theme_path(self, a_theme):
524517
return a_file
525518
return ''
526519

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-
546520

547521
class PyRadioThemeReadWrite(object):
548522

@@ -646,7 +620,7 @@ def read_theme(self, theme_name, theme_path):
646620
names['Border'] = [names['Stations'][0]]
647621

648622
logger.error('\n\nnames = {}\n\n'.format(names))
649-
self._temp_colors = { 'data': {}, 'css': {}, 'transparency': 0}
623+
self._temp_colors = { 'data': {}, 'css': {}, 'transparency': 2}
650624
for name in names.keys():
651625
if name != 'transparency':
652626
try:
@@ -659,13 +633,15 @@ def read_theme(self, theme_name, theme_path):
659633
if len(self._param_to_color_id[name]) == 2:
660634
self._temp_colors['css'][self._param_to_color_id[name][1]] = names[name][1]
661635
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\nset transparency: {}\n\n'.format(self._temp_colors['transparency']))
669645

670646
if self._theme_is_incomplete():
671647
if logger.isEnabledFor(logging.ERROR):
@@ -780,9 +756,9 @@ def write_theme(self, out_theme, base_theme=None, colors=None):
780756
781757
# Theme Transparency
782758
# Values are:
783-
# 0: No transparency (default)
759+
# 0: No transparency
784760
# 1: Theme is transparent
785-
# 2: Obey config setting
761+
# 2: Obey config setting (default)
786762
transparency 0
787763
'''
788764
with open(out_theme, 'w', encoding='utf-8') as f:

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Messages Border #FD5902
3838

3939
# Theme Transparency
4040
# Values are:
41-
# 0: No transparency (default)
41+
# 0: No transparency
4242
# 1: Theme is transparent
43-
# 2: Obey config setting
43+
# 2: Obey config setting (default)
4444
transparency 0

pyradio/themes/catppuccin-frappe.pyradio-theme

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Messages Border #CA9EE6
3737

3838
# Theme Transparency
3939
# Values are:
40-
# 0: No transparency (default)
40+
# 0: No transparency
4141
# 1: Theme is transparent
42-
# 2: Obey config setting
42+
# 2: Obey config setting (default)
4343
transparency 0

pyradio/themes/catppuccin-latte.pyradio-theme

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Messages Border #8839EF
3737

3838
# Theme Transparency
3939
# Values are:
40-
# 0: No transparency (default)
40+
# 0: No transparency
4141
# 1: Theme is transparent
42-
# 2: Obey config setting
42+
# 2: Obey config setting (default)
4343
transparency 0

pyradio/themes/catppuccin-macchiato.pyradio-theme

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Messages Border #C6A0F6
3737

3838
# Theme Transparency
3939
# Values are:
40-
# 0: No transparency (default)
40+
# 0: No transparency
4141
# 1: Theme is transparent
42-
# 2: Obey config setting
42+
# 2: Obey config setting (default)
4343
transparency 0

pyradio/themes/catppuccin-mocha.pyradio-theme

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Messages Border #CBA6F7
3737

3838
# Theme Transparency
3939
# Values are:
40-
# 0: No transparency (default)
40+
# 0: No transparency
4141
# 1: Theme is transparent
42-
# 2: Obey config setting
42+
# 2: Obey config setting (default)
4343
transparency 0

pyradio/themes/classic_by_obsdg.pyradio-theme

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Messages Border #b3b4b6
3737

3838
# Theme Transparency
3939
# Values are:
40-
# 0: No transparency (default)
40+
# 0: No transparency
4141
# 1: Theme is transparent
42-
# 2: Obey config setting
42+
# 2: Obey config setting (default)
4343
transparency 2

pyradio/themes/cupcake_by_edunfelt.pyradio-theme

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Messages Border #a3b367
3737

3838
# Theme Transparency
3939
# Values are:
40-
# 0: No transparency (default)
40+
# 0: No transparency
4141
# 1: Theme is transparent
42-
# 2: Obey config setting
42+
# 2: Obey config setting (default)
4343
transparency 0

pyradio/themes/fairyflossy_by_edunfelt.pyradio-theme

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Messages Border #9673d3
3737

3838
# Theme Transparency
3939
# Values are:
40-
# 0: No transparency (default)
40+
# 0: No transparency
4141
# 1: Theme is transparent
42-
# 2: Obey config setting
42+
# 2: Obey config setting (default)
4343
transparency 0

pyradio/themes/gruvbox_dark_by_sng.pyradio-theme

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Edit Cursor #ffffff #fb4933
3737

3838
# Theme Transparency
3939
# Values are:
40-
# 0: No transparency (default)
40+
# 0: No transparency
4141
# 1: Theme is transparent
42-
# 2: Obey config setting
42+
# 2: Obey config setting (default)
4343
transparency 0

pyradio/themes/gruvbox_light_by_sng.pyradio-theme

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Edit Cursor #bdae93 #504945
3838

3939
# Theme Transparency
4040
# Values are:
41-
# 0: No transparency (default)
41+
# 0: No transparency
4242
# 1: Theme is transparent
43-
# 2: Obey config setting
43+
# 2: Obey config setting (default)
4444
transparency 0

pyradio/themes/minima_by_ben_chile.pyradio-theme

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Messages Border #1AA085
3737

3838
# Theme Transparency
3939
# Values are:
40-
# 0: No transparency (default)
40+
# 0: No transparency
4141
# 1: Theme is transparent
42-
# 2: Obey config setting
42+
# 2: Obey config setting (default)
4343
transparency 0

pyradio/themes/pastel_based_by_sng.pyradio-theme

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Messages Border #8ceb76
3737

3838
# Theme Transparency
3939
# Values are:
40-
# 0: No transparency (default)
40+
# 0: No transparency
4141
# 1: Theme is transparent
42-
# 2: Obey config setting
42+
# 2: Obey config setting (default)
4343
transparency 0

0 commit comments

Comments
 (0)