Commit a948bccf authored by phob1an's avatar phob1an 🎧
Browse files

Added debug script to find errors

parent ab982192
#!/usr/bin/python3
"""Culla generates a desktop theme using colours
from the current wallpaper"""
import sys
import os
import subprocess
import time
import colorsys
from PIL import Image
import colorgram
#Template for our Plasma theme
plasma_colors = """[Colors:Window]
ForegroundNormal=bbb
BackgroundNormal=aaa
ForegroundNegative=212,84,0
[Colors:Selection]
BackgroundNormal=ddd
[Colors:Complimentary]
BackgroundNormal=aaa
ForegroundNormal=bbb
[Colors:Button]
ForegroundNormal=eee
BackgroundNormal=fff
DecorationFocus=ddd
DecorationHover=hhh
[Colors:View]
ForegroundNormal=bbb
BackgroundNormal=ccc
DecorationHover=ddd
DecorationFocus=ggg"""
def notify_user(message):
""" Simple notification to show something's happening """
icon_path = os.path.expanduser('~/.local/share/pixmaps/cullax.png')
icon = '--icon={}'.format(icon_path)
try:
subprocess.run(['notify-send',
icon,
'--expire-time=3000',
message])
except:
pass
def color_triplet(h, l, s):
"""Return color triplet to use in colorschemes"""
r, g, b = colorsys.hls_to_rgb(h, l, s)
if r > 1.0:
r = 1.0
r = int(r * 255)
if g > 1.0:
g = 1.0
g = int(g * 255)
if b > 1.0:
r = 1.0
b = int(b * 255)
return ','.join([str(r), str(g), str(b)])
def theme_mode():
"""User chooses light or dark"""
try:
q = subprocess.run(['kdialog', '--radiolist', 'Mode', '1', 'Dark',
'on', '2', 'Light', 'off'], capture_output=True)
mode = q.stdout.decode().strip()
except:
mode = 1
return mode
# ---- CullaX ----
print("----\n\tAsk for light or dark using KDialog")
mode = 0
# User chooses light or dark
mode = theme_mode()
if not mode:
sys.exit("Cancelled by user.")
# Try sending a notification to show we're working
notify_user("CullaX - Beautifying the Desktop ;) ")
# Raise flag when finding correct session in plasmarc
flag = False
# Holder for current activity ID
activity = ""
print("----\n\tLooking for Plasma config", end="... ")
try:
with open(os.path.expanduser(
'~/.config/plasma-org.kde.plasma.desktop-appletsrc')) as f:
plasmaconfig = f.readlines()
except:
sys.exit('Unable to find plasma config.')
print("found.")
print("----\n\tLooking for Activities config", end="... ")
try:
with open(os.path.expanduser('~/.config/kactivitymanagerdrc')) as f:
activityrc = f.readlines()
except:
print('Unable to find kactivity manager rc. Presuming only default activity.')
activityrc = None
flag = True # There is only default activity
print("maybe found but continuing anyway.")
# Retrieve current activity
if activityrc is not None:
a = [a for a in activityrc if 'current' in a]
a = a[0].split('=')
activity = a[1].rstrip()
# Flag if wallpaper is found
found = False
# Find current activity then grab next Image= key
for line in plasmaconfig:
if activity in line:
flag = True
if 'Image=' in line and flag:
found = True
break
if not found:
notify_user(
"""You need to set your own wallpaper\n\
before I can work."""
)
sys.exit("I didn't find your wallpaper. Have you set one yet?")
#tmp, wallpaper = line.split('//')
line = line[6:]
if line[0] == 'f':
line = line[7:]
wallpaper = line.strip()
if not os.path.exists(wallpaper):
notify_user("I can't your wallpaper."
.format(wallpaper))
sys.exit("I think the wallpaper is {0} but I can't find it."
.format(wallpaper))
print("----\n\tGot the wallpaper.")
# Resize and write to temp file - massive speedup
tmp_img = Image.open(wallpaper.rstrip())
tmp_img = tmp_img.resize((256, 256))
tmp_img_path = os.path.expanduser('~/.cullax.png')
tmp_img.save(tmp_img_path)
colors = colorgram.extract(tmp_img_path, 6)
sat = 0
hb,sb,lb = [ c/255.0 for c in colors[0].hsl ]
colors.sort(key=lambda c: c.hsl.s)
h,s,l = [ c/255.0 for c in colors[len(colors) - 1].hsl ]
# Cleanup temp file
os.remove(tmp_img_path)
# Remove hue for b/w images
if s < 0.011:
s = 0.0
h = 0.0
if mode == '1':
panel_background = color_triplet(hb, 0.15, 0.12)
panel_header = color_triplet(hb, 0.12, 0.09)
button_hover = color_triplet(h, 0.2, s)
foreground = "252,252,252"
task_focus = "112,112,112"
button_foreground = "252,252,252"
highlight_color = color_triplet(h, 0.88, 1)
midlight = color_triplet(h, 0.5, 0.5)
elif mode == '2':
panel_background = color_triplet(hb, 0.96, 0.5)
panel_header = color_triplet(hb, 1, 0.83)
task_focus = "255,255,255"
foreground = "72,72,72"
button_foreground = "64,64,64"
button_hover = color_triplet(h, 0.9, s)
highlight_color = color_triplet(h, 0.6, 0.85)
midlight = color_triplet(h, 0.77, 0.6)
else:
sys.exit("Well that didn't go well.")
print("----\n\tThe base color is (RGB): {}".format(panel_background))
# Write the colorscheme
plasma_colors = plasma_colors.replace('aaa', panel_background)
plasma_colors = plasma_colors.replace('bbb', foreground)
plasma_colors = plasma_colors.replace('ddd', highlight_color)
plasma_colors = plasma_colors.replace('eee', button_foreground)
plasma_colors = plasma_colors.replace('fff', midlight)
plasma_colors = plasma_colors.replace('ccc', panel_header)
plasma_colors = plasma_colors.replace('ggg', task_focus)
plasma_colors = plasma_colors.replace('hhh', button_hover)
print("----\n\tOpening CullaX template", end="... ")
try:
with open(os.path.expanduser(
'~/.local/share/plasma/desktoptheme/CullaX/colors'), 'w') as f:
f.write(plasma_colors)
except:
sys.exit("Unable to open Culla Plasma colors. Is it installed?")
print("done.")
print("----\n\tCalling kwriteconfig5 to apply changes.")
# Call kwriteconfig5 to change Plasma theme
try:
subprocess.run(['kwriteconfig5', '--file=plasmarc',
'--group=Theme', '--key=name', 'Default'])
# Do this too quickly and Plasma won't reload
time.sleep(0.8)
subprocess.run(['kwriteconfig5', '--file=plasmarc',
'--group=Theme', '--key=name', 'CullaX'])
except IOError as e:
sys.exit(e)
# ---- Set Global Colours ----
try:
subprocess.run(['kwriteconfig5', '--file=kdeglobals',
'--group=Colors:Selection',
'--key=BackgroundNormal', midlight])
subprocess.run(['kwriteconfig5', '--file=kdeglobals',
'--group=Colors:View',
'--key=DecorationFocus',
midlight])
#subprocess.run(['kwriteconfig5', '--file=kdeglobals',
#'--group=WM',
#'--key=activeBackground',
#midlight_color])
#subprocess.run(['kwriteconfig5', '--file=kdeglobals',
#'--group=WM',
#'--key=activeForeground',
#foreground])
except IOError as e:
sys.exit(e)
print("\nCullaX has completed successfully.")
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment