Skip to content

Commit

Permalink
Merge pull request #41 from luisbocanegra/dev
Browse files Browse the repository at this point in the history
Add pywal support with Material You Colors
  • Loading branch information
luisbocanegra authored Apr 12, 2022
2 parents 459f786 + c7ac825 commit 42dc79e
Show file tree
Hide file tree
Showing 7 changed files with 278 additions and 33 deletions.
27 changes: 24 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ https://user-images.githubusercontent.com/15076387/162865563-2784fa53-7cc9-4817-
- Dark an Light Color schemes
- Dark and Light Icon theme
- Multiple wallpaper plugins supported
- [Pywal](https://github.com/dylanaraps/pywal) support to theme other programs using Material You Colors (Experimental)

# Installing:
### Arch Linux:
Expand All @@ -46,8 +47,10 @@ sudo ./install-ubuntu-based.sh
chmod +x install-fedora-based.sh
sudo ./install-fedora-based.sh
```
3. OPTIONAL
### Optional features
- Install the [Colr](https://pypi.org/project/Colr/) python module to display colored seed colors from terminal
- Install the [pywal](https://pypi.org/project/pywal/) python module to theme other programs using Material You Colors
- Check [pywal Customization Wiki](https://github.com/dylanaraps/pywal/wiki/Customization) for scripts to theme supported programs

<span style="color:#ff6568"> **You may need to update to latest Plasma 5.24 due to a BUG related to [this one](https://bugs.kde.org/show_bug.cgi?id=445058) that blocks this program from getting the current wallpaper.** </span>

Expand Down Expand Up @@ -81,6 +84,10 @@ sudo ./install-fedora-based.sh

`--iconsdark [ICONS-NAME]`&emsp; Icons for Light scheme

`--pywallight -wall`&emsp; Use pywal Light scheme

`--pywaldark -wald`&emsp; Use pywal Dark scheme

# Startup script:

1. Copy the default configuration to ~/.config/kde-material-you-colors/config.conf:
Expand Down Expand Up @@ -154,10 +161,23 @@ light = False
ncolor = 0

# Light scheme icons
iconslight = Papirus-Light
# Commented by default
#iconslight = Papirus-Light

# Dark scheme icons
iconsdark = Papirus-Dark
# Commented by default
#iconsdark = Papirus-Dark

# Use pywal to theme other programs using Material You colors (experimental)
# You need to install pywal python module first
# Accepted values are True or False
# Commented by default
#pywal=True

# Force light/dark mode for pywal (experimental)
# Accepted values are True or False comment out to dark/light scheme
# Commented by default
#pywal_light = False

```

Expand All @@ -181,3 +201,4 @@ And run `kde-material-you-colors` with no arguments from terminal to test it.
- [@albi005 (Albert Ragány-Németh)](https://github.com/albi005) for the [C# implementation](https://github.com/albi005/MaterialColorUtilities) of Material Color Utilities which I found the easiest to work with.
- [This comment by throwaway6560192 on Reddit](https://www.reddit.com/r/kde/comments/mg6wr4/comment/gssbtqe/?utm_source=share&utm_medium=web2x&context=3) and [@pashazz (Pavel Borisov) ksetwallpaper](https://github.com/pashazz/ksetwallpaper) for the script to get the current Wallpaper that served me as starting point.
- Everyone that made [material-color-utilities](https://github.com/material-foundation/material-color-utilities) possible.
- [Pywal](https://github.com/dylanaraps/pywal) developers
54 changes: 49 additions & 5 deletions color_scheme.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import importlib
from pathlib import Path
import sys
import glob
import os
USER_HAS_PYWAL = importlib.util.find_spec("pywal") is not None
if USER_HAS_PYWAL:
import pywal
from color_utils import blendColors
import subprocess
from schemeconfigs import ThemeConfig
Expand All @@ -12,7 +17,9 @@ class ColorScheme:
def __init__(self, colors):
self._colors = colors

def make_color_schemes(self, light):
def make_color_schemes(self, light=None, pywal_light=None, wallpaper=None, pywal_material=True, use_pywal=False):
wallpaper_type = wallpaper[0]
wallpaper_data = wallpaper[1]
colors = self._colors

# Base text states taken from Breeze Color Scheme
Expand Down Expand Up @@ -57,12 +64,11 @@ def make_color_schemes(self, light):
# Load themes config on the go for now
importlib.reload(sys.modules['schemeconfigs'])
from schemeconfigs import ThemeConfig
schemes = ThemeConfig(colors, extras, base_text_states)
schemes = ThemeConfig(colors, extras, base_text_states,wallpaper_data)

light_scheme=schemes.get_light_scheme()
dark_scheme=schemes.get_dark_scheme()
#subprocess.run("/home/luis/scripts/conky-colors.sh",
# shell=True, stderr=subprocess.DEVNULL,stdout=subprocess.DEVNULL)

# plasma-apply-colorscheme doesnt allow to apply the same theme twice to reload
# since I don't know how to reaload it with code lets make a copy and switch between them
# sadly color settings will show copies too
Expand All @@ -85,4 +91,42 @@ def make_color_schemes(self, light):
shell=True, stderr=subprocess.DEVNULL,stdout=subprocess.DEVNULL)
subprocess.run("plasma-apply-colorscheme "+THEME_DARK_PATH+".colors",
shell=True, stderr=subprocess.PIPE)

if use_pywal != None and use_pywal == True:
if USER_HAS_PYWAL:
if pywal_light != None:
if pywal_light == True:
pywal_colors=schemes.get_wal_light_scheme()
else:
pywal_colors=schemes.get_wal_dark_scheme()
elif light != None:
if light == True:
pywal_colors=schemes.get_wal_light_scheme()
else:
pywal_colors=schemes.get_wal_dark_scheme()
#use material you colors for pywal
if pywal_material:

# Apply the palette to all open terminals.
# Second argument is a boolean for VTE terminals.
# Set it to true if the terminal you're using is
# VTE based. (xfce4-terminal, termite, gnome-terminal.)
#print(pywal_colors)
pywal.sequences.send(pywal_colors, vte_fix=False)

# Export all template files.
pywal.export.every(pywal_colors)

# Reload xrdb, i3 and polybar.
pywal.reload.env()

# TODO: remove this or make it optional
elif wallpaper_data != None:
use_flag = ""
if pywal_light != None:
if pywal_light == True:
use_flag = "-l"
elif light != None:
if light == True:
use_flag = "-l"
subprocess.Popen("/usr/bin/wal -i "+wallpaper_data +" "+use_flag , shell=True, stderr=subprocess.DEVNULL,stdout=subprocess.DEVNULL)

71 changes: 52 additions & 19 deletions kde-material-you-colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
from color_scheme import ColorScheme
from pathlib import Path
from color_utils import rgb2hex
find_colr = importlib.util.find_spec("colr")
USER_HAS_COLR = find_colr is not None

USER_HAS_COLR = importlib.util.find_spec("colr") is not None
if USER_HAS_COLR:
from colr import color

HOME = str(Path.home())
SAMPLE_CONFIG_FILE = "sample_config.conf"
CONFIG_FILE = "config.conf"
Expand Down Expand Up @@ -182,7 +183,8 @@ def get_material_you_colors(wallpaper_data, ncolor, flag):
print(f'Error trying to get colors from {wallpaper_data}')
return None

def set_color_schemes(wallpaper, light, ncolor):
def set_color_schemes(wallpaper, light=None, ncolor=None, pywal=None, pywal_light=None):

""" Display best colors, allow to select alternative color,
and make and apply color schemes for dark and light mode
Expand Down Expand Up @@ -234,18 +236,17 @@ def set_color_schemes(wallpaper, light, ncolor):
colors_json, indent=4, sort_keys=False))

# generate and apply Plasma color schemes
colors_light = ColorScheme(colors_json)
colors_light.make_color_schemes(light)
colors_schemes = ColorScheme(colors_json)
colors_schemes.make_color_schemes(light=light, pywal_light=pywal_light, wallpaper=wallpaper,use_pywal=pywal)

except Exception as e:
print(f'Error:\n {e}')




# else:
# print(
# f'''Error: File "{current_wallpaper}" does not exist''')

else:
print(
f'''Error: Couldn't set schemes with "{wallpaper_data}"''')




def set_icons(icons_light, icons_dark, light):
Expand All @@ -272,7 +273,7 @@ class Configs():
dict: Settings dictionary
"""
def __init__(self, args):
c_light = c_monitor = c_file = c_plugin = c_ncolor = c_iconsdark = c_iconslight = None
c_light = c_monitor = c_file = c_plugin = c_ncolor = c_iconsdark = c_iconslight = c_pywal = c_pywal_light = None
# User may just want to set the startup script / default config, do that only and exit
if args.autostart == True:
if not os.path.exists(USER_AUTOSTART_SCRIPT_PATH):
Expand Down Expand Up @@ -337,13 +338,31 @@ def __init__(self, args):

if 'iconsdark' in custom:
c_iconsdark = custom['iconsdark']

if 'pywal' in custom:
c_pywal = custom.getboolean('pywal')

if 'pywal_light' in custom:
c_pywal_light = custom.getboolean('pywal_light')

if args.dark == True:
c_light = False
elif args.light == True:
c_light = args.light
else:
c_light = c_light

if args.pywal == True:
c_pywal = args.pywal
elif c_pywal != None:
c_pywal = c_pywal

if args.pywaldark == True:
c_pywal_light = False
elif args.pywallight == True:
c_pywal_light = args.pywallight
else:
c_pywal_light = c_pywal_light

if args.file != None:
c_file = args.file
Expand Down Expand Up @@ -396,7 +415,9 @@ def __init__(self, args):
'plugin': c_plugin,
'ncolor': c_ncolor,
'iconslight': c_iconslight,
'iconsdark': c_iconsdark
'iconsdark': c_iconsdark,
"pywal": c_pywal,
"pywal_light": c_pywal_light
}

@property
Expand Down Expand Up @@ -434,6 +455,12 @@ def currentWallpaper(options):
help='Icons for Dark scheme', default=None)
parser.add_argument('--iconsdark', type=str,
help='Icons for Light scheme', default=None)
parser.add_argument('--pywal', '-wal', action='store_true',
help='Use wall to theme other apps')
parser.add_argument('--pywallight', '-wall', action='store_true',
help='Use mode for pywall controlled apps')
parser.add_argument('--pywaldark', '-wald', action='store_true',
help='Use dark mode for pywall controlled apps')

# Get arguments
args = parser.parse_args()
Expand All @@ -457,20 +484,21 @@ def currentWallpaper(options):
wallpaper_mod_time_old = None

print(f'Settting color schemes for {wallpaper_old_data}')
set_color_schemes(wallpaper_old,
options_old['light'], options_old['ncolor'])
set_color_schemes(
wallpaper=wallpaper_old, light=options_old['light'], ncolor=options_old['ncolor'], pywal=options_old['pywal'], pywal_light=options_old['pywal_light'])

set_icons(icons_light=options_old['iconslight'],
icons_dark=options_old['iconsdark'], light=options_old['light'])
#fix borked terminal idk...
print("---------------------")

# check wallpaper change
while True:
# reload config file
config = Configs(args)
options_new = config.options

#print(f"pywal: {options_new['pywal']}")
wallpaper_new = currentWallpaper(options_new)

if wallpaper_new != None and wallpaper_new[1] != None:
wallpaper_new_type = wallpaper_new[0]
wallpaper_new_data = wallpaper_new[1]
Expand All @@ -496,10 +524,15 @@ def currentWallpaper(options):
if icons_changed or light_changed:
set_icons(
icons_light=options_new['iconslight'], icons_dark=options_new['iconsdark'], light=options_new['light'])

if wallpaper_changed or wallpaper_modified:
print(f'Wallpaper changed: {wallpaper_new_data}')

set_color_schemes(
wallpaper_new, options_new['light'], options_new['ncolor'])
wallpaper=wallpaper_new, light=options_new['light'], ncolor=options_new['ncolor'], pywal=options_new['pywal'], pywal_light=options_new['pywal_light'])
#fix borked terminal idk...
print("---------------------")

wallpaper_old = wallpaper_new
wallpaper_mod_time_old = wallpaper_mod_time_new
options_old = options_new
Expand Down
Binary file modified material-color-utility-bin
Binary file not shown.
49 changes: 48 additions & 1 deletion material-color-utility/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,48 @@ static void Main(string[] args)
colors_dark.Add(property.Name, "#" + color.ToString("X")[2..]);
}

// get all tones of core palettes
var primaryTones = new Dictionary<string, string>();
for (int i = 0; i< 100; i++)
{
int color = myCorePalette.Primary[i]!;
primaryTones.Add(Convert.ToString(i), "#" + color.ToString("X")[2..]);
}

var secondaryTones = new Dictionary<string, string>();
for (int i = 0; i< 100; i++)
{
int color = myCorePalette.Secondary[i]!;
secondaryTones.Add(Convert.ToString(i), "#" + color.ToString("X")[2..]);
}

var tertiaryTones = new Dictionary<string, string>();
for (int i = 0; i< 100; i++)
{
int color = myCorePalette.Tertiary[i]!;
tertiaryTones.Add(Convert.ToString(i), "#" + color.ToString("X")[2..]);
}

var neutralTones = new Dictionary<string, string>();
for (int i = 0; i< 100; i++)
{
int color = myCorePalette.Neutral[i]!;
neutralTones.Add(Convert.ToString(i), "#" + color.ToString("X")[2..]);
}

var neutralVariantTones = new Dictionary<string, string>();
for (int i = 0; i< 100; i++)
{
int color = myCorePalette.Neutral[i]!;
neutralVariantTones.Add(Convert.ToString(i), "#" + color.ToString("X")[2..]);
}

string jsonPrimaryTones = JsonConvert.SerializeObject(primaryTones);
string jsonSecondaryTones = JsonConvert.SerializeObject(secondaryTones);
string jsonTertiaryTones = JsonConvert.SerializeObject(tertiaryTones);
string jsonNeutraTones = JsonConvert.SerializeObject(neutralTones);
string jsonNeutralVariantTones = JsonConvert.SerializeObject(neutralVariantTones);

string jsonBestColors = JsonConvert.SerializeObject(bestColors);

// light to json
Expand All @@ -160,7 +202,12 @@ static void Main(string[] args)
Console.WriteLine("{\"bestColors\":" + jsonBestColors + ",");
Console.WriteLine("\"seedColor\":{\"" + seedNo + "\":\"#" + seedColor.ToString("X")[2..] + "\"},");
Console.WriteLine("\"light\":" + jsonLight + ",");
Console.WriteLine("\"dark\":" + jsonDark + "}");
Console.WriteLine("\"dark\":" + jsonDark + ",");
Console.WriteLine("\"primaryTones\":" + jsonPrimaryTones + ",");
Console.WriteLine("\"secondaryTones\":" + jsonSecondaryTones + ",");
Console.WriteLine("\"tertiaryTones\":" + jsonTertiaryTones + ",");
Console.WriteLine("\"neutralTones\":" + jsonNeutraTones + ",");
Console.WriteLine("\"neutralVariantTones\":" + jsonNeutralVariantTones + "}");
}
}
}
19 changes: 16 additions & 3 deletions sample_config.conf
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ monitor = 0
plugin = org.kde.image

# File containing absolute path of an image (Takes precedence over the above options as they are no longer needed)
# Commented out by default
# Commented by default
#file = /tmp/000_eDP-1_current_wallpaper

# Enable Light mode
Expand All @@ -33,7 +33,20 @@ light = False
ncolor = 0

# Light scheme icons
iconslight = Papirus-Light
# Commented by default
#iconslight = Papirus-Light

# Dark scheme icons
iconsdark = Papirus-Dark
# Commented by default
#iconsdark = Papirus-Dark

# Use pywal to theme other programs using Material You colors (experimental)
# You need to install pywal python module first
# Accepted values are True or False
# Commented by default
#pywal=True

# Force light/dark mode for pywal (experimental)
# Accepted values are True or False comment out to dark/light scheme
# Commented by default
#pywal_light = False
Loading

0 comments on commit 42dc79e

Please sign in to comment.