Skip to content

Commit a083f26

Browse files
committed
Merge branch 'dev' into testing
2 parents 49fd15e + 0914168 commit a083f26

File tree

1 file changed

+39
-34
lines changed

1 file changed

+39
-34
lines changed

utils.py

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
USER_HAS_COLR = importlib.util.find_spec("colr") is not None
1212
if USER_HAS_COLR:
1313
from colr import color
14-
USER_HAS_PYWAL = importlib.util.find_spec("pywal") is not None
15-
if USER_HAS_PYWAL:
16-
import pywal
1714
import logging
1815
import signal
1916
HOME = str(Path.home())
@@ -47,6 +44,7 @@
4744
COLOR_DEBUG = '\033[94m'
4845
COLOR_INFO = '\033[90m'
4946
LOG_HINT= BOLD+'\033[97m'
47+
BOLD_RESET= COLOR_RESET+BOLD
5048

5149
# Custom logging format (adapted from https://stackoverflow.com/a/14859558)
5250
class MyFormatter(logging.Formatter):
@@ -487,23 +485,22 @@ def get_color_schemes(wallpaper, ncolor=None):
487485
colors_json = json.loads(materialYouColors)
488486

489487
if wallpaper_type != "color":
490-
best_colors = f'Best colors: '
488+
best_colors = f'Best colors:'
491489

492490
for index, col in colors_json['bestColors'].items():
493491
if USER_HAS_COLR:
494-
best_colors+=f'{COLOR_RESET}{BOLD}{index}:{color(col,fore=col)}'
492+
best_colors+=f' {BOLD_RESET}{index}:{color(col,fore=col)}'
495493
else:
496-
best_colors+=f'{BOLD}{index}:{col}'
494+
best_colors+=f' {BOLD_RESET}{index}:{COLOR_INFO}{col}'
497495
logging.info(best_colors)
498496

499497
seed = colors_json['seedColor']
500498
sedColor = list(seed.values())[0]
501499
seedNo = list(seed.keys())[0]
502500
if USER_HAS_COLR:
503-
logging.info(f'Using seed: {COLOR_RESET}{BOLD}{seedNo}:{color(sedColor, fore=sedColor)}')
501+
logging.info(f'Using seed: {BOLD_RESET}{seedNo}:{color(sedColor, fore=sedColor)}')
504502
else:
505-
print(BOLD+"Using seed: " +
506-
seedNo+":"+sedColor+COLOR_RESET)
503+
logging.info(f'{BOLD}Using seed: {BOLD_RESET}{seedNo}:{COLOR_INFO}{sedColor}')
507504

508505
with open('/tmp/kde-material-you-colors.json', 'w', encoding='utf8') as current_scheme:
509506
current_scheme.write(json.dumps(
@@ -572,24 +569,25 @@ def apply_color_schemes(light=False):
572569
colorscheme_out = subprocess.check_output("plasma-apply-colorscheme "+color_scheme+".colors",
573570
shell=True, stderr=subprocess.PIPE,universal_newlines=True).strip()
574571
logging.info(colorscheme_out)
575-
572+
576573
def apply_pywal_schemes(light=None, pywal_light=None, use_pywal=False, schemes=None):
577-
if use_pywal != None and use_pywal == True:
578-
pywal_colors = None
579-
if pywal_light != None:
580-
if pywal_light == True:
581-
pywal_colors=schemes.get_wal_light_scheme()
582-
else:
583-
pywal_light=False
584-
pywal_colors=schemes.get_wal_dark_scheme()
585-
elif light != None:
586-
if light == True:
587-
pywal_colors=schemes.get_wal_light_scheme()
588-
elif light == False:
589-
pywal_colors=schemes.get_wal_dark_scheme()
590-
591-
if pywal_colors != None:
592-
if USER_HAS_PYWAL:
574+
pywal_colors = None
575+
if pywal_light != None:
576+
if pywal_light == True:
577+
pywal_colors=schemes.get_wal_light_scheme()
578+
else:
579+
pywal_light=False
580+
pywal_colors=schemes.get_wal_dark_scheme()
581+
elif light != None:
582+
if light == True:
583+
pywal_colors=schemes.get_wal_light_scheme()
584+
elif light == False:
585+
pywal_colors=schemes.get_wal_dark_scheme()
586+
587+
if pywal_colors != None:
588+
if use_pywal != None and use_pywal == True:
589+
if importlib.util.find_spec("pywal") is not None:
590+
import pywal
593591
# On very rare occassions pywal will hang, add a timeout to it
594592
timeout_set(3)
595593
try:
@@ -608,8 +606,8 @@ def apply_pywal_schemes(light=None, pywal_light=None, use_pywal=False, schemes=N
608606
timeout_reset()
609607
else:
610608
logging.warning("pywal option enabled but python module is not installed")
611-
# print palette
612-
print_pywal_palette(pywal_colors)
609+
# print palette
610+
print_color_palette(pywal_colors)
613611

614612

615613
def kde_globals_light():
@@ -688,7 +686,7 @@ def sierra_breeze_button_colors(schemes,light=None):
688686
def tup2str(tup):
689687
return ','.join(map(str,tup))
690688

691-
def print_pywal_palette(pywal_colors):
689+
def print_color_palette(pywal_colors):
692690
if USER_HAS_COLR:
693691
i=0
694692
for index, col in pywal_colors['colors'].items():
@@ -697,12 +695,19 @@ def print_pywal_palette(pywal_colors):
697695
print(f'{color(" ",back=hex2rgb(col))}', end='')
698696
i+=1
699697
print(f'{BOLD}')
700-
elif USER_HAS_PYWAL:
701-
logging.debug("Install colr python module to tint color codes and palette as they update")
702-
# Print color palette with pywal
703-
pywal.colors.palette()
704698
else:
705-
logging.info("Install pywal or colr python module to show color schemes")
699+
logging.debug("Install colr python module to tint color codes and palette as they update")
700+
#Print color palette from pywal.colors.palette
701+
for i in range(0, 16):
702+
if i % 8 == 0:
703+
print()
704+
705+
if i > 7:
706+
i = "8;5;%s" % i
707+
708+
print("\033[4%sm%s\033[0m" % (i, " " * (80 // 20)), end="")
709+
print("\n",end="")
710+
706711

707712
def konsole_export_scheme(light=None, pywal_light=None, schemes=None):
708713
if pywal_light != None:

0 commit comments

Comments
 (0)