|
1 |
| -#!/bin/sh |
2 |
| -/usr/bin/python3 /usr/lib/kde-material-you-colors/kde-material-you-colors.py "$@" |
| 1 | +#!/usr/bin/python3 |
| 2 | +import logging |
| 3 | +import time |
| 4 | +import os |
| 5 | +import argparse |
| 6 | +import utils |
| 7 | +from schemeconfigs import ThemeConfig |
| 8 | +if __name__ == '__main__': |
| 9 | + # Make sure the schemes path exists |
| 10 | + if not os.path.exists(utils.USER_SCHEMES_PATH): |
| 11 | + os.makedirs(utils.USER_SCHEMES_PATH) |
| 12 | + parser = argparse.ArgumentParser( |
| 13 | + description='Automatic Material You Colors Generator from your wallpaper for the Plasma Desktop') |
| 14 | + parser.add_argument('--monitor', '-m', type=int, |
| 15 | + help='Monitor to get wallpaper (default is 0) but second one is 6 in my case, play with this to find yours', default=None) |
| 16 | + parser.add_argument('--plugin', '-p', type=str, |
| 17 | + 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) |
| 18 | + parser.add_argument('--file', '-f', type=str, |
| 19 | + help='Text file that contains wallpaper absolute path (Takes precedence over the above options)', default=None) |
| 20 | + parser.add_argument('--ncolor', '-n', type=int, |
| 21 | + 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) |
| 22 | + parser.add_argument('--light', '-l', action='store_true', |
| 23 | + help='Enable Light mode (default is Dark)') |
| 24 | + parser.add_argument('--dark', '-d', action='store_true', |
| 25 | + help='Enable Dark mode (ignores user config)') |
| 26 | + parser.add_argument('--autostart', '-a', action='store_true', |
| 27 | + help='Enable (copies) the startup script to automatically start with KDE') |
| 28 | + parser.add_argument('--copyconfig', '-c', action='store_true', |
| 29 | + help='Copies the default config to ~/.config/kde-material-you-colors/config.conf') |
| 30 | + parser.add_argument('--iconslight', type=str, |
| 31 | + help='Icons for Dark scheme', default=None) |
| 32 | + parser.add_argument('--iconsdark', type=str, |
| 33 | + help='Icons for Light scheme', default=None) |
| 34 | + parser.add_argument('--pywal', '-wal', action='store_true', |
| 35 | + help='Use pywal to theme other apps with Material You') |
| 36 | + parser.add_argument('--pywallight', '-wall', action='store_true', |
| 37 | + help='Use Light mode for pywal controlled apps') |
| 38 | + parser.add_argument('--pywaldark', '-wald', action='store_true', |
| 39 | + help='Use Dark mode for pywal controlled apps') |
| 40 | + parser.add_argument('--lbmultiplier', '-lbm', type=float, |
| 41 | + help='The amount of color for backgrounds in Light mode (value from 0 to 4.0, default is 1)',default=None) |
| 42 | + parser.add_argument('--dbmultiplier', '-dbm', type=float, |
| 43 | + help='The amount of color for backgrounds in Dark mode (value from 0 to 4.0, default is 1)',default=None) |
| 44 | + parser.add_argument('--on-change-hook', type=str, |
| 45 | + help='A script/command that will be executed on start or wallpaper/dark/light/settings change',default=None) |
| 46 | + parser.add_argument('--sierra-breeze-buttons-color', '-sbb', action='store_true', |
| 47 | + help='Tint SierraBreeze decoration buttons') |
| 48 | + parser.add_argument('--konsole-profile', '-kp', type=str, |
| 49 | + 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) |
| 50 | + |
| 51 | + # Get arguments |
| 52 | + args = parser.parse_args() |
| 53 | + # Get config from file |
| 54 | + config = utils.Configs(args) |
| 55 | + #kill existing instance if found |
| 56 | + utils.kill_existing() |
| 57 | + options_old = config.options |
| 58 | + logging.debug(f"Config: {options_old}") |
| 59 | + icons_old = [options_old['iconslight'], options_old['iconsdark']] |
| 60 | + light_old = options_old['light'] |
| 61 | + # Get the current wallpaper on startup |
| 62 | + wallpaper_old = utils.currentWallpaper(options_old) |
| 63 | + kde_globals_light_old=utils.kde_globals_light() |
| 64 | + pywal_light_old=options_old['pywal_light'] |
| 65 | + konsole_profile_old=options_old['konsole_profile'] |
| 66 | + konsole_profile_mod_time_old = None |
| 67 | + if konsole_profile_old != None: |
| 68 | + konsole_profile_mod_time_old = utils.get_last_modification(utils.KONSOLE_DIR+konsole_profile_old+".profile") |
| 69 | + if wallpaper_old != None and wallpaper_old[1] != None: |
| 70 | + wallpaper_old_type = wallpaper_old[0] |
| 71 | + wallpaper_old_data = wallpaper_old[1] |
| 72 | + logging.info(f'Using wallpaper: {wallpaper_old_data}') |
| 73 | + colors = utils.get_color_schemes(wallpaper_old,options_old['ncolor']) |
| 74 | + |
| 75 | + # if wallpaper is image save time of last modification |
| 76 | + if wallpaper_old_type == "image": |
| 77 | + wallpaper_mod_time_old = utils.get_last_modification(wallpaper_old_data) |
| 78 | + else: |
| 79 | + wallpaper_mod_time_old = None |
| 80 | + |
| 81 | + light = False |
| 82 | + if options_old['light'] == None: |
| 83 | + if kde_globals_light_old != None: |
| 84 | + light=kde_globals_light_old |
| 85 | + else: |
| 86 | + light = options_old['light'] |
| 87 | + |
| 88 | + if colors != None: |
| 89 | + schemes = ThemeConfig(colors,wallpaper_old_data,light_blend_multiplier=options_old['lbm'], dark_blend_multiplier=options_old['dbm']) |
| 90 | + utils.make_plasma_scheme(schemes=schemes) |
| 91 | + utils.apply_color_schemes( |
| 92 | + light=light) |
| 93 | + if options_old['sierra_breeze_buttons_color'] == True: |
| 94 | + utils.sierra_breeze_button_colors(schemes,light) |
| 95 | + utils.set_icons(icons_light=options_old['iconslight'], |
| 96 | + icons_dark=options_old['iconsdark'], light=options_old['light']) |
| 97 | + utils.make_konsole_mirror_profile(konsole_profile_old) |
| 98 | + utils.konsole_apply_color_scheme(light,options_old['pywal_light'],schemes,options_old['konsole_profile']) |
| 99 | + utils.apply_pywal_schemes( |
| 100 | + light=light, use_pywal=options_old['pywal'], pywal_light=options_old['pywal_light'], schemes=schemes) |
| 101 | + utils.run_hook(options_old['on_change_hook']) |
| 102 | + print("---------------------") |
| 103 | + # check wallpaper change |
| 104 | + while True: |
| 105 | + # reload config file |
| 106 | + config = utils.Configs(args) |
| 107 | + options_new = config.options |
| 108 | + wallpaper_new = utils.currentWallpaper(options_new) |
| 109 | + kde_globals_light_new=utils.kde_globals_light() |
| 110 | + pywal_light_new=options_new['pywal_light'] |
| 111 | + konsole_profile_new=options_new['konsole_profile'] |
| 112 | + konsole_profile_mod_time_new = None |
| 113 | + if konsole_profile_new != None: |
| 114 | + konsole_profile_mod_time_new = utils.get_last_modification(utils.KONSOLE_DIR+konsole_profile_new+".profile") |
| 115 | + if wallpaper_new != None and wallpaper_new[1] != None: |
| 116 | + wallpaper_new_type = wallpaper_new[0] |
| 117 | + wallpaper_new_data = wallpaper_new[1] |
| 118 | + |
| 119 | + # if wallpaper is image save time of last modification |
| 120 | + if wallpaper_new_type == "image": |
| 121 | + wallpaper_mod_time_new = utils.get_last_modification(wallpaper_new_data) |
| 122 | + else: |
| 123 | + wallpaper_mod_time_new = None |
| 124 | + |
| 125 | + icons_new = [options_new['iconslight'], options_new['iconsdark']] |
| 126 | + light_new = options_new['light'] |
| 127 | + |
| 128 | + wallpaper_changed = wallpaper_old != wallpaper_new |
| 129 | + wallpaper_modified = wallpaper_mod_time_old != wallpaper_mod_time_new |
| 130 | + options_changed = options_new != options_old |
| 131 | + icons_changed = icons_new != icons_old |
| 132 | + light_changed = light_new != light_old |
| 133 | + kde_globals_light_changed = kde_globals_light_old != kde_globals_light_new |
| 134 | + pywal_light_changed = pywal_light_old != pywal_light_new |
| 135 | + konsole_profile_changed = konsole_profile_old != konsole_profile_new |
| 136 | + konsole_profile_modified = konsole_profile_mod_time_new != konsole_profile_mod_time_old |
| 137 | + light=False |
| 138 | + if options_new['light'] == None: |
| 139 | + if kde_globals_light_new != None: |
| 140 | + light=kde_globals_light_new |
| 141 | + else: |
| 142 | + light = options_new['light'] |
| 143 | + if konsole_profile_modified == True or konsole_profile_changed == True: |
| 144 | + utils.make_konsole_mirror_profile(konsole_profile_new) |
| 145 | + konsole_profile_mod_time_old = konsole_profile_mod_time_new |
| 146 | + |
| 147 | + if wallpaper_changed or options_changed or wallpaper_modified: |
| 148 | + if wallpaper_changed or wallpaper_modified: |
| 149 | + logging.info(f'Wallpaper changed: {wallpaper_new_data}') |
| 150 | + if options_changed: |
| 151 | + logging.debug(f"New Config: {options_new}") |
| 152 | + colors = utils.get_color_schemes(wallpaper_new,options_new['ncolor']) |
| 153 | + if colors != None: |
| 154 | + schemes = ThemeConfig(colors,wallpaper_new_data,light_blend_multiplier=options_new['lbm'], dark_blend_multiplier=options_new['dbm']) |
| 155 | + utils.make_plasma_scheme(schemes=schemes) |
| 156 | + if options_changed: |
| 157 | + if icons_changed or light_changed: |
| 158 | + utils.set_icons( |
| 159 | + icons_light=options_new['iconslight'], icons_dark=options_new['iconsdark'], light=light) |
| 160 | + |
| 161 | + utils.apply_color_schemes(light=light) |
| 162 | + if options_new['sierra_breeze_buttons_color'] == True: |
| 163 | + utils.sierra_breeze_button_colors(schemes,light) |
| 164 | + utils.konsole_apply_color_scheme(light,options_new['pywal_light'],schemes,options_new['konsole_profile']) |
| 165 | + utils.apply_pywal_schemes( |
| 166 | + light=light, use_pywal=options_new['pywal'], pywal_light=options_new['pywal_light'], schemes=schemes) |
| 167 | + utils.run_hook(options_new['on_change_hook']) |
| 168 | + print("---------------------") |
| 169 | + elif kde_globals_light_changed and kde_globals_light_new != None: |
| 170 | + if colors != None: |
| 171 | + if options_new['sierra_breeze_buttons_color'] == True: |
| 172 | + utils.sierra_breeze_button_colors(schemes,kde_globals_light_new) |
| 173 | + utils.set_icons(icons_light=options_new['iconslight'], |
| 174 | + icons_dark=options_new['iconsdark'], light=kde_globals_light_new) |
| 175 | + utils.konsole_apply_color_scheme(light,options_new['pywal_light'],schemes,options_new['konsole_profile']) |
| 176 | + utils.apply_pywal_schemes( |
| 177 | + light=kde_globals_light_new, use_pywal=options_new['pywal'], pywal_light=options_new['pywal_light'], schemes=schemes) |
| 178 | + |
| 179 | + utils.run_hook(options_new['on_change_hook']) |
| 180 | + print("---------------------") |
| 181 | + wallpaper_old = wallpaper_new |
| 182 | + wallpaper_mod_time_old = wallpaper_mod_time_new |
| 183 | + options_old = options_new |
| 184 | + icons_old = icons_new |
| 185 | + light_old = light_new |
| 186 | + kde_globals_light_old = kde_globals_light_new |
| 187 | + pywal_light_old = pywal_light_new |
| 188 | + konsole_profile_old = konsole_profile_new |
| 189 | + konsole_profile_mod_time_old = konsole_profile_mod_time_new |
| 190 | + time.sleep(1) |
0 commit comments