Skip to content

Commit e5cd5ee

Browse files
committed
feat: Add support for image and color at the same time
1 parent dcb248c commit e5cd5ee

File tree

3 files changed

+58
-27
lines changed

3 files changed

+58
-27
lines changed

azote/images/empty_btn.png

6.49 KB
Loading

azote/main.py

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,11 @@ def __init__(self, name, width, height, path=None, thumb=None, xrandr_idx=None):
247247

248248
self.img = Gtk.Image.new_from_pixbuf(pixbuf)
249249

250+
if path is None:
251+
self.img_selected = False
252+
else:
253+
self.img_selected = True
254+
250255
self.select_button = Gtk.Button()
251256
self.select_button.set_always_show_image(True)
252257
self.select_button.set_label("{} ({} x {})".format(name, width, height)) # label on top: name (with x height)
@@ -276,6 +281,13 @@ def __init__(self, name, width, height, path=None, thumb=None, xrandr_idx=None):
276281
options_box.set_orientation(Gtk.Orientation.HORIZONTAL)
277282
self.pack_start(options_box, True, False, 0)
278283

284+
self.not_wallpaper_button = Gtk.Button()
285+
img = Gtk.Image()
286+
img.set_from_file('images/empty_btn.png')
287+
self.not_wallpaper_button.set_image(img)
288+
self.not_wallpaper_button.connect("clicked", self.on_not_wallpaper_button)
289+
options_box.pack_start(self.not_wallpaper_button, False, False, 0)
290+
279291
check_button = Gtk.CheckButton()
280292
check_button.set_active(self.include)
281293
check_button.set_tooltip_text(common.lang["include_when_splitting"])
@@ -333,12 +345,14 @@ def clear_color_selection(self):
333345
def on_select_button(self, button):
334346
if common.selected_wallpaper:
335347
self.img.set_from_file(common.selected_wallpaper.thumb_file)
348+
self.img_selected = True
336349
self.wallpaper_path = common.selected_wallpaper.source_path
337350
self.thumbnail_path = common.selected_wallpaper.thumb_file
338351
button.set_property("name", "display-btn-selected")
339352
self.flip_button.set_sensitive(True)
340353

341-
self.clear_color_selection()
354+
# When select a new wallpaper, not clear color selection
355+
#self.clear_color_selection()
342356

343357
common.apply_button.set_sensitive(True)
344358

@@ -359,7 +373,8 @@ def on_mode_combo_changed(self, combo):
359373
def on_color_chosen(self, user_data, button):
360374
self.color = rgba_to_hex(button.get_rgba())
361375
# clear selected image to indicate it won't be used
362-
self.img.set_from_file("images/empty.png")
376+
# self.img.set_from_file("images/empty.png")
377+
# self.img_selected = False
363378
common.apply_button.set_sensitive(True)
364379

365380
def on_flip_button(self, button):
@@ -370,6 +385,13 @@ def on_flip_button(self, button):
370385
self.thumbnail_path = images[0]
371386
self.flip_button.set_sensitive(False)
372387

388+
def on_not_wallpaper_button(self, button):
389+
self.img.set_from_file("images/empty.png")
390+
self.img_selected = False
391+
self.wallpaper_path = None
392+
self.thumbnail_path = None
393+
common.apply_button.set_sensitive(True)
394+
373395

374396
class SortingButton(Gtk.Button):
375397
def __init__(self):
@@ -449,26 +471,26 @@ def on_apply_button(button):
449471
# Prepare, save and execute the shell script for swaybg. It'll be placed in ~/.azotebg for further use.
450472
batch_content = ['#!/usr/bin/env bash', 'pkill swaybg']
451473
for box in common.display_boxes_list:
452-
if box.color:
453-
# if a color chosen, the wallpaper won't appear
454-
batch_content.append("swaybg -o {} -c{} &".format(box.display_name, box.color))
455-
elif box.wallpaper_path:
456-
# see: https://github.com/nwg-piotr/azote/issues/143
457-
if common.settings.generic_display_names:
458-
display_name = ""
459-
for item in common.displays:
460-
if item["name"] == box.display_name:
461-
display_name = item["generic-name"]
462-
else:
463-
display_name = box.display_name
474+
if common.settings.generic_display_names:
475+
display_name = ""
476+
for item in common.displays:
477+
if item["name"] == box.display_name:
478+
display_name = item["generic-name"]
479+
else:
480+
display_name = box.display_name
464481

482+
if box.img_selected:
483+
# see: https://github.com/nwg-piotr/azote/issues/143
465484
# Escape some special characters which would mess up the script
466485
wallpaper_path = box.wallpaper_path.replace('\\', '\\\\').replace("$", "\$").replace("`",
467486
"\\`").replace('"',
468487
'\\"')
469-
470-
batch_content.append(
471-
"swaybg -o '{}' -i \"{}\" -m {} &".format(display_name, wallpaper_path, box.mode))
488+
if box.color:
489+
batch_content.append(
490+
"swaybg -o '{}' -c '{}' -i \"{}\" -m {} &".format(display_name, box.color, wallpaper_path, box.mode))
491+
else:
492+
batch_content.append(
493+
"swaybg -o '{}' -i \"{}\" -m {} &".format(display_name, wallpaper_path, box.mode))
472494

473495
# build the json file content
474496
if box.wallpaper_path.startswith("{}/backgrounds-sway/flipped-".format(common.data_home)):
@@ -483,8 +505,11 @@ def on_apply_button(button):
483505
thumb = "{}.png".format(hash_name(box.wallpaper_path))
484506
thumb = os.path.join(common.data_home, "thumbnails", thumb)
485507

486-
entry = {"name": box.display_name, "path": box.wallpaper_path, "thumb": thumb}
508+
entry = {"name": display_name, "path": box.wallpaper_path, "thumb": thumb}
487509
restore_from.append(entry)
510+
elif box.color:
511+
# if a color chosen, the wallpaper won't appear
512+
batch_content.append("swaybg -o '{}' -c '{}' &".format(display_name, box.color))
488513

489514
with open(common.cmd_file, 'w') as f:
490515
# print(batch_content)
@@ -546,6 +571,7 @@ def on_split_button(button):
546571
if box.include:
547572
box.wallpaper_path = paths[i][0]
548573
box.img.set_from_file(paths[i][1])
574+
box.img_selected = True
549575
box.thumbnail_path = paths[i][1]
550576
i += 1
551577

@@ -882,12 +908,15 @@ def __init__(self, height):
882908
# Buttons below represent displays preview
883909
common.display_boxes_list = []
884910
for display in common.displays:
885-
name = display.get('name')
911+
if common.settings.generic_display_names:
912+
display_name = display.get('generic-name')
913+
else:
914+
display_name = display.get('name')
886915
# Check if we have stored values
887916
path, thumb = None, None
888917
if restore_from:
889918
for item in restore_from:
890-
if item["name"] == name:
919+
if item["name"] == display_name:
891920
path = item["path"]
892921
thumb = item["thumb"]
893922

@@ -896,7 +925,7 @@ def __init__(self, height):
896925
xrandr_idx = display.get('xrandr-idx')
897926
except KeyError:
898927
xrandr_idx = None
899-
display_box = DisplayBox(name, display.get('width'), display.get('height'), path, thumb, xrandr_idx)
928+
display_box = DisplayBox(display.get('name'), display.get('width'), display.get('height'), path, thumb, xrandr_idx)
900929
common.display_boxes_list.append(display_box)
901930
displays_box.pack_start(display_box, True, False, 0)
902931

azote/tools.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ def set_env(language=None):
362362
# Sway comes with some sample wallpapers
363363
if common.sway and os.path.isdir('/usr/share/backgrounds/sway'):
364364
common.sample_dir = '/usr/share/backgrounds/sway'
365-
365+
366366
if os.path.isdir('/usr/share/backgrounds/archlabs'):
367367
common.sample_dir = '/usr/share/backgrounds/archlabs'
368368

@@ -512,11 +512,13 @@ def set_env(language=None):
512512
def copy_backgrounds():
513513
used = []
514514
for item in common.display_boxes_list:
515-
fn = item.wallpaper_path.split("/")[-1]
516-
used.append(fn)
517-
fn = item.thumbnail_path.split("/")[-1]
518-
used.append(fn)
519-
515+
if item.wallpaper_path is not None:
516+
fn = item.wallpaper_path.split("/")[-1]
517+
used.append(fn)
518+
if item.thumbnail_path is not None:
519+
fn = item.thumbnail_path.split("/")[-1]
520+
used.append(fn)
521+
520522
# Clear unused files
521523
for file in os.listdir(common.bcg_dir):
522524
f2delete = os.path.join(common.bcg_dir, file)

0 commit comments

Comments
 (0)