Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support for plasma-apply-desktoptheme #16

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/defaults.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ themes:
colorscheme: BreezeLight # Check 'plasma-apply-colorscheme -l' for options
icontheme: breeze
wallpaper: /usr/share/wallpapers/Flow/contents/images/5120x2880.jpg
desktop-theme: breeze-light # Check 'plasma-apply-desktopscheme --list-themes' for options
command: '' # Runs command at theme activation
time: sunrise # Keywords 'sunrise', 'sunset', or ANY correct systemd 'OnCalendar' time
night:
colorscheme: BreezeDark
icontheme: breeze-dark
wallpaper: /usr/share/wallpapers/Flow/contents/images_dark/5120x2880.jpg
desktoptheme: breeze-dark
command: ''
time:
time:
- sunset
october:
wallpaper: /usr/share/wallpapers/FallenLeaf/contents/images/2560x1600.jpg
Expand Down
9 changes: 5 additions & 4 deletions src/kshift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ for name in c.data["themes"]:
time = [time]

for ti in time:
t = theme.Theme(name, colorscheme, icontheme, wallpaper, command, ti, enabled )
t = theme.Theme(name, colorscheme, icontheme, wallpaper, desktoptheme, command, ti, enabled )

themes_dic[name] = t
themes.append(t)
Expand Down Expand Up @@ -181,7 +181,8 @@ parser = argparse.ArgumentParser(description="KDE Theme Switching")
parser.add_argument("-w", "--wallpaper", help="Sets the current wallpaper", type=str, required=False)
parser.add_argument("-c","--colorscheme", type=str,help="Sets the colorscheme", required=False)
parser.add_argument("-i","--icontheme", type=str,help="Sets the icon theme", required=False)
parser.add_argument("-t", "--theme", help="Sets the theme", type=str, choices=list(c.data["themes"].keys()), required=False)
parser.add_argument("-t", "--theme", help="Sets the kshift theme", type=str, choices=list(c.data["themes"].keys()), required=False)
parser.add_argument("-dk", "--desktop_theme", help="Sets the KDE desktop theme", type=str, required=False)


# These cannot be called together
Expand Down Expand Up @@ -214,8 +215,8 @@ else:
if args.theme:
themes_dic[args.theme].kshift()

elif args.colorscheme or args.icontheme or args.wallpaper:
theme.Theme("tmp", args.colorscheme, args.icontheme, args.wallpaper, None, None, None).kshift()
elif args.colorscheme or args.icontheme or args.wallpaper or args.desktop_theme:
theme.Theme("tmp", args.colorscheme, args.icontheme, args.wallpaper, args.desktop_theme, None, None, None).kshift()

else:

Expand Down
15 changes: 12 additions & 3 deletions src/theme.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@

@total_ordering
class Theme:
attributes = ["colorscheme", "icontheme", "wallpaper", "command", "time", "enabled"]
attributes = ["colorscheme", "icontheme", "wallpaper", "desktoptheme", "command", "time", "enabled"]

colorschemes = utils.get_colorschemes()
iconthemes = utils.get_iconthemes()
desktopthemes = utils.get_desktopthemes()

def __init__(self, name, colorscheme, icontheme, wallpaper, command, time, enabled):
def __init__(self, name, colorscheme, icontheme, wallpaper, desktoptheme, command, time, enabled):
self.name = name

if colorscheme is None or self.colorschemes.count(colorscheme) >= 1:
Expand All @@ -35,6 +36,11 @@ def __init__(self, name, colorscheme, icontheme, wallpaper, command, time, enabl
else:
raise ValueError(f"Wallpaper does not exist: {wallpaper}")

if desktoptheme is None or self.desktopthemes.count(desktoptheme) >= 1:
self.desktoptheme = desktoptheme
else:
raise ValueError(f"Theme does not exist: {desktoptheme}")

self.command = command

if time == "sunrise" or time == "sunset":
Expand Down Expand Up @@ -68,7 +74,7 @@ def __le__(self, __o) -> bool:
return False

def __repr__(self) -> str:
return f"Name: {self.name}, ColorScheme: {self.colorscheme}, IconTheme: {self.icontheme}, Wallpaper: {self.wallpaper}, Time: {self.time}\n"
return f"Name: {self.name}, ColorScheme: {self.colorscheme}, IconTheme: {self.icontheme}, Wallpaper: {self.wallpaper}, DesktopTheme: {self.desktoptheme}, Time: {self.time}\n"


###################################
Expand All @@ -91,5 +97,8 @@ def kshift(self):
if (plasma_changeicons is not None):
os.system(f"{plasma_changeicons} {self.icontheme}")

if self.desktoptheme and self.desktoptheme != utils.curr_desktoptheme():
os.system(f"plasma-apply-desktoptheme {self.desktoptheme}")

if self.command:
os.system(self.command)
29 changes: 29 additions & 0 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,32 @@ def systemd_to_datetime(time, today: datetime) -> datetime:
return date


# Gets the names of all available deskop themes
def get_desktopthemes():

arr = []

desktopthemes_cmd = "plasma-apply-desktoptheme --list-themes"
output = subprocess.run(desktopthemes_cmd.split(), stdout=subprocess.PIPE).stdout.decode('utf-8').strip()

for line in output.splitlines():
r = re.search(" \\* ([A-Za-z]*(-[A-Za-z]*)?)", line)
if r:
arr.append(r.group(1))

return arr

# Gets the current desktoptheme
def curr_desktoptheme():
curr = ""

desktoptheme_cmd = "plasma-apply-desktoptheme --list-themes"
output = subprocess.run(desktoptheme_cmd.split(), stdout=subprocess.PIPE).stdout.decode('utf-8').strip()

for line in output.splitlines():
r = re.search(" \\* ([A-Za-z]*(-[A-Za-z]*)?) \\(current theme for the Plasma session\\)", line)
if r:
curr = r.group(1)
break

return curr