Skip to content

Commit

Permalink
Separate settings for system and icon themes (#40)
Browse files Browse the repository at this point in the history
- Add support to use different themes for system and icons
  • Loading branch information
hsbasu authored Nov 8, 2022
1 parent 8dd475a commit 609ad43
Show file tree
Hide file tree
Showing 5 changed files with 388 additions and 257 deletions.
11 changes: 7 additions & 4 deletions src/ThemeManager/DesktopTheme.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def set_desktop_theme(self, state, nexttheme):
# Window border/Metacity
os.system("gsettings set org.cinnamon.desktop.wm.preferences theme %s" % nexttheme[5])
# Icon theme
os.system("gsettings set org.cinnamon.desktop.interface icon-theme %s" % nexttheme[6])
if self.manager.icon_theme:
os.system("gsettings set org.cinnamon.desktop.interface icon-theme %s" % nexttheme[6])
# Cursor theme
if self.manager.cursor_theme:
os.system("gsettings set org.cinnamon.desktop.interface cursor-theme %s" % nexttheme[7])
Expand All @@ -69,7 +70,8 @@ def set_desktop_theme(self, state, nexttheme):
# Window border/Metacity
os.system("gsettings set org.gnome.desktop.wm.preferences theme %s" % nexttheme[5])
# Icon theme
os.system("gsettings set org.gnome.desktop.interface icon-theme %s" % nexttheme[6])
if self.manager.icon_theme:
os.system("gsettings set org.gnome.desktop.interface icon-theme %s" % nexttheme[6])
# Cursor theme
if self.manager.cursor_theme:
os.system("gsettings set org.gnome.desktop.interface cursor-theme %s" % nexttheme[7])
Expand All @@ -87,7 +89,8 @@ def set_desktop_theme(self, state, nexttheme):
# Window border/Metacity
os.system("gsettings set org.mate.Marco.general theme %s" % nexttheme[5])
# Icon theme
os.system("gsettings set org.mate.interface icon-theme %s" % nexttheme[6])
if self.manager.icon_theme:
os.system("gsettings set org.mate.interface icon-theme %s" % nexttheme[6])
# Cursor theme
if self.manager.cursor_theme:
os.system("gsettings set org.mate.peripherals-mouse cursor-theme %s" % nexttheme[7])
Expand Down Expand Up @@ -142,7 +145,7 @@ def get_desktop_theme(self, state, systheme, colvariants):
# Window border/Metacity
currenttheme.append(self.run_command("gsettings get org.mate.Marco.general theme"))
# Icon theme
currenttheme.append(self.run_command("gsettings set org.mate.interface icon-theme"))
currenttheme.append(self.run_command("gsettings get org.mate.interface icon-theme"))
# Cursor theme
currenttheme.append(self.run_command("gsettings get org.mate.peripherals-mouse cursor-theme"))

Expand Down
96 changes: 66 additions & 30 deletions src/ThemeManager/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ def load_config(self):
try:
colvars = self.config["system-theme"]['color-variants'].split(',')
self.systemthemename = self.config["system-theme"]['system-theme-name']
self.iconthemename = self.config["system-theme"]['icon-theme-name']
self.darkmode_suffix = self.config["system-theme"]['dark-mode-suffix']
self.darkermode = self.config["system-theme"].getboolean('darker-mode')
self.darkermode_suffix = self.config["system-theme"]['darker-mode-suffix']
self.theme_name_style = int(self.config["system-theme"]['theme-style-name'])

self.colorvariants = "" # This string will be saved in config file
self.colvariants = [] # This list will be used to randomize variants
Expand All @@ -127,6 +130,21 @@ def load_config(self):
self.colvariants.append(var.strip().strip('"').strip("'"))
self.colorvariants = self.colorvariants.strip(",") # removes the last comma, it looks ugly with the comma

# Icon Theme
self.icon_theme = self.config["system-theme"].getboolean('icon-theme')
self.iconthemename = self.config["system-theme"]['icon-theme-name']
self.icon_darkmode_suffix = self.config["system-theme"]['icon-dark-mode-suffix']
self.icon_theme_name_style = int(self.config["system-theme"]['icon-theme-style-name'])

colvars = self.config["system-theme"]['icon-color-variants'].split(',')
self.icon_colorvariants = "" # This string will be saved in config file
self.icon_colvariants = [] # This list will be used to randomize variants
for var in colvars:
self.icon_colorvariants += str(var+",")
self.icon_colvariants.append(var.strip().strip('"').strip("'"))
self.icon_colorvariants = self.icon_colorvariants.strip(",") # removes the last comma, it looks ugly with the comma

# Cursor Theme
self.cursor_theme = self.config["system-theme"].getboolean('cursor-theme')
self.cursorthemename = self.config["system-theme"]['cursor-theme-name']

Expand All @@ -138,11 +156,6 @@ def load_config(self):
self.cursor_colvariants.append(var.strip().strip('"').strip("'"))
self.cursor_colorvariants = self.cursor_colorvariants.strip(",") # removes the last comma, it looks ugly with the comma

self.theme_name_style = int(self.config["system-theme"]['theme-style-name'])
self.darkmode_suffix = self.config["system-theme"]['dark-mode-suffix']
self.darkermode = self.config["system-theme"].getboolean('darker-mode')
self.darkermode_suffix = self.config["system-theme"]['darker-mode-suffix']

theme_interval = self.config["system-theme"]['theme-interval']
self.theme_interval_HH = int(theme_interval.split(':')[0])
self.theme_interval_MM = int(theme_interval.split(':')[1])
Expand All @@ -152,17 +165,23 @@ def load_config(self):
self.colvariants = []
self.colorvariants = ""
self.systemthemename = ""
self.darkmode_suffix = "Dark"
self.darkermode = False
self.darkermode_suffix = "Darker"
self.theme_name_style = 0

self.icon_theme = True
self.iconthemename = ""
self.icon_darkmode_suffix = "Dark"
self.icon_colvariants = []
self.icon_colorvariants = ""
self.icon_theme_name_style = 0

self.cursor_theme = False
self.cursorthemename = ""
self.cursor_colvariants = []
self.cursor_colorvariants = ""

self.theme_name_style = 0
self.darkmode_suffix = "Dark"
self.darkermode = False
self.darkermode_suffix = "Darker"
self.theme_interval_HH = 1
self.theme_interval_MM = 0
self.theme_interval_SS = 0
Expand All @@ -175,14 +194,18 @@ def save_config(self):
self.config['system-theme'] = {
'color-variants': "",
'system-theme-name': "",
'dark-mode-suffix': "Dark",
'darker-mode': False,
'darker-mode-suffix': "Darker",
'theme-style-name': 0,
'icon-theme': True,
'icon-theme-name': "",
'icon-color-variants': "",
'icon-dark-mode-suffix': "Dark",
'icon-theme-style-name': 0,
'cursor-theme': False,
'cursor-theme-name': "",
'cursor-color-variants': "",
'theme-style-name': 0,
'dark-mode-suffix': "Dark",
'darker-mode': False,
'darker-mode-suffix': "Darker",
'theme-interval': '1:0:0'
}
with open(CONFIG_FILE, 'w') as f:
Expand Down Expand Up @@ -210,35 +233,30 @@ def prep_theme_variants(self, state, theme_styles):
stateflag = 1
module_logger.info("Current State: %s", currentstate)

if self.icon_theme:
icontheme = self.prep_icon_theme(currentstate, currentcolor)

if self.cursor_theme:
cursrtheme = self.prep_cursor_theme(currentcolor)

if currentstate == "daytime":
wmtheme = self.systemthemename
if len(currentcolor) != 0:
shelltheme = self.systemthemename+"-"+currentcolor
icontheme = self.iconthemename+"-"+currentcolor
else:
shelltheme = self.systemthemename
icontheme = self.iconthemename

gtktheme = shelltheme
if self.cursor_theme:
cursrtheme = self.prep_cursor_theme(currentcolor)

elif currentstate == "night":
wmtheme = self.systemthemename+"-"+self.darkmode_suffix
if len(currentcolor) != 0:
if theme_styles[self.theme_name_style] == theme_styles[0]:
shelltheme = self.systemthemename+"-"+self.darkmode_suffix+"-"+currentcolor
icontheme = self.iconthemename+"-"+self.darkmode_suffix+"-"+currentcolor
else:
shelltheme = self.systemthemename+"-"+currentcolor+"-"+self.darkmode_suffix
icontheme = self.iconthemename+"-"+currentcolor+"-"+self.darkmode_suffix
else:
shelltheme = self.systemthemename+"-"+self.darkmode_suffix
icontheme = self.iconthemename+"-"+self.darkmode_suffix

gtktheme = shelltheme
if self.cursor_theme:
cursrtheme = self.prep_cursor_theme(currentcolor)

else:
wmtheme = self.systemthemename+"-"+self.darkmode_suffix
Expand All @@ -255,17 +273,12 @@ def prep_theme_variants(self, state, theme_styles):
gtktheme = self.systemthemename+"-"+currentcolor+"-"+self.darkermode_suffix
else:
gtktheme = self.systemthemename+"-"+currentcolor+"-"+self.darkmode_suffix
icontheme = self.iconthemename+"-"+currentcolor
else:
shelltheme = self.systemthemename+"-"+self.darkmode_suffix
if self.darkermode:
gtktheme = self.systemthemename+"-"+self.darkermode_suffix
else:
gtktheme = self.systemthemename+"-"+self.darkmode_suffix
icontheme = self.iconthemename

if self.cursor_theme:
cursrtheme = self.prep_cursor_theme(currentcolor)

nxt_theme = [timestamp, currentcolor, stateflag, shelltheme, gtktheme, wmtheme, icontheme, cursrtheme]
themes = {}
Expand All @@ -277,6 +290,29 @@ def prep_theme_variants(self, state, theme_styles):
module_logger.debug("Next Colour Variant: %s, Next Themes: %s" % (nxt_theme[1], themes))

return nxt_theme

def prep_icon_theme(self, currentstate, currentcolor):
if currentcolor in self.icon_colvariants:
iconcolor = currentcolor
else:
iconcolor = random.choice(self.icon_colvariants)
module_logger.debug("Icon Colour Variant: %s", iconcolor)
if currentstate == "night":
if len(iconcolor) != 0:
if theme_styles[self.icon_theme_name_style] == theme_styles[0]:
icontheme = self.iconthemename+"-"+self.icon_darkmode_suffix+"-"+iconcolor
else:
icontheme = self.iconthemename+"-"+iconcolor+"-"+self.icon_darkmode_suffix
else:
icontheme = self.iconthemename+"-"+self.icon_darkmode_suffix
else:
# for daytime and transition
if len(iconcolor) != 0:
icontheme = self.iconthemename+"-"+iconcolor
else:
icontheme = self.iconthemename

return icontheme

def prep_cursor_theme(self, currentcolor):
if currentcolor in self.cursor_colvariants:
Expand Down
75 changes: 49 additions & 26 deletions src/ThemeManager/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,26 @@ def __init__(self, application):
# input values
self.color_variants = self.builder.get_object("colour_variants")
self.systemtheme_variants = self.builder.get_object("system_theme_name")
self.icontheme_variants = self.builder.get_object("Icon_theme_name")

self.cursor_theme_name = self.builder.get_object("cursor_theme_name")
self.cursor_colour_variants = self.builder.get_object("cursor_colour_variants")
self.cursor_settings = self.builder.get_object("cursor_settings")

self.darkmode_name = self.builder.get_object("dark_mode_name")
self.darkermode_switch = self.builder.get_object("darker_switch")
self.darkermode_label = self.builder.get_object("darker_mode_label")
self.darkermode_name = self.builder.get_object("darker_mode_name")

self.icon_settings = self.builder.get_object("icon_settings")
self.icon_theme_name = self.builder.get_object("icon_theme_name")
self.icon_colour_variants = self.builder.get_object("icon_colour_variants")
self.icon_darkmode_name = self.builder.get_object("icon_dark_mode_name")

self.cursor_settings = self.builder.get_object("cursor_settings")
self.cursor_theme_name = self.builder.get_object("cursor_theme_name")
self.cursor_colour_variants = self.builder.get_object("cursor_colour_variants")

self.user_interval_HH = self.builder.get_object("hour")
self.user_interval_MM = self.builder.get_object("minute")
self.user_interval_SS = self.builder.get_object("second")

# Buttons
self.icon_switch = self.builder.get_object("icon_switch")
self.cursor_switch = self.builder.get_object("cursor_switch")
self.darkermode_switch = self.builder.get_object("darker_switch")
self.randomize_button = self.builder.get_object("randomize_theme_button")
Expand All @@ -121,13 +126,21 @@ def __init__(self, application):
self.theme_name_style_combo.add_attribute(renderer, "text", 0)
self.theme_name_style_combo.set_model(theme_style_store)

self.icon_theme_name_style_combo = self.builder.get_object("icon_theme_name_style_combo")
renderer = Gtk.CellRendererText()
self.icon_theme_name_style_combo.pack_start(renderer, True)
self.icon_theme_name_style_combo.add_attribute(renderer, "text", 0)
self.icon_theme_name_style_combo.set_model(theme_style_store)

# Widget signals
self.randomize_button.connect("clicked", self.on_random_button)
self.save_button.connect("clicked", self.on_save_button)
# self.quit_button.connect("clicked", self.on_quit)

#TODO: Show entries when cursor and darker switch is clicked
#TODO: Show entries when icon, cursor and darker switch is clicked
# self.icon_switch.connect("notify::active", self.load_conf)
# self.cursor_switch.connect("notify::active", self.load_conf)
# self.darkermode_switch.connect("notify::active", self.load_conf)

# Menubar
accel_group = Gtk.AccelGroup()
Expand Down Expand Up @@ -180,7 +193,26 @@ def load_conf(self):
self.manager.load_config()
self.color_variants.set_text(str(self.manager.colorvariants))
self.systemtheme_variants.set_text(str(self.manager.systemthemename))
self.icontheme_variants.set_text(str(self.manager.iconthemename))
self.darkmode_name.set_text(str(self.manager.darkmode_suffix))
self.darkermode_switch.set_active(self.manager.darkermode)
self.darkermode_name.set_text(str(self.manager.darkermode_suffix))
self.theme_name_style_combo.set_active(self.manager.theme_name_style) # Select 1st category
if self.manager.darkermode:
self.darkermode_label.set_visible(True)
self.darkermode_name.set_visible(True)
else:
self.darkermode_label.set_visible(False)
self.darkermode_name.set_visible(False)

self.icon_switch.set_active(self.manager.icon_theme)
self.icon_theme_name.set_text(str(self.manager.iconthemename))
self.icon_colour_variants.set_text(str(self.manager.icon_colorvariants))
if self.manager.icon_theme:
self.icon_settings.set_visible(True)
else:
self.icon_settings.set_visible(False)
self.icon_darkmode_name.set_text(str(self.manager.icon_darkmode_suffix))
self.icon_theme_name_style_combo.set_active(self.manager.icon_theme_name_style) # Select 1st category

self.cursor_switch.set_active(self.manager.cursor_theme)
self.cursor_theme_name.set_text(str(self.manager.cursorthemename))
Expand All @@ -190,22 +222,9 @@ def load_conf(self):
else:
self.cursor_settings.set_visible(False)

self.darkmode_name.set_text(str(self.manager.darkmode_suffix))
self.darkermode_switch.set_active(self.manager.darkermode)
self.darkermode_name.set_text(str(self.manager.darkermode_suffix))

self.theme_name_style_combo.set_active(self.manager.theme_name_style) # Select 1st category

self.user_interval_HH.set_value(self.manager.theme_interval_HH)
self.user_interval_MM.set_value(self.manager.theme_interval_MM)
self.user_interval_SS.set_value(self.manager.theme_interval_SS)

if self.manager.darkermode:
self.darkermode_label.set_visible(True)
self.darkermode_name.set_visible(True)
else:
self.darkermode_label.set_visible(False)
self.darkermode_name.set_visible(False)

def on_quit(self, widget):
self.application.quit()
Expand Down Expand Up @@ -233,14 +252,18 @@ def on_save_button(self, widget):
self.manager.config['system-theme'] = {
'color-variants': self.color_variants.get_text(),
'system-theme-name': self.systemtheme_variants.get_text(),
'icon-theme-name': self.icontheme_variants.get_text(),
'cursor-theme': self.cursor_switch.get_active(),
'cursor-theme-name': self.cursor_theme_name.get_text(),
'cursor-color-variants': self.cursor_colour_variants.get_text(),
'theme-style-name': self.theme_name_style_combo.get_active(),
'dark-mode-suffix': self.darkmode_name.get_text(),
'darker-mode': self.darkermode_switch.get_active(),
'darker-mode-suffix': self.darkermode_name.get_text(),
'theme-style-name': self.theme_name_style_combo.get_active(),
'icon-theme': self.icon_switch.get_active(),
'icon-theme-name': self.icon_theme_name.get_text(),
'icon-color-variants': self.icon_colour_variants.get_text(),
'icon-dark-mode-suffix': self.icon_darkmode_name.get_text(),
'icon-theme-style-name': self.icon_theme_name_style_combo.get_active(),
'cursor-theme': self.cursor_switch.get_active(),
'cursor-theme-name': self.cursor_theme_name.get_text(),
'cursor-color-variants': self.cursor_colour_variants.get_text(),
'theme-interval': user_interval
}
with open(CONFIG_FILE, 'w') as f:
Expand Down
1 change: 1 addition & 0 deletions src/ThemeManager/tm_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def startdaemons(self):
module_logger.debug("Initiaing state change daemon.")
statechange_daemon = _async(self.on_statechange)
statechange_daemon()
sleep(10)

module_logger.debug("Initiaing auto-change at regular interval daemon.")
autouser_request_daemon = _async(self.on_autouser_request)
Expand Down
Loading

0 comments on commit 609ad43

Please sign in to comment.