Skip to content

Commit 010afe3

Browse files
authored
Separate options for plank themes (#45)
1 parent dfb786d commit 010afe3

File tree

4 files changed

+307
-16
lines changed

4 files changed

+307
-16
lines changed

src/ThemeManager/DesktopTheme.py

+28-15
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,12 @@ def set_desktop_theme(self, state, nexttheme):
5555
if self.manager.cursor_theme:
5656
os.system("gsettings set org.cinnamon.desktop.interface cursor-theme %s" % nexttheme[7])
5757

58-
# plank theme
59-
try:
60-
os.system("gsettings set net.launchpad.plank.dock.settings theme %s" % nexttheme[3])
61-
except:
62-
module_logger.error("Either 'plank' is not installed or the plank theme is not present.")
58+
# Plank theme
59+
if self.manager.plank_theme:
60+
try:
61+
os.system("gsettings set net.launchpad.plank.dock.settings theme %s" % nexttheme[8])
62+
except:
63+
module_logger.error("Either 'plank' is not installed or the plank theme is not present.")
6364

6465
elif (thisDE == "gnome" or thisDE == "ubuntu:gnome" or thisDE == "unity"):
6566
# When the DE is gnome set
@@ -76,11 +77,12 @@ def set_desktop_theme(self, state, nexttheme):
7677
if self.manager.cursor_theme:
7778
os.system("gsettings set org.gnome.desktop.interface cursor-theme %s" % nexttheme[7])
7879

79-
# plank theme
80-
try:
81-
os.system("gsettings set net.launchpad.plank.dock.settings theme %s" % nexttheme[3])
82-
except:
83-
module_logger.error("Either 'plank' is not installed or the plank theme is not present.")
80+
# Plank theme
81+
if self.manager.plank_theme:
82+
try:
83+
os.system("gsettings set net.launchpad.plank.dock.settings theme %s" % nexttheme[8])
84+
except:
85+
module_logger.error("Either 'plank' is not installed or the plank theme is not present.")
8486

8587
elif (thisDE == "mate"):
8688
# When the DE is mate set
@@ -95,18 +97,20 @@ def set_desktop_theme(self, state, nexttheme):
9597
if self.manager.cursor_theme:
9698
os.system("gsettings set org.mate.peripherals-mouse cursor-theme %s" % nexttheme[7])
9799

98-
# plank theme
99-
try:
100-
os.system("gsettings set net.launchpad.plank.dock.settings theme %s" % nexttheme[3])
101-
except:
102-
module_logger.error("Either 'plank' is not installed or the plank theme is not present")
100+
# Plank theme
101+
if self.manager.plank_theme:
102+
try:
103+
os.system("gsettings set net.launchpad.plank.dock.settings theme %s" % nexttheme[8])
104+
except:
105+
module_logger.error("Either 'plank' is not installed or the plank theme is not present")
103106

104107
themes = {}
105108
themes["System"] = nexttheme[4]
106109
themes["DE Theme"] = nexttheme[3]
107110
themes["Decoration"] = nexttheme[5]
108111
themes["Icon"] = nexttheme[6]
109112
themes["Cursor"] = nexttheme[7]
113+
themes["Plank"] = nexttheme[8]
110114
module_logger.info("Updated with Colour Variant: %s, Themes: %s" % (nexttheme[1], themes))
111115

112116
def get_desktop_theme(self, state, systheme, colvariants):
@@ -126,6 +130,9 @@ def get_desktop_theme(self, state, systheme, colvariants):
126130
themes["Icon"] = self.run_command("gsettings get org.cinnamon.desktop.interface icon-theme")
127131
# Cursor theme
128132
themes["Cursor"] = self.run_command("gsettings get org.cinnamon.desktop.interface cursor-theme")
133+
# Plank theme
134+
if self.manager.plank_theme:
135+
themes["Plank"] = self.run_command("gsettings get net.launchpad.plank.dock.settings theme")
129136

130137
elif (thisDE == "gnome" or thisDE == "ubuntu:gnome" or thisDE == "unity"):
131138
# When the DE is gnome/unity get
@@ -137,6 +144,9 @@ def get_desktop_theme(self, state, systheme, colvariants):
137144
themes["Icon"] = self.run_command("gsettings get org.gnome.desktop.interface icon-theme")
138145
# Cursor theme
139146
themes["Cursor"] = self.run_command("gsettings get org.gnome.desktop.interface cursor-theme")
147+
# Plank theme
148+
if self.manager.plank_theme:
149+
themes["Plank"] = self.run_command("gsettings get net.launchpad.plank.dock.settings theme")
140150

141151
elif (thisDE == "mate"):
142152
# When the DE is mate get
@@ -148,6 +158,9 @@ def get_desktop_theme(self, state, systheme, colvariants):
148158
currenttheme.append(self.run_command("gsettings get org.mate.interface icon-theme"))
149159
# Cursor theme
150160
currenttheme.append(self.run_command("gsettings get org.mate.peripherals-mouse cursor-theme"))
161+
# Plank theme
162+
if self.manager.plank_theme:
163+
themes["Plank"] = self.run_command("gsettings get net.launchpad.plank.dock.settings theme")
151164

152165
currenttheme["Themes"] = themes
153166

src/ThemeManager/common.py

+57-1
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,20 @@ def load_config(self):
156156
self.cursor_colvariants.append(var.strip().strip('"').strip("'"))
157157
self.cursor_colorvariants = self.cursor_colorvariants.strip(",") # removes the last comma, it looks ugly with the comma
158158

159+
# Plank Theme
160+
self.plank_theme = self.config["system-theme"].getboolean('plank-theme')
161+
self.plankthemename = self.config["system-theme"]['plank-theme-name']
162+
self.plank_darkmode_suffix = self.config["system-theme"]['plank-dark-mode-suffix']
163+
self.plank_theme_name_style = int(self.config["system-theme"]['plank-theme-style-name'])
164+
165+
colvars = self.config["system-theme"]['plank-color-variants'].split(',')
166+
self.plank_colorvariants = "" # This string will be saved in config file
167+
self.plank_colvariants = [] # This list will be used to randomize variants
168+
for var in colvars:
169+
self.plank_colorvariants += str(var+",")
170+
self.plank_colvariants.append(var.strip().strip('"').strip("'"))
171+
self.plank_colorvariants = self.plank_colorvariants.strip(",") # removes the last comma, it looks ugly with the comma
172+
159173
theme_interval = self.config["system-theme"]['theme-interval']
160174
self.theme_interval_HH = int(theme_interval.split(':')[0])
161175
self.theme_interval_MM = int(theme_interval.split(':')[1])
@@ -182,6 +196,13 @@ def load_config(self):
182196
self.cursor_colvariants = []
183197
self.cursor_colorvariants = ""
184198

199+
self.plank_theme = False
200+
self.plankthemename = ""
201+
self.plank_darkmode_suffix = "Dark"
202+
self.plank_colvariants = []
203+
self.plank_colorvariants = ""
204+
self.plank_theme_name_style = 0
205+
185206
self.theme_interval_HH = 1
186207
self.theme_interval_MM = 0
187208
self.theme_interval_SS = 0
@@ -206,6 +227,11 @@ def save_config(self):
206227
'cursor-theme': False,
207228
'cursor-theme-name': "",
208229
'cursor-color-variants': "",
230+
'plank-theme': False,
231+
'plank-theme-name': "",
232+
'plank-color-variants': "",
233+
'plank-dark-mode-suffix': "Dark",
234+
'plank-theme-style-name': 0,
209235
'theme-interval': '1:0:0'
210236
}
211237
with open(CONFIG_FILE, 'w') as f:
@@ -239,6 +265,9 @@ def prep_theme_variants(self, state, theme_styles):
239265
if self.cursor_theme:
240266
cursrtheme = self.prep_cursor_theme(currentcolor)
241267

268+
if self.plank_theme:
269+
planktheme = self.prep_plank_theme(currentstate, currentcolor)
270+
242271
if currentstate == "daytime":
243272
wmtheme = self.systemthemename
244273
if len(currentcolor) != 0:
@@ -280,13 +309,14 @@ def prep_theme_variants(self, state, theme_styles):
280309
else:
281310
gtktheme = self.systemthemename+"-"+self.darkmode_suffix
282311

283-
nxt_theme = [timestamp, currentcolor, stateflag, shelltheme, gtktheme, wmtheme, icontheme, cursrtheme]
312+
nxt_theme = [timestamp, currentcolor, stateflag, shelltheme, gtktheme, wmtheme, icontheme, cursrtheme, planktheme]
284313
themes = {}
285314
themes["System"] = gtktheme
286315
themes["DE Theme"] = shelltheme
287316
themes["Decoration"] = wmtheme
288317
themes["Icon"] = icontheme
289318
themes["Cursor"] = cursrtheme
319+
themes["Plank"] = planktheme
290320
module_logger.debug("Next Colour Variant: %s, Next Themes: %s" % (nxt_theme[1], themes))
291321

292322
return nxt_theme
@@ -340,6 +370,32 @@ def prep_cursor_theme(self, currentcolor):
340370

341371
module_logger.debug("Cursor Theme: %s, Colour Variant: %s" % (cursrtheme, cursrcolor))
342372
return cursrtheme
373+
374+
def prep_plank_theme(self, currentstate, currentcolor):
375+
for color in self.plank_colvariants:
376+
if currentcolor.lower() in color.lower():
377+
plankcolor = color
378+
break
379+
else:
380+
plankcolor = random.choice(self.plank_colvariants)
381+
module_logger.debug("Plank Colour Variant: %s", plankcolor)
382+
if currentstate == "night":
383+
if len(plankcolor) != 0:
384+
if theme_styles[self.plank_theme_name_style] == theme_styles[0]:
385+
planktheme = self.plankthemename+"-"+self.plank_darkmode_suffix+"-"+plankcolor
386+
else:
387+
planktheme = self.plankthemename+"-"+plankcolor+"-"+self.plank_darkmode_suffix
388+
else:
389+
planktheme = self.plankthemename+"-"+self.plank_darkmode_suffix
390+
else:
391+
# for daytime and transition
392+
if len(plankcolor) != 0:
393+
planktheme = self.plankthemename+"-"+plankcolor
394+
else:
395+
planktheme = self.plankthemename
396+
397+
module_logger.debug("Plank Theme: %s, Colour Variant: %s" % (planktheme, plankcolor))
398+
return planktheme
343399

344400
if __name__ == "__main__":
345401
pass

src/ThemeManager/gui.py

+27
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ def __init__(self, application):
100100
self.icon_colour_variants = self.builder.get_object("icon_colour_variants")
101101
self.icon_darkmode_name = self.builder.get_object("icon_dark_mode_name")
102102

103+
self.plank_settings = self.builder.get_object("plank_settings")
104+
self.plank_theme_name = self.builder.get_object("plank_theme_name")
105+
self.plank_colour_variants = self.builder.get_object("plank_colour_variants")
106+
self.plank_darkmode_name = self.builder.get_object("plank_dark_mode_name")
107+
103108
self.cursor_settings = self.builder.get_object("cursor_settings")
104109
self.cursor_theme_name = self.builder.get_object("cursor_theme_name")
105110
self.cursor_colour_variants = self.builder.get_object("cursor_colour_variants")
@@ -111,6 +116,7 @@ def __init__(self, application):
111116
# Buttons
112117
self.icon_switch = self.builder.get_object("icon_switch")
113118
self.cursor_switch = self.builder.get_object("cursor_switch")
119+
self.plank_switch = self.builder.get_object("plank_switch")
114120
self.darkermode_switch = self.builder.get_object("darker_switch")
115121
self.randomize_button = self.builder.get_object("randomize_theme_button")
116122
self.save_button = self.builder.get_object("save_button")
@@ -132,6 +138,12 @@ def __init__(self, application):
132138
self.icon_theme_name_style_combo.add_attribute(renderer, "text", 0)
133139
self.icon_theme_name_style_combo.set_model(theme_style_store)
134140

141+
self.plank_theme_name_style_combo = self.builder.get_object("plank_theme_name_style_combo")
142+
renderer = Gtk.CellRendererText()
143+
self.plank_theme_name_style_combo.pack_start(renderer, True)
144+
self.plank_theme_name_style_combo.add_attribute(renderer, "text", 0)
145+
self.plank_theme_name_style_combo.set_model(theme_style_store)
146+
135147
# Widget signals
136148
self.randomize_button.connect("clicked", self.on_random_button)
137149
self.save_button.connect("clicked", self.on_save_button)
@@ -222,6 +234,16 @@ def load_conf(self):
222234
else:
223235
self.cursor_settings.set_visible(False)
224236

237+
self.plank_switch.set_active(self.manager.plank_theme)
238+
self.plank_theme_name.set_text(str(self.manager.plankthemename))
239+
self.plank_colour_variants.set_text(str(self.manager.plank_colorvariants))
240+
if self.manager.plank_theme:
241+
self.plank_settings.set_visible(True)
242+
else:
243+
self.plank_settings.set_visible(False)
244+
self.plank_darkmode_name.set_text(str(self.manager.plank_darkmode_suffix))
245+
self.plank_theme_name_style_combo.set_active(self.manager.plank_theme_name_style) # Select 1st category
246+
225247
self.user_interval_HH.set_value(self.manager.theme_interval_HH)
226248
self.user_interval_MM.set_value(self.manager.theme_interval_MM)
227249
self.user_interval_SS.set_value(self.manager.theme_interval_SS)
@@ -264,6 +286,11 @@ def on_save_button(self, widget):
264286
'cursor-theme': self.cursor_switch.get_active(),
265287
'cursor-theme-name': self.cursor_theme_name.get_text(),
266288
'cursor-color-variants': self.cursor_colour_variants.get_text(),
289+
'plank-theme': self.plank_switch.get_active(),
290+
'plank-theme-name': self.plank_theme_name.get_text(),
291+
'plank-color-variants': self.plank_colour_variants.get_text(),
292+
'plank-dark-mode-suffix': self.plank_darkmode_name.get_text(),
293+
'plank-theme-style-name': self.plank_theme_name_style_combo.get_active(),
267294
'theme-interval': user_interval
268295
}
269296
with open(CONFIG_FILE, 'w') as f:

0 commit comments

Comments
 (0)