From e5cd5eeddd7edf1a90e40f33143f71be9fad30d9 Mon Sep 17 00:00:00 2001 From: Hector Miuler Malpica Gallegos Date: Fri, 14 Oct 2022 15:21:35 -0500 Subject: [PATCH] feat: Add support for image and color at the same time --- azote/images/empty_btn.png | Bin 0 -> 6648 bytes azote/main.py | 71 ++++++++++++++++++++++++++----------- azote/tools.py | 14 ++++---- 3 files changed, 58 insertions(+), 27 deletions(-) create mode 100644 azote/images/empty_btn.png diff --git a/azote/images/empty_btn.png b/azote/images/empty_btn.png new file mode 100644 index 0000000000000000000000000000000000000000..825c00ed6bea06bf049dcd221d4d0431e5e1f9a7 GIT binary patch literal 6648 zcmeHKc{r47{~t??X+gO$dZF} zG8{`%6j3BgDA|&v(n2ZkL!Ihe?|WUp>s;6G{jZs8o_U_{^7($hpYMI&&wa-@+FLG% zslp%-$Z~5dGYa?*2Y<>?De#)^JdcAwq!L11+yoSAFr3HdGFg5AToA$o;DC_Dgg}J7 z7hRoBz0iVw4qkmF>R?XA+SMelAWU;sthG;NVd3NS=dOg+_mw44d&sHtbJg`8Gdf<& zt&feSO&{_o$md6%Yn=7{WN+E~;q%ah{Ku?Y68&hMXhg3tNY7(>%0E;KpDtx>q}A?E zdX}aBKrr65(Y(v#K9WEEg5rWUPi&JGZ1T?AZCU)AQRTg{p5Dov%=stR0;^nGM@3n% z9IuE##B`j3Y#)8N| zoUc=7!DW6toSZK@RdDs;!xCoXX!Nx;n&l5gjhU5EnPKC-zFdiM-S&h;OBLdC?^}w? z=cql$@^|1)$ZY*vrzK+Gx1H#$RSk= zThWe$ju<=>5@(8lyRQ}BfZNJELa}+#L||G1E{8F33XLsI@)8lOmCZS8s_Hi89Pd*f zRJ8dRwPs#H^yFT3OrL9?dp483%D)d9vO3i9#L?%wU8qpHp52+lRpT!dMPs>^%WO(& zJ`9wssxN%+OqjdfjJi=!b5F){?U_$aSK99P%B5Co-%ShiWgl}maoNGny|cn0s;h$> zZAq4E%3P6_Y=Rxevp+x7naIm{)u>u*e@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lz$I!%&F2 z(LT?BfGgK6P5~>_46X8Aa&{J~ICXb-*NyN81;p9&K82k=4MYCLdqm=O=Pge-?pS@I zk=`u;&yk-$1}c~vci=dE71y6X_o4sx1$VmCEiSa$zS@1G0?hx*T*%O#4jj|VOXkRp zna|-;Qc|gB&J5Nak~kn;_uzp7o6W8=ArXl_0>_J#!MEcbP>p5jV2Jki_Of6|*_MFO z78SeP`C^--hL}|wdHA&!$M~YY;!~|-(=OU6)e^5}_eGg#Km>d99JL_lv|t4VITJ+p z-%pD~1f%ddtE<0Vblbw8c!)f9lXl*;b~*$M^1QRKsVq(|LO{Ix=o(kV8x%KzqV`rc zWNZz-w6n0NsOVgQ_I1w$CA51&+gKtXI`k}jvv}k2b?cRvA)>ZJjWv@8Uk^1}c=vM* z60I7nZ1Y{74&FH8$7X*{8X(u2W{?qnPkdhw1s2kKfBmC)g zoki4aN4RQy_!@XpLsjsUo4b21C7(AnKsv8=Bsv-_=zw}%cegT$M6wV%=PTUzKFPzk zOmzLeJok#*mJKUoa*zDxZ0=p^rmUi(qt+RiVTLGe9<_wYN=24myO!KGHg7Mv&qzJI zws!D_`a8?)eFW;g>J&g)>gSBC;;vq)izg`K^Q zTh&fTYe=T$YV=G7CE8pBr-5PE`?#^TtTo$Pn7TtlLlzSNRwdIgs;G$unoK1+-AIN$3K0TI+L0C<&Tr$9?fk1HOa}z^ZStV ZFi)jxs0Y1eW8j>JSex6M6`OcQ{2TC@tM>o^ literal 0 HcmV?d00001 diff --git a/azote/main.py b/azote/main.py index dbafd3f..3534ebf 100644 --- a/azote/main.py +++ b/azote/main.py @@ -247,6 +247,11 @@ def __init__(self, name, width, height, path=None, thumb=None, xrandr_idx=None): self.img = Gtk.Image.new_from_pixbuf(pixbuf) + if path is None: + self.img_selected = False + else: + self.img_selected = True + self.select_button = Gtk.Button() self.select_button.set_always_show_image(True) 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): options_box.set_orientation(Gtk.Orientation.HORIZONTAL) self.pack_start(options_box, True, False, 0) + self.not_wallpaper_button = Gtk.Button() + img = Gtk.Image() + img.set_from_file('images/empty_btn.png') + self.not_wallpaper_button.set_image(img) + self.not_wallpaper_button.connect("clicked", self.on_not_wallpaper_button) + options_box.pack_start(self.not_wallpaper_button, False, False, 0) + check_button = Gtk.CheckButton() check_button.set_active(self.include) check_button.set_tooltip_text(common.lang["include_when_splitting"]) @@ -333,12 +345,14 @@ def clear_color_selection(self): def on_select_button(self, button): if common.selected_wallpaper: self.img.set_from_file(common.selected_wallpaper.thumb_file) + self.img_selected = True self.wallpaper_path = common.selected_wallpaper.source_path self.thumbnail_path = common.selected_wallpaper.thumb_file button.set_property("name", "display-btn-selected") self.flip_button.set_sensitive(True) - self.clear_color_selection() + # When select a new wallpaper, not clear color selection + #self.clear_color_selection() common.apply_button.set_sensitive(True) @@ -359,7 +373,8 @@ def on_mode_combo_changed(self, combo): def on_color_chosen(self, user_data, button): self.color = rgba_to_hex(button.get_rgba()) # clear selected image to indicate it won't be used - self.img.set_from_file("images/empty.png") + # self.img.set_from_file("images/empty.png") + # self.img_selected = False common.apply_button.set_sensitive(True) def on_flip_button(self, button): @@ -370,6 +385,13 @@ def on_flip_button(self, button): self.thumbnail_path = images[0] self.flip_button.set_sensitive(False) + def on_not_wallpaper_button(self, button): + self.img.set_from_file("images/empty.png") + self.img_selected = False + self.wallpaper_path = None + self.thumbnail_path = None + common.apply_button.set_sensitive(True) + class SortingButton(Gtk.Button): def __init__(self): @@ -449,26 +471,26 @@ def on_apply_button(button): # Prepare, save and execute the shell script for swaybg. It'll be placed in ~/.azotebg for further use. batch_content = ['#!/usr/bin/env bash', 'pkill swaybg'] for box in common.display_boxes_list: - if box.color: - # if a color chosen, the wallpaper won't appear - batch_content.append("swaybg -o {} -c{} &".format(box.display_name, box.color)) - elif box.wallpaper_path: - # see: https://github.com/nwg-piotr/azote/issues/143 - if common.settings.generic_display_names: - display_name = "" - for item in common.displays: - if item["name"] == box.display_name: - display_name = item["generic-name"] - else: - display_name = box.display_name + if common.settings.generic_display_names: + display_name = "" + for item in common.displays: + if item["name"] == box.display_name: + display_name = item["generic-name"] + else: + display_name = box.display_name + if box.img_selected: + # see: https://github.com/nwg-piotr/azote/issues/143 # Escape some special characters which would mess up the script wallpaper_path = box.wallpaper_path.replace('\\', '\\\\').replace("$", "\$").replace("`", "\\`").replace('"', '\\"') - - batch_content.append( - "swaybg -o '{}' -i \"{}\" -m {} &".format(display_name, wallpaper_path, box.mode)) + if box.color: + batch_content.append( + "swaybg -o '{}' -c '{}' -i \"{}\" -m {} &".format(display_name, box.color, wallpaper_path, box.mode)) + else: + batch_content.append( + "swaybg -o '{}' -i \"{}\" -m {} &".format(display_name, wallpaper_path, box.mode)) # build the json file content if box.wallpaper_path.startswith("{}/backgrounds-sway/flipped-".format(common.data_home)): @@ -483,8 +505,11 @@ def on_apply_button(button): thumb = "{}.png".format(hash_name(box.wallpaper_path)) thumb = os.path.join(common.data_home, "thumbnails", thumb) - entry = {"name": box.display_name, "path": box.wallpaper_path, "thumb": thumb} + entry = {"name": display_name, "path": box.wallpaper_path, "thumb": thumb} restore_from.append(entry) + elif box.color: + # if a color chosen, the wallpaper won't appear + batch_content.append("swaybg -o '{}' -c '{}' &".format(display_name, box.color)) with open(common.cmd_file, 'w') as f: # print(batch_content) @@ -546,6 +571,7 @@ def on_split_button(button): if box.include: box.wallpaper_path = paths[i][0] box.img.set_from_file(paths[i][1]) + box.img_selected = True box.thumbnail_path = paths[i][1] i += 1 @@ -882,12 +908,15 @@ def __init__(self, height): # Buttons below represent displays preview common.display_boxes_list = [] for display in common.displays: - name = display.get('name') + if common.settings.generic_display_names: + display_name = display.get('generic-name') + else: + display_name = display.get('name') # Check if we have stored values path, thumb = None, None if restore_from: for item in restore_from: - if item["name"] == name: + if item["name"] == display_name: path = item["path"] thumb = item["thumb"] @@ -896,7 +925,7 @@ def __init__(self, height): xrandr_idx = display.get('xrandr-idx') except KeyError: xrandr_idx = None - display_box = DisplayBox(name, display.get('width'), display.get('height'), path, thumb, xrandr_idx) + display_box = DisplayBox(display.get('name'), display.get('width'), display.get('height'), path, thumb, xrandr_idx) common.display_boxes_list.append(display_box) displays_box.pack_start(display_box, True, False, 0) diff --git a/azote/tools.py b/azote/tools.py index bb10e0c..47e5d5a 100644 --- a/azote/tools.py +++ b/azote/tools.py @@ -362,7 +362,7 @@ def set_env(language=None): # Sway comes with some sample wallpapers if common.sway and os.path.isdir('/usr/share/backgrounds/sway'): common.sample_dir = '/usr/share/backgrounds/sway' - + if os.path.isdir('/usr/share/backgrounds/archlabs'): common.sample_dir = '/usr/share/backgrounds/archlabs' @@ -512,11 +512,13 @@ def set_env(language=None): def copy_backgrounds(): used = [] for item in common.display_boxes_list: - fn = item.wallpaper_path.split("/")[-1] - used.append(fn) - fn = item.thumbnail_path.split("/")[-1] - used.append(fn) - + if item.wallpaper_path is not None: + fn = item.wallpaper_path.split("/")[-1] + used.append(fn) + if item.thumbnail_path is not None: + fn = item.thumbnail_path.split("/")[-1] + used.append(fn) + # Clear unused files for file in os.listdir(common.bcg_dir): f2delete = os.path.join(common.bcg_dir, file)