Commit 7867014c authored by phob1an's avatar phob1an 🎧
Browse files

drop colorgram for colorz

parent d3fd57fc
#!/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 colorz
#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
[Colors:Header]
ForegroundNormal=ddd"""
def rgb_to_hex(rgb):
return '%02x%02x%02x' % rgb
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)])
# ---- CullaX ----
# User chooses light or dark
#mode = theme_mode()
# 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 = ""
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.')
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
# 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))
# Resize and write to temp file - massive speedup
#tmp_img = Image.open(wallpaper.rstrip())
#w, h = tmp_img.size
#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, 2)
#primary_h, primary_s, primary_l = [ c/256.0 for c in colors[0].hsl ]
## Cleanup temp file
#os.remove(tmp_img_path)
#print("Primary HSL:\t {}, {}, {} ".format(primary_h, primary_s, primary_l))
# --------------------------------------------------------------------------------
print(wallpaper.rstrip())
try:
image_filename = open(wallpaper.rstrip(), 'rb')
except:
sys.exit("Could not open image file.")
colors_list = colorz.colorz(image_filename)
r,g,b = colors_list[0][0]
print(r,g,b)
primary_h, primary_l, primary_s = colorsys.rgb_to_hls(r/255,g/255,b/255)
print("Colorz HSL:\t {}, {}, {} ".format(primary_h, primary_s, primary_l))
#sys.exit()
# ---------------------------------------------------------------------------------
new_s = primary_s
titlebar_s = 0.25
#if primary_s < 0.85 and primary_s > 0.16 and primary_l > 0.18:
#new_s = primary_s + 0.1
# Remove hue for b/w images
#if primary_s < 0.01:
#titlebar_s = 0.0
#print("new_s ", new_s)
print(primary_h)
panel_background = color_triplet(primary_h, max(primary_l/1.5, 0.2), new_s)
panel_header = color_triplet(primary_h, 0.12, 0.09)
button_hover = color_triplet(primary_h, min(primary_l/1.25, 0.7), new_s)
foreground = "255,255,255"
task_focus = color_triplet(primary_h, min(primary_l/1.25, 0.7), new_s/1.5)
button_foreground = "255,255,255"
highlight_color = color_triplet(primary_h, 0.8, new_s)
button_background = color_triplet(primary_h, 0.4, new_s)
titlebar = color_triplet(primary_h, 0.5, titlebar_s)
#print(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', button_background)
plasma_colors = plasma_colors.replace('ccc', panel_header)
plasma_colors = plasma_colors.replace('ggg', task_focus)
plasma_colors = plasma_colors.replace('hhh', button_hover)
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?")
# 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', highlight_color])
subprocess.run(['kwriteconfig5', '--file=kdeglobals',
'--group=Colors:View',
'--key=DecorationFocus',
button_background])
subprocess.run(['kwriteconfig5', '--file=kdeglobals',
'--group=WM',
'--key=activeBackground',
titlebar])
subprocess.run(['kwriteconfig5', '--file=kdeglobals',
'--group=WM',
'--key=activeForeground',
foreground])
subprocess.run(['kwriteconfig5', '--file=kdeglobals',
'--group=Colors:Button',
'--key=activeForeground',
foreground])
except IOError as e:
sys.exit(e)
......@@ -8,8 +8,7 @@ import subprocess
import time
import colorsys
from PIL import Image
import colorgram
import colorz
#Template for our Plasma theme
......@@ -54,7 +53,7 @@ def notify_user(message):
try:
subprocess.run(['notify-send',
icon,
'--expire-time=3000',
'--expire-time=2000',
message])
except:
pass
......@@ -81,8 +80,6 @@ def color_triplet(h, l, s):
# ---- CullaX ----
# User chooses light or dark
#mode = theme_mode()
# Try sending a notification to show we're working
notify_user("CullaX - Beautifying the Desktop")
......@@ -145,40 +142,34 @@ if not os.path.exists(wallpaper):
sys.exit("I think the wallpaper is {0} but I can't find it."
.format(wallpaper))
try:
image_filename = open(wallpaper.rstrip(), 'rb')
except:
sys.exit("Could not open image file.")
colors_list = colorz.colorz(image_filename, 8)
r,g,b = colors_list[0][0]
#print(r,g,b)
primary_h, primary_l, primary_s = colorsys.rgb_to_hls(r/255,g/255,b/255)
print("Colorz HSL:\t {}, {}, {} ".format(primary_h, primary_s, primary_l))
# Resize and write to temp file - massive speedup
tmp_img = Image.open(wallpaper.rstrip())
tmp_img = tmp_img.resize((512, 512))
tmp_img_path = os.path.expanduser('~/.cullax.png')
tmp_img.save(tmp_img_path)
colors = colorgram.extract(tmp_img_path, 5)
primary_h, primary_s, primary_l = [ c/256.0 for c in colors[0].hsl ]
# Cleanup temp file
os.remove(tmp_img_path)
print("Primary HSL:\t {}, {}, {} ".format(primary_h, primary_s, primary_l))
new_s = 0.0
# ---------------------------------------------------------------------------------
new_s = primary_s
titlebar_s = 0.25
if primary_s < 0.85 and primary_l > 0.15:
new_s = primary_s + 0.15
#if primary_s < 0.85 and primary_s > 0.16 and primary_l > 0.18:
#new_s = primary_s + 0.1
# Remove hue for b/w images
#if primary_s < 0.01:
#titlebar_s = 0.0
panel_background = color_triplet(primary_h, primary_l/2, new_s)
#print("new_s ", new_s)
print(primary_l)
panel_background = color_triplet(primary_h, max(primary_l/2.0, 0.2), primary_s/1.5)
panel_header = color_triplet(primary_h, 0.12, 0.09)
button_hover = color_triplet(primary_h, min(primary_l/1.25,0.7), new_s)
button_hover = color_triplet(primary_h, min(primary_l/1.25, 0.7), new_s)
foreground = "255,255,255"
task_focus = color_triplet(primary_h, min(primary_l/1.25,0.7), new_s/2)
task_focus = color_triplet(primary_h, min(primary_l/1.25, 0.7), new_s/1.5)
button_foreground = "255,255,255"
highlight_color = color_triplet(primary_h, 0.8, new_s)
button_background = color_triplet(primary_h, 0.4, new_s)
......
[Colors:Window]
ForegroundNormal=255,255,255
BackgroundNormal=15,24,22
BackgroundNormal=24,58,77
ForegroundNegative=212,84,0
[Colors:Selection]
BackgroundNormal=193,214,210
BackgroundNormal=164,215,243
[Colors:Complimentary]
BackgroundNormal=15,24,22
BackgroundNormal=24,58,77
ForegroundNormal=255,255,255
[Colors:Button]
ForegroundNormal=255,255,255
BackgroundNormal=80,123,114
DecorationFocus=193,214,210
DecorationHover=25,38,35
BackgroundNormal=23,125,180
DecorationFocus=164,215,243
DecorationHover=18,96,138
[Colors:View]
ForegroundNormal=255,255,255
BackgroundNormal=27,33,32
DecorationHover=193,214,210
DecorationFocus=28,35,33
BackgroundNormal=27,31,33
DecorationHover=164,215,243
DecorationFocus=38,90,118
[Colors:Header]
ForegroundNormal=193,214,210
\ No newline at end of file
ForegroundNormal=164,215,243
\ No newline at end of file
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