11
11
USER_HAS_COLR = importlib .util .find_spec ("colr" ) is not None
12
12
if USER_HAS_COLR :
13
13
from colr import color
14
- USER_HAS_PYWAL = importlib .util .find_spec ("pywal" ) is not None
15
- if USER_HAS_PYWAL :
16
- import pywal
17
14
import logging
18
15
import signal
19
16
HOME = str (Path .home ())
47
44
COLOR_DEBUG = '\033 [94m'
48
45
COLOR_INFO = '\033 [90m'
49
46
LOG_HINT = BOLD + '\033 [97m'
47
+ BOLD_RESET = COLOR_RESET + BOLD
50
48
51
49
# Custom logging format (adapted from https://stackoverflow.com/a/14859558)
52
50
class MyFormatter (logging .Formatter ):
@@ -487,23 +485,22 @@ def get_color_schemes(wallpaper, ncolor=None):
487
485
colors_json = json .loads (materialYouColors )
488
486
489
487
if wallpaper_type != "color" :
490
- best_colors = f'Best colors: '
488
+ best_colors = f'Best colors:'
491
489
492
490
for index , col in colors_json ['bestColors' ].items ():
493
491
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 )} '
495
493
else :
496
- best_colors += f'{ BOLD } { index } :{ col } '
494
+ best_colors += f' { BOLD_RESET } { index } :{ COLOR_INFO } { col } '
497
495
logging .info (best_colors )
498
496
499
497
seed = colors_json ['seedColor' ]
500
498
sedColor = list (seed .values ())[0 ]
501
499
seedNo = list (seed .keys ())[0 ]
502
500
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 )} ' )
504
502
else :
505
- print (BOLD + "Using seed: " +
506
- seedNo + ":" + sedColor + COLOR_RESET )
503
+ logging .info (f'{ BOLD } Using seed: { BOLD_RESET } { seedNo } :{ COLOR_INFO } { sedColor } ' )
507
504
508
505
with open ('/tmp/kde-material-you-colors.json' , 'w' , encoding = 'utf8' ) as current_scheme :
509
506
current_scheme .write (json .dumps (
@@ -572,24 +569,25 @@ def apply_color_schemes(light=False):
572
569
colorscheme_out = subprocess .check_output ("plasma-apply-colorscheme " + color_scheme + ".colors" ,
573
570
shell = True , stderr = subprocess .PIPE ,universal_newlines = True ).strip ()
574
571
logging .info (colorscheme_out )
575
-
572
+
576
573
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
593
591
# On very rare occassions pywal will hang, add a timeout to it
594
592
timeout_set (3 )
595
593
try :
@@ -608,8 +606,8 @@ def apply_pywal_schemes(light=None, pywal_light=None, use_pywal=False, schemes=N
608
606
timeout_reset ()
609
607
else :
610
608
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 )
613
611
614
612
615
613
def kde_globals_light ():
@@ -688,7 +686,7 @@ def sierra_breeze_button_colors(schemes,light=None):
688
686
def tup2str (tup ):
689
687
return ',' .join (map (str ,tup ))
690
688
691
- def print_pywal_palette (pywal_colors ):
689
+ def print_color_palette (pywal_colors ):
692
690
if USER_HAS_COLR :
693
691
i = 0
694
692
for index , col in pywal_colors ['colors' ].items ():
@@ -697,12 +695,19 @@ def print_pywal_palette(pywal_colors):
697
695
print (f'{ color (" " ,back = hex2rgb (col ))} ' , end = '' )
698
696
i += 1
699
697
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 ()
704
698
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
+
706
711
707
712
def konsole_export_scheme (light = None , pywal_light = None , schemes = None ):
708
713
if pywal_light != None :
0 commit comments