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

sync

parent 71aefb00
#!/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
[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())
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
titlebar_s = 0.25
if primary_s < 0.85 and primary_l > 0.15:
new_s = primary_s + 0.15
# 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)
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/2)
button_foreground = "255,255,255"
highlight_color = color_triplet(primary_h, 0.8, new_s)
button_background = color_triplet(primary_h, min(primary_l/1.5,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)
......@@ -181,7 +181,7 @@ foreground = "255,255,255"
task_focus = color_triplet(primary_h, min(primary_l/1.25,0.7), new_s/2)
button_foreground = "255,255,255"
highlight_color = color_triplet(primary_h, 0.8, new_s)
button_background = color_triplet(primary_h, min(primary_l/1.5,0.4), new_s)
button_background = color_triplet(primary_h, 0.4, new_s)
titlebar = color_triplet(primary_h, 0.5, titlebar_s)
......
[Colors:Window]
ForegroundNormal=255,255,255
BackgroundNormal=12,20,28
BackgroundNormal=15,24,22
ForegroundNegative=212,84,0
[Colors:Selection]
BackgroundNormal=184,204,223
BackgroundNormal=193,214,210
[Colors:Complimentary]
BackgroundNormal=12,20,28
BackgroundNormal=15,24,22
ForegroundNormal=255,255,255
[Colors:Button]
ForegroundNormal=255,255,255
BackgroundNormal=16,27,37
DecorationFocus=184,204,223
DecorationHover=20,32,44
BackgroundNormal=80,123,114
DecorationFocus=193,214,210
DecorationHover=25,38,35
[Colors:View]
ForegroundNormal=255,255,255
BackgroundNormal=27,30,33
DecorationHover=184,204,223
DecorationFocus=26,32,38
BackgroundNormal=27,33,32
DecorationHover=193,214,210
DecorationFocus=28,35,33
[Colors:Header]
ForegroundNormal=184,204,223
\ No newline at end of file
ForegroundNormal=193,214,210
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -23,9 +23,9 @@
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="2.8738029"
inkscape:cx="55.50293"
inkscape:cy="70.322562"
inkscape:zoom="5.7476058"
inkscape:cx="41.369681"
inkscape:cy="50.93742"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
......@@ -101,7 +101,7 @@
style="opacity:0.6;fill:currentColor;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:2.40910006;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;paint-order:normal" />
<rect
style="opacity:0.6;fill:currentColor;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.60224789;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;paint-order:normal"
class="ColorScheme-ButtonBackground"
class="ColorScheme-ViewHover"
id="hover-bottom"
width="64"
height="4"
......@@ -113,12 +113,12 @@
height="4"
width="64"
id="hover-top"
class="ColorScheme-ButtonBackground"
class="ColorScheme-ViewHover"
style="opacity:0.6;fill:currentColor;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.60224789;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;paint-order:normal" />
<rect
transform="rotate(90)"
style="opacity:0.6;fill:currentColor;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.60224789;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;paint-order:normal"
class="ColorScheme-ButtonBackground"
class="ColorScheme-ViewHover"
id="hover-right"
width="64"
height="4"
......@@ -130,7 +130,7 @@
height="4"
width="64"
id="hover-left"
class="ColorScheme-ButtonBackground"
class="ColorScheme-ViewHover"
style="opacity:0.6;fill:currentColor;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.60224789;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;paint-order:normal"
transform="rotate(90)" />
<rect
......@@ -199,38 +199,12 @@
id="selected+hover-bottomleft"
inkscape:connector-curvature="0"
class="ColorScheme-ViewHover" />
<rect
<path
style="opacity:0.6;fill:currentColor;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.15056875;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;paint-order:normal"
class="ColorScheme-ButtonBackground"
d="m 167.5,906 v 4 h 4 v -3 h -1 v -1 z"
id="hover-topright"
width="4"
height="4"
x="167.5"
y="906" />
<rect
y="906"
x="99.5"
height="4"
width="4"
id="hover-topleft"
class="ColorScheme-ButtonBackground"
style="opacity:0.6;fill:currentColor;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.15056875;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;paint-order:normal" />
<rect
y="974"
x="167.5"
height="4"
width="4"
id="hover-bottomright"
class="ColorScheme-ButtonBackground"
style="opacity:0.6;fill:currentColor;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.15056875;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;paint-order:normal" />
<rect
style="opacity:0.6;fill:currentColor;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.15056875;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;paint-order:normal"
class="ColorScheme-ButtonBackground"
id="hover-bottomleft"
width="4"
height="4"
x="99.5"
y="974" />
inkscape:connector-curvature="0"
class="ColorScheme-ViewHover" />
<rect
y="910"
x="197.45216"
......@@ -305,5 +279,23 @@
height="4"
x="193.45216"
y="974" />
<path
class="ColorScheme-ViewHover"
inkscape:connector-curvature="0"
id="hover-topleft"
d="m 103.5,906 v 4 h -4 v -3 h 1 v -1 z"
style="opacity:0.6;fill:currentColor;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.15056875;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;paint-order:normal" />
<path
class="ColorScheme-ViewHover"
inkscape:connector-curvature="0"
id="hover-bottomright"
d="m 167.5,978 v -4 h 4 v 3 h -1 v 1 z"
style="opacity:0.6;fill:currentColor;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.15056875;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;paint-order:normal" />
<path
class="ColorScheme-ViewHover"
inkscape:connector-curvature="0"
id="hover-bottomleft"
d="m 103.5,978 v -4 h -4 v 3 h 1 v 1 z"
style="opacity:0.6;fill:currentColor;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0.15056875;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;paint-order:normal" />
</g>
</svg>
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