From 53f52341ac29f737ab3f615b49df5d3c3a7e22d4 Mon Sep 17 00:00:00 2001 From: luisbocanegra Date: Tue, 26 Apr 2022 19:37:29 -0500 Subject: [PATCH 1/4] Make script directly executable --- PKGBUILD | 4 +- install-fedora-based.sh | 8 +- install-ubuntu-based.sh | 10 +- kde-material-you-colors | 190 ++++++++++++++++++++++++++++++++++++- kde-material-you-colors.py | 187 ------------------------------------ 5 files changed, 203 insertions(+), 196 deletions(-) delete mode 100644 kde-material-you-colors.py diff --git a/PKGBUILD b/PKGBUILD index 7d7412e..c5d6d35 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -23,13 +23,13 @@ package() { cd "${pkgname}-${pkgver}" install -Dm644 kde-material-you-colors.desktop ${pkgdir}/usr/lib/${pkgname}/kde-material-you-colors.desktop install -Dm644 sample_config.conf ${pkgdir}/usr/lib/${pkgname}/sample_config.conf - install -Dm755 kde-material-you-colors.py ${pkgdir}/usr/lib/${pkgname}/kde-material-you-colors.py - install -Dm755 kde-material-you-colors ${pkgdir}/usr/bin/kde-material-you-colors + install -Dm755 kde-material-you-colors /usr/lib/${pkgname}/kde-material-you-colors install -Dm755 color_utils.py ${pkgdir}/usr/lib/${pkgname}/color_utils.py install -Dm755 utils.py ${pkgdir}/usr/lib/${pkgname}/utils.py install -Dm755 schemeconfigs.py ${pkgdir}/usr/lib/${pkgname}/schemeconfigs.py install -Dm755 material-color-utility-bin ${pkgdir}/usr/lib/${pkgname}/material-color-utility-bin install -Dm755 libSkiaSharp.so ${pkgdir}/usr/lib/${pkgname}/libSkiaSharp.so + ln -s /usr/lib/${pkgname}/kde-material-you-colors ${pkgdir}/usr/bin/kde-material-you-colors ln -s /usr/lib/${pkgname}/material-color-utility-bin ${pkgdir}/usr/bin/material-color-utility install -Dm644 LICENSE ${pkgdir}/usr/share/licenses/${pkgname}/LICENSE } diff --git a/install-fedora-based.sh b/install-fedora-based.sh index 2652214..c477b2f 100644 --- a/install-fedora-based.sh +++ b/install-fedora-based.sh @@ -13,9 +13,12 @@ dnf update dnf install python3 python3-dbus python3-numpy echo -e "${BGreen}Installing kde-material-you-colors${clean}" +# Cleanup +rm -rf /usr/lib/${pkgname} + mkdir -p /usr/lib/${pkgname} cp -f *.{py,conf,desktop} /usr/lib/${pkgname}/ -cp -f kde-material-you-colors /usr/bin/kde-material-you-colors +cp -f kde-material-you-colors /usr/lib/${pkgname}/kde-material-you-colors cp -f material-color-utility-bin /usr/lib/${pkgname}/material-color-utility-bin cp -f libSkiaSharp.so /usr/lib/${pkgname}/libSkiaSharp.so chmod 755 /usr/lib/${pkgname}/*.py @@ -25,7 +28,8 @@ cp -f LICENSE /usr/share/licenses/${pkgname}/LICENSE chmod 664 /usr/share/licenses/${pkgname}/LICENSE chmod 664 /usr/lib/${pkgname}/*.{desktop,conf} -chmod 755 /usr/bin/kde-material-you-colors +chmod 755 /usr/lib/${pkgname}/kde-material-you-colors chmod 755 /usr/lib/${pkgname}/material-color-utility-bin chmod 755 /usr/lib/${pkgname}/libSkiaSharp.so +ln -sf /usr/lib/${pkgname}/kde-material-you-colors /usr/bin/kde-material-you-colors ln -sf /usr/lib/${pkgname}/material-color-utility-bin /usr/bin/material-color-utility diff --git a/install-ubuntu-based.sh b/install-ubuntu-based.sh index 2ec85a0..3c8d950 100644 --- a/install-ubuntu-based.sh +++ b/install-ubuntu-based.sh @@ -13,9 +13,12 @@ apt update apt install python3 python3-dbus python3-numpy echo -e "${BGreen}Installing kde-material-you-colors${clean}" +# Cleanup +rm -rf /usr/lib/${pkgname} + mkdir -p /usr/lib/${pkgname} cp -f *.{py,conf,desktop} /usr/lib/${pkgname}/ -cp -f kde-material-you-colors /usr/bin/kde-material-you-colors +cp -f kde-material-you-colors /usr/lib/${pkgname}/kde-material-you-colors cp -f material-color-utility-bin /usr/lib/${pkgname}/material-color-utility-bin cp -f libSkiaSharp.so /usr/lib/${pkgname}/libSkiaSharp.so chmod 755 /usr/lib/${pkgname}/*.py @@ -25,7 +28,8 @@ cp -f LICENSE /usr/share/licenses/${pkgname}/LICENSE chmod 664 /usr/share/licenses/${pkgname}/LICENSE chmod 664 /usr/lib/${pkgname}/*.{desktop,conf} -chmod 755 /usr/bin/kde-material-you-colors +chmod 755 /usr/lib/${pkgname}/kde-material-you-colors chmod 755 /usr/lib/${pkgname}/material-color-utility-bin chmod 755 /usr/lib/${pkgname}/libSkiaSharp.so -ln -sf /usr/lib/${pkgname}/material-color-utility-bin /usr/bin/material-color-utility \ No newline at end of file +ln -sf /usr/lib/${pkgname}/kde-material-you-colors /usr/bin/kde-material-you-colors +ln -sf /usr/lib/${pkgname}/material-color-utility-bin /usr/bin/material-color-utility diff --git a/kde-material-you-colors b/kde-material-you-colors index f51b1c4..16e3fc8 100644 --- a/kde-material-you-colors +++ b/kde-material-you-colors @@ -1,2 +1,188 @@ -#!/bin/sh -/usr/bin/python3 /usr/lib/kde-material-you-colors/kde-material-you-colors.py "$@" +#!/usr/bin/python3 +import logging +import time +import os +import argparse +import utils +from schemeconfigs import ThemeConfig +if __name__ == '__main__': + # Make sure the schemes path exists + if not os.path.exists(utils.USER_SCHEMES_PATH): + os.makedirs(utils.USER_SCHEMES_PATH) + parser = argparse.ArgumentParser( + description='Automatic Material You Colors Generator from your wallpaper for the Plasma Desktop') + parser.add_argument('--monitor', '-m', type=int, + help='Monitor to get wallpaper (default is 0) but second one is 6 in my case, play with this to find yours', default=None) + parser.add_argument('--plugin', '-p', type=str, + help=f'Wallpaper plugin id (default is {utils.DEFAULT_PLUGIN}) you can find them in: /usr/share/plasma/wallpapers/ or ~/.local/share/plasma/wallpapers', default=None) + parser.add_argument('--file', '-f', type=str, + help='Text file that contains wallpaper absolute path (Takes precedence over the above options)', default=None) + parser.add_argument('--ncolor', '-n', type=int, + help='Alternative color mode (default is 0), some images return more than one color, this will use either the matched or last one', default=None) + parser.add_argument('--light', '-l', action='store_true', + help='Enable Light mode (default is Dark)') + parser.add_argument('--dark', '-d', action='store_true', + help='Enable Dark mode (ignores user config)') + parser.add_argument('--autostart', '-a', action='store_true', + help='Enable (copies) the startup script to automatically start with KDE') + parser.add_argument('--copyconfig', '-c', action='store_true', + help='Copies the default config to ~/.config/kde-material-you-colors/config.conf') + parser.add_argument('--iconslight', type=str, + 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 pywal to theme other apps with Material You') + parser.add_argument('--pywallight', '-wall', action='store_true', + help='Use Light mode for pywal controlled apps') + parser.add_argument('--pywaldark', '-wald', action='store_true', + help='Use Dark mode for pywal controlled apps') + parser.add_argument('--lbmultiplier', '-lbm', type=float, + help='The amount of color for backgrounds in Light mode (value from 0 to 4.0, default is 1)',default=None) + parser.add_argument('--dbmultiplier', '-dbm', type=float, + help='The amount of color for backgrounds in Dark mode (value from 0 to 4.0, default is 1)',default=None) + parser.add_argument('--on-change-hook', type=str, + help='A script/command that will be executed on start or wallpaper/dark/light/settings change',default=None) + parser.add_argument('--sierra-breeze-buttons-color', '-sbb', action='store_true', + help='Tint SierraBreeze decoration buttons') + parser.add_argument('--konsole-profile', '-kp', type=str, + help='The name of your (existing) Konsole profile that is going to be themed, you can check your current profiles with konsole --list-profiles', default=None) + + # Get arguments + args = parser.parse_args() + # Get config from file + config = utils.Configs(args) + options_old = config.options + logging.debug(f"Config: {options_old}") + icons_old = [options_old['iconslight'], options_old['iconsdark']] + light_old = options_old['light'] + # Get the current wallpaper on startup + wallpaper_old = utils.currentWallpaper(options_old) + kde_globals_light_old=utils.kde_globals_light() + pywal_light_old=options_old['pywal_light'] + konsole_profile_old=options_old['konsole_profile'] + konsole_profile_mod_time_old = None + if konsole_profile_old != None: + konsole_profile_mod_time_old = utils.get_last_modification(utils.KONSOLE_DIR+konsole_profile_old+".profile") + if wallpaper_old != None and wallpaper_old[1] != None: + wallpaper_old_type = wallpaper_old[0] + wallpaper_old_data = wallpaper_old[1] + logging.info(f'Using wallpaper: {wallpaper_old_data}') + colors = utils.get_color_schemes(wallpaper_old,options_old['ncolor']) + + # if wallpaper is image save time of last modification + if wallpaper_old_type == "image": + wallpaper_mod_time_old = utils.get_last_modification(wallpaper_old_data) + else: + wallpaper_mod_time_old = None + + light = False + if options_old['light'] == None: + if kde_globals_light_old != None: + light=kde_globals_light_old + else: + light = options_old['light'] + + if colors != None: + schemes = ThemeConfig(colors,wallpaper_old_data,light_blend_multiplier=options_old['lbm'], dark_blend_multiplier=options_old['dbm']) + utils.make_plasma_scheme(schemes=schemes) + utils.apply_color_schemes( + light=light) + if options_old['sierra_breeze_buttons_color'] == True: + utils.sierra_breeze_button_colors(schemes,light) + utils.set_icons(icons_light=options_old['iconslight'], + icons_dark=options_old['iconsdark'], light=options_old['light']) + utils.make_konsole_mirror_profile(konsole_profile_old) + utils.konsole_apply_color_scheme(light,options_old['pywal_light'],schemes,options_old['konsole_profile']) + utils.apply_pywal_schemes( + light=light, use_pywal=options_old['pywal'], pywal_light=options_old['pywal_light'], schemes=schemes) + utils.run_hook(options_old['on_change_hook']) + print("---------------------") + # check wallpaper change + while True: + # reload config file + config = utils.Configs(args) + options_new = config.options + wallpaper_new = utils.currentWallpaper(options_new) + kde_globals_light_new=utils.kde_globals_light() + pywal_light_new=options_new['pywal_light'] + konsole_profile_new=options_new['konsole_profile'] + konsole_profile_mod_time_new = None + if konsole_profile_new != None: + konsole_profile_mod_time_new = utils.get_last_modification(utils.KONSOLE_DIR+konsole_profile_new+".profile") + if wallpaper_new != None and wallpaper_new[1] != None: + wallpaper_new_type = wallpaper_new[0] + wallpaper_new_data = wallpaper_new[1] + + # if wallpaper is image save time of last modification + if wallpaper_new_type == "image": + wallpaper_mod_time_new = utils.get_last_modification(wallpaper_new_data) + else: + wallpaper_mod_time_new = None + + icons_new = [options_new['iconslight'], options_new['iconsdark']] + light_new = options_new['light'] + + wallpaper_changed = wallpaper_old != wallpaper_new + wallpaper_modified = wallpaper_mod_time_old != wallpaper_mod_time_new + options_changed = options_new != options_old + icons_changed = icons_new != icons_old + light_changed = light_new != light_old + kde_globals_light_changed = kde_globals_light_old != kde_globals_light_new + pywal_light_changed = pywal_light_old != pywal_light_new + konsole_profile_changed = konsole_profile_old != konsole_profile_new + konsole_profile_modified = konsole_profile_mod_time_new != konsole_profile_mod_time_old + light=False + if options_new['light'] == None: + if kde_globals_light_new != None: + light=kde_globals_light_new + else: + light = options_new['light'] + if konsole_profile_modified == True or konsole_profile_changed == True: + utils.make_konsole_mirror_profile(konsole_profile_new) + konsole_profile_mod_time_old = konsole_profile_mod_time_new + + if wallpaper_changed or options_changed or wallpaper_modified: + if wallpaper_changed or wallpaper_modified: + logging.info(f'Wallpaper changed: {wallpaper_new_data}') + if options_changed: + logging.debug(f"New Config: {options_new}") + colors = utils.get_color_schemes(wallpaper_new,options_new['ncolor']) + if colors != None: + schemes = ThemeConfig(colors,wallpaper_new_data,light_blend_multiplier=options_new['lbm'], dark_blend_multiplier=options_new['dbm']) + utils.make_plasma_scheme(schemes=schemes) + if options_changed: + if icons_changed or light_changed: + utils.set_icons( + icons_light=options_new['iconslight'], icons_dark=options_new['iconsdark'], light=light) + + utils.apply_color_schemes(light=light) + if options_new['sierra_breeze_buttons_color'] == True: + utils.sierra_breeze_button_colors(schemes,light) + utils.konsole_apply_color_scheme(light,options_new['pywal_light'],schemes,options_new['konsole_profile']) + utils.apply_pywal_schemes( + light=light, use_pywal=options_new['pywal'], pywal_light=options_new['pywal_light'], schemes=schemes) + utils.run_hook(options_new['on_change_hook']) + print("---------------------") + elif kde_globals_light_changed and kde_globals_light_new != None: + if colors != None: + if options_new['sierra_breeze_buttons_color'] == True: + utils.sierra_breeze_button_colors(schemes,kde_globals_light_new) + utils.set_icons(icons_light=options_new['iconslight'], + icons_dark=options_new['iconsdark'], light=kde_globals_light_new) + utils.konsole_apply_color_scheme(light,options_new['pywal_light'],schemes,options_new['konsole_profile']) + utils.apply_pywal_schemes( + light=kde_globals_light_new, use_pywal=options_new['pywal'], pywal_light=options_new['pywal_light'], schemes=schemes) + + utils.run_hook(options_new['on_change_hook']) + print("---------------------") + wallpaper_old = wallpaper_new + wallpaper_mod_time_old = wallpaper_mod_time_new + options_old = options_new + icons_old = icons_new + light_old = light_new + kde_globals_light_old = kde_globals_light_new + pywal_light_old = pywal_light_new + konsole_profile_old = konsole_profile_new + konsole_profile_mod_time_old = konsole_profile_mod_time_new + time.sleep(1) diff --git a/kde-material-you-colors.py b/kde-material-you-colors.py deleted file mode 100644 index 2d95999..0000000 --- a/kde-material-you-colors.py +++ /dev/null @@ -1,187 +0,0 @@ -import logging -import time -import os -import argparse -import utils -from schemeconfigs import ThemeConfig -if __name__ == '__main__': - # Make sure the schemes path exists - if not os.path.exists(utils.USER_SCHEMES_PATH): - os.makedirs(utils.USER_SCHEMES_PATH) - parser = argparse.ArgumentParser( - description='Automatic Material You Colors Generator from your wallpaper for the Plasma Desktop') - parser.add_argument('--monitor', '-m', type=int, - help='Monitor to get wallpaper (default is 0) but second one is 6 in my case, play with this to find yours', default=None) - parser.add_argument('--plugin', '-p', type=str, - help=f'Wallpaper plugin id (default is {utils.DEFAULT_PLUGIN}) you can find them in: /usr/share/plasma/wallpapers/ or ~/.local/share/plasma/wallpapers', default=None) - parser.add_argument('--file', '-f', type=str, - help='Text file that contains wallpaper absolute path (Takes precedence over the above options)', default=None) - parser.add_argument('--ncolor', '-n', type=int, - help='Alternative color mode (default is 0), some images return more than one color, this will use either the matched or last one', default=None) - parser.add_argument('--light', '-l', action='store_true', - help='Enable Light mode (default is Dark)') - parser.add_argument('--dark', '-d', action='store_true', - help='Enable Dark mode (ignores user config)') - parser.add_argument('--autostart', '-a', action='store_true', - help='Enable (copies) the startup script to automatically start with KDE') - parser.add_argument('--copyconfig', '-c', action='store_true', - help='Copies the default config to ~/.config/kde-material-you-colors/config.conf') - parser.add_argument('--iconslight', type=str, - 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 pywal to theme other apps with Material You') - parser.add_argument('--pywallight', '-wall', action='store_true', - help='Use Light mode for pywal controlled apps') - parser.add_argument('--pywaldark', '-wald', action='store_true', - help='Use Dark mode for pywal controlled apps') - parser.add_argument('--lbmultiplier', '-lbm', type=float, - help='The amount of color for backgrounds in Light mode (value from 0 to 4.0, default is 1)',default=None) - parser.add_argument('--dbmultiplier', '-dbm', type=float, - help='The amount of color for backgrounds in Dark mode (value from 0 to 4.0, default is 1)',default=None) - parser.add_argument('--on-change-hook', type=str, - help='A script/command that will be executed on start or wallpaper/dark/light/settings change',default=None) - parser.add_argument('--sierra-breeze-buttons-color', '-sbb', action='store_true', - help='Tint SierraBreeze decoration buttons') - parser.add_argument('--konsole-profile', '-kp', type=str, - help='The name of your (existing) Konsole profile that is going to be themed, you can check your current profiles with konsole --list-profiles', default=None) - - # Get arguments - args = parser.parse_args() - # Get config from file - config = utils.Configs(args) - options_old = config.options - logging.debug(f"Config: {options_old}") - icons_old = [options_old['iconslight'], options_old['iconsdark']] - light_old = options_old['light'] - # Get the current wallpaper on startup - wallpaper_old = utils.currentWallpaper(options_old) - kde_globals_light_old=utils.kde_globals_light() - pywal_light_old=options_old['pywal_light'] - konsole_profile_old=options_old['konsole_profile'] - konsole_profile_mod_time_old = None - if konsole_profile_old != None: - konsole_profile_mod_time_old = utils.get_last_modification(utils.KONSOLE_DIR+konsole_profile_old+".profile") - if wallpaper_old != None and wallpaper_old[1] != None: - wallpaper_old_type = wallpaper_old[0] - wallpaper_old_data = wallpaper_old[1] - logging.info(f'Using wallpaper: {wallpaper_old_data}') - colors = utils.get_color_schemes(wallpaper_old,options_old['ncolor']) - - # if wallpaper is image save time of last modification - if wallpaper_old_type == "image": - wallpaper_mod_time_old = utils.get_last_modification(wallpaper_old_data) - else: - wallpaper_mod_time_old = None - - light = False - if options_old['light'] == None: - if kde_globals_light_old != None: - light=kde_globals_light_old - else: - light = options_old['light'] - - if colors != None: - schemes = ThemeConfig(colors,wallpaper_old_data,light_blend_multiplier=options_old['lbm'], dark_blend_multiplier=options_old['dbm']) - utils.make_plasma_scheme(schemes=schemes) - utils.apply_color_schemes( - light=light) - if options_old['sierra_breeze_buttons_color'] == True: - utils.sierra_breeze_button_colors(schemes,light) - utils.set_icons(icons_light=options_old['iconslight'], - icons_dark=options_old['iconsdark'], light=options_old['light']) - utils.make_konsole_mirror_profile(konsole_profile_old) - utils.konsole_apply_color_scheme(light,options_old['pywal_light'],schemes,options_old['konsole_profile']) - utils.apply_pywal_schemes( - light=light, use_pywal=options_old['pywal'], pywal_light=options_old['pywal_light'], schemes=schemes) - utils.run_hook(options_old['on_change_hook']) - print("---------------------") - # check wallpaper change - while True: - # reload config file - config = utils.Configs(args) - options_new = config.options - wallpaper_new = utils.currentWallpaper(options_new) - kde_globals_light_new=utils.kde_globals_light() - pywal_light_new=options_new['pywal_light'] - konsole_profile_new=options_new['konsole_profile'] - konsole_profile_mod_time_new = None - if konsole_profile_new != None: - konsole_profile_mod_time_new = utils.get_last_modification(utils.KONSOLE_DIR+konsole_profile_new+".profile") - if wallpaper_new != None and wallpaper_new[1] != None: - wallpaper_new_type = wallpaper_new[0] - wallpaper_new_data = wallpaper_new[1] - - # if wallpaper is image save time of last modification - if wallpaper_new_type == "image": - wallpaper_mod_time_new = utils.get_last_modification(wallpaper_new_data) - else: - wallpaper_mod_time_new = None - - icons_new = [options_new['iconslight'], options_new['iconsdark']] - light_new = options_new['light'] - - wallpaper_changed = wallpaper_old != wallpaper_new - wallpaper_modified = wallpaper_mod_time_old != wallpaper_mod_time_new - options_changed = options_new != options_old - icons_changed = icons_new != icons_old - light_changed = light_new != light_old - kde_globals_light_changed = kde_globals_light_old != kde_globals_light_new - pywal_light_changed = pywal_light_old != pywal_light_new - konsole_profile_changed = konsole_profile_old != konsole_profile_new - konsole_profile_modified = konsole_profile_mod_time_new != konsole_profile_mod_time_old - light=False - if options_new['light'] == None: - if kde_globals_light_new != None: - light=kde_globals_light_new - else: - light = options_new['light'] - if konsole_profile_modified == True or konsole_profile_changed == True: - utils.make_konsole_mirror_profile(konsole_profile_new) - konsole_profile_mod_time_old = konsole_profile_mod_time_new - - if wallpaper_changed or options_changed or wallpaper_modified: - if wallpaper_changed or wallpaper_modified: - logging.info(f'Wallpaper changed: {wallpaper_new_data}') - if options_changed: - logging.debug(f"New Config: {options_new}") - colors = utils.get_color_schemes(wallpaper_new,options_new['ncolor']) - if colors != None: - schemes = ThemeConfig(colors,wallpaper_new_data,light_blend_multiplier=options_new['lbm'], dark_blend_multiplier=options_new['dbm']) - utils.make_plasma_scheme(schemes=schemes) - if options_changed: - if icons_changed or light_changed: - utils.set_icons( - icons_light=options_new['iconslight'], icons_dark=options_new['iconsdark'], light=light) - - utils.apply_color_schemes(light=light) - if options_new['sierra_breeze_buttons_color'] == True: - utils.sierra_breeze_button_colors(schemes,light) - utils.konsole_apply_color_scheme(light,options_new['pywal_light'],schemes,options_new['konsole_profile']) - utils.apply_pywal_schemes( - light=light, use_pywal=options_new['pywal'], pywal_light=options_new['pywal_light'], schemes=schemes) - utils.run_hook(options_new['on_change_hook']) - print("---------------------") - elif kde_globals_light_changed and kde_globals_light_new != None: - if colors != None: - if options_new['sierra_breeze_buttons_color'] == True: - utils.sierra_breeze_button_colors(schemes,kde_globals_light_new) - utils.set_icons(icons_light=options_new['iconslight'], - icons_dark=options_new['iconsdark'], light=kde_globals_light_new) - utils.konsole_apply_color_scheme(light,options_new['pywal_light'],schemes,options_new['konsole_profile']) - utils.apply_pywal_schemes( - light=kde_globals_light_new, use_pywal=options_new['pywal'], pywal_light=options_new['pywal_light'], schemes=schemes) - - utils.run_hook(options_new['on_change_hook']) - print("---------------------") - wallpaper_old = wallpaper_new - wallpaper_mod_time_old = wallpaper_mod_time_new - options_old = options_new - icons_old = icons_new - light_old = light_new - kde_globals_light_old = kde_globals_light_new - pywal_light_old = pywal_light_new - konsole_profile_old = konsole_profile_new - konsole_profile_mod_time_old = konsole_profile_mod_time_new - time.sleep(1) From 16b26753052a706c29c6a3870f2ac76f88d0fde9 Mon Sep 17 00:00:00 2001 From: luisbocanegra Date: Tue, 26 Apr 2022 19:46:06 -0500 Subject: [PATCH 2/4] Only allow one instance of the script at the time --- kde-material-you-colors | 2 ++ utils.py | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/kde-material-you-colors b/kde-material-you-colors index 16e3fc8..48664ed 100644 --- a/kde-material-you-colors +++ b/kde-material-you-colors @@ -6,6 +6,8 @@ import argparse import utils from schemeconfigs import ThemeConfig if __name__ == '__main__': + #kill existing instance if found + utils.kill_existing() # Make sure the schemes path exists if not os.path.exists(utils.USER_SCHEMES_PATH): os.makedirs(utils.USER_SCHEMES_PATH) diff --git a/utils.py b/utils.py index ea324e5..406b3ab 100644 --- a/utils.py +++ b/utils.py @@ -875,3 +875,13 @@ def timeout_set(time_s=3): def timeout_reset(): signal.alarm(0) + +def kill_existing(): + get_pids=subprocess.check_output("ps -e -f | grep [/]usr/bin/kde-material-you-colors | awk '{print $2}'", + shell=True, stderr=subprocess.PIPE,universal_newlines=True).strip().splitlines() + current_pid = os.getpid() + for pid in get_pids: + pid = int(pid) + if pid != current_pid: + logging.debug(f"Found existing process with PID: '{pid}' killing...") + subprocess.Popen("kill -9 "+str(pid),shell=True) \ No newline at end of file From b1549076e7d0971644eef3534147af5702160095 Mon Sep 17 00:00:00 2001 From: luisbocanegra Date: Tue, 26 Apr 2022 19:54:48 -0500 Subject: [PATCH 3/4] Update configuration file --- README.md | 24 +++++++++++++----------- sample_config.conf | 23 +++++++++++++---------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 08c07d0..3385df5 100644 --- a/README.md +++ b/README.md @@ -162,7 +162,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 @@ -183,47 +183,49 @@ ncolor = 0 # Commented by default #iconsdark = Papirus-Dark -# Use pywal to theme other programs using Material You colors (experimental) +# Use pywal to theme other programs using Material You colors +# https://github.com/dylanaraps/pywal/wiki/Customization # 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 +# Force light/dark mode for pywal and/or Konsole # Accepted values are True or False comment out to dark/light scheme -# Commented by default +# Commented by default (Follows light option above) +# NOTE: +# Theming konsole only doesn't require pywal, just setting konsole_profile below #pywal_light = False # The amount of perceptible color for backgrounds in dark mode # A number between 0 and 4.0 (limited for accessibility purposes) # Defaults to 1 if not set -light_blend_multiplier = 1.0 +#light_blend_multiplier = 1.0 # The amount of perceptible color for backgrounds in dark mode # A number between 0 and 4.0 (limited for accessibility purposes) # Defaults to 1 if not set -dark_blend_multiplier = 1.0 +#dark_blend_multiplier = 1.0 # A script/command that will be executed on start or wallpaper/dark/light/settings change -# Commented by default -# example below using https://github.com/vlevit/notify-send.sh to send a desktop notification +# example below using https://github.com/vlevit/notify-send.sh to send a desktop notification: #on_change_hook = notify-send.sh "kde-material-you-colors" "This is a test" -t 2000 # Tint SierraBreeze decoration buttons https://github.com/ishovkun/SierraBreeze # Accepted values are True or False # Default is False # NOTE: -# This WILL OVERWRITE any set colors and reload KWin +# This WILL OVERWRITE any set colors and reload KWin (screen will blink on x11) #sierra_breeze_buttons_color = True # Dynamically updated Konsole color scheme # Accepted value is the name of your current Konsole profile, except TempMyou and Default profile as is read only # Default is commented (disabled) -# WARNING: -# I recommend you to backup the ~/.local/share/konsole/ folder before trying this because it will edit your profiles # NOTE: # This makes a temp profile named TempMyou.profile and MaterialYou/MaterialYouAlt color schemes to switch between them automatically in all open Konsole instances # You can make direct changes to your profile, but for the color scheme edit MaterialYou one +# WARNING: +# I recommend you to backup the ~/.local/share/konsole/ folder before trying this because it will edit your profiles #konsole_profile = Profile 1 ``` diff --git a/sample_config.conf b/sample_config.conf index a2d4814..2d87213 100644 --- a/sample_config.conf +++ b/sample_config.conf @@ -42,44 +42,47 @@ ncolor = 0 # Commented by default #iconsdark = Papirus-Dark -# Use pywal to theme other programs using Material You colors (experimental) +# Use pywal to theme other programs using Material You colors +# https://github.com/dylanaraps/pywal/wiki/Customization # 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 +# Force light/dark mode for pywal and/or Konsole # Accepted values are True or False comment out to dark/light scheme -# Commented by default +# Commented by default (Follows light option above) +# NOTE: +# Theming konsole only doesn't require pywal, just setting konsole_profile below #pywal_light = False # The amount of perceptible color for backgrounds in dark mode # A number between 0 and 4.0 (limited for accessibility purposes) # Defaults to 1 if not set -light_blend_multiplier = 1.0 +#light_blend_multiplier = 1.0 # The amount of perceptible color for backgrounds in dark mode # A number between 0 and 4.0 (limited for accessibility purposes) # Defaults to 1 if not set -dark_blend_multiplier = 1.0 +#dark_blend_multiplier = 1.0 # A script/command that will be executed on start or wallpaper/dark/light/settings change -# example below using https://github.com/vlevit/notify-send.sh to send a desktop notification +# example below using https://github.com/vlevit/notify-send.sh to send a desktop notification: #on_change_hook = notify-send.sh "kde-material-you-colors" "This is a test" -t 2000 # Tint SierraBreeze decoration buttons https://github.com/ishovkun/SierraBreeze # Accepted values are True or False # Default is False # NOTE: -# This WILL OVERWRITE any set colors and reload KWin +# This WILL OVERWRITE any set colors and reload KWin (screen will blink on x11) #sierra_breeze_buttons_color = True # Dynamically updated Konsole color scheme # Accepted value is the name of your current Konsole profile, except TempMyou and Default profile as is read only # Default is commented (disabled) -# WARNING: -# I recommend you to backup the ~/.local/share/konsole/ folder before trying this because it will edit your profiles # NOTE: # This makes a temp profile named TempMyou.profile and MaterialYou/MaterialYouAlt color schemes to switch between them automatically in all open Konsole instances # You can make direct changes to your profile, but for the color scheme edit MaterialYou one -#konsole_profile = Profile 1 \ No newline at end of file +# WARNING: +# I recommend you to backup the ~/.local/share/konsole/ folder before trying this because it will edit your profiles +#konsole_profile = Profile 1 From 865262f655118811a142b1f0ef9aba10e5121be3 Mon Sep 17 00:00:00 2001 From: luisbocanegra Date: Tue, 26 Apr 2022 20:13:31 -0500 Subject: [PATCH 4/4] Only kill existing instance if a new one will actually be created --- kde-material-you-colors | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kde-material-you-colors b/kde-material-you-colors index 48664ed..3971e69 100644 --- a/kde-material-you-colors +++ b/kde-material-you-colors @@ -6,8 +6,6 @@ import argparse import utils from schemeconfigs import ThemeConfig if __name__ == '__main__': - #kill existing instance if found - utils.kill_existing() # Make sure the schemes path exists if not os.path.exists(utils.USER_SCHEMES_PATH): os.makedirs(utils.USER_SCHEMES_PATH) @@ -54,6 +52,8 @@ if __name__ == '__main__': args = parser.parse_args() # Get config from file config = utils.Configs(args) + #kill existing instance if found + utils.kill_existing() options_old = config.options logging.debug(f"Config: {options_old}") icons_old = [options_old['iconslight'], options_old['iconsdark']]