4
4
import threading
5
5
import os
6
6
import gi
7
+ import shutil
7
8
from pathlib import Path
8
- from platformdirs import user_cache_path
9
9
from PIL import Image
10
10
11
11
from waypaper .aboutdata import AboutData
12
12
from waypaper .changer import change_wallpaper
13
13
from waypaper .config import Config
14
- from waypaper .common import get_image_paths , get_random_file , check_missing_backends
14
+ from waypaper .common import get_image_paths , get_random_file
15
15
from waypaper .options import FILL_OPTIONS , BACKEND_OPTIONS , SORT_OPTIONS , SORT_DISPLAYS
16
16
17
17
gi .require_version ("Gtk" , "3.0" )
@@ -27,7 +27,7 @@ def read_webp_image(image_path):
27
27
return pixbuf
28
28
29
29
30
- def cache_image (image_path , cachedir ):
30
+ def cache_image (image_path , cache_dir ):
31
31
"""Resize and cache images using gtk library"""
32
32
ext = os .path .splitext (image_path )[1 ].lower ()
33
33
if ext == ".webp" :
@@ -38,7 +38,7 @@ def cache_image(image_path, cachedir):
38
38
scaled_width = 240
39
39
scaled_height = int (scaled_width / aspect_ratio )
40
40
scaled_pixbuf = pixbuf .scale_simple (scaled_width , scaled_height , GdkPixbuf .InterpType .BILINEAR )
41
- output_file = cachedir / Path (os .path .basename (image_path ))
41
+ output_file = cache_dir / Path (os .path .basename (image_path ))
42
42
scaled_pixbuf .savev (str (output_file ), "jpeg" , [], [])
43
43
44
44
@@ -47,15 +47,14 @@ class App(Gtk.Window):
47
47
48
48
def __init__ (self , txt ):
49
49
super ().__init__ (title = "Waypaper" )
50
+ self .cf = Config ()
51
+ self .about = AboutData ()
50
52
self .txt = txt
51
53
self .check_backends ()
52
54
self .set_default_size (780 , 600 )
53
55
self .connect ("delete-event" , Gtk .main_quit )
54
56
self .selected_index = 0
55
57
self .highlighted_image_row = 0
56
- self .aboutData = AboutData ()
57
- self .cachePath = user_cache_path (self .aboutData .applicationName ())
58
- self .cf = Config ()
59
58
self .init_ui ()
60
59
61
60
# Start the image processing in a separate thread:
@@ -96,16 +95,13 @@ def init_ui(self):
96
95
97
96
# Create a backend dropdown menu:
98
97
self .backend_option_combo = Gtk .ComboBoxText ()
99
- for backend , is_missing in zip (BACKEND_OPTIONS , self .missing_backends ):
100
- if not is_missing :
101
- self .backend_option_combo .append_text (backend )
98
+ for backend in self .cf .installed_backends :
99
+ self .backend_option_combo .append_text (backend )
102
100
103
101
# Set as active line the backend from config, if it is installed:
104
- try :
105
- installed_backends = [value for value , miss in zip (BACKEND_OPTIONS , self .missing_backends ) if not miss ]
106
- active_num = installed_backends .index (self .cf .backend )
107
- except :
108
- active_num = 0
102
+ active_num = 0
103
+ if self .cf .backend in self .cf .installed_backends :
104
+ active_num = self .cf .installed_backends .index (self .cf .backend )
109
105
self .backend_option_combo .set_active (active_num )
110
106
self .backend_option_combo .connect ("changed" , self .on_backend_option_changed )
111
107
self .backend_option_combo .set_tooltip_text (self .txt .tip_backend )
@@ -192,7 +188,6 @@ def init_ui(self):
192
188
def monitor_option_display (self ):
193
189
"""Display monitor option if backend is swww"""
194
190
self .options_box .remove (self .monitor_option_combo )
195
- # if "swww" not in self.missing_backends and self.cf.backend not in ["wallutils", "feh"]:
196
191
if self .cf .backend == "swww" :
197
192
198
193
# Check available monitors:
@@ -219,12 +214,9 @@ def monitor_option_display(self):
219
214
220
215
221
216
def check_backends (self ):
222
- """Before running the app, check which backends are installed"""
223
- self .missing_backends = check_missing_backends ()
224
-
225
- # Show error message if no backends are installed:
226
- if all (self .missing_backends ):
227
- self .show_message (sefl .txt .err_backend )
217
+ """Before running the app, check which backends are installed or show the error"""
218
+ if not self .cf .installed_backends :
219
+ self .show_message (self .txt .err_backend )
228
220
exit ()
229
221
230
222
@@ -275,9 +267,9 @@ def process_images(self):
275
267
self .image_paths .remove (image_path )
276
268
continue
277
269
# If this image is not cached yet, resize and cache it:
278
- cached_image_path = self .cachePath / os .path .basename (image_path )
270
+ cached_image_path = self .cf . cache_dir / os .path .basename (image_path )
279
271
if not cached_image_path .exists ():
280
- cache_image (image_path , self .cachePath )
272
+ cache_image (image_path , self .cf . cache_dir )
281
273
282
274
# Load cached thumbnail:
283
275
thumbnail = GdkPixbuf .Pixbuf .new_from_file (str (cached_image_path ))
@@ -406,7 +398,7 @@ def on_image_clicked(self, widget, path):
406
398
self .load_image_grid ()
407
399
print (self .txt .msg_path , self .cf .selected_wallpaper )
408
400
self .cf .fill_option = self .fill_option_combo .get_active_text () or self .cf .fill_option
409
- change_wallpaper (self .cf .selected_wallpaper , self .cf , self .cf .selected_monitor , self .txt , self . missing_backends )
401
+ change_wallpaper (self .cf .selected_wallpaper , self .cf , self .cf .selected_monitor , self .txt )
410
402
self .cf .save ()
411
403
412
404
@@ -433,17 +425,17 @@ def set_random_wallpaper(self):
433
425
return
434
426
print (self .txt .msg_path , self .cf .selected_wallpaper )
435
427
self .cf .fill_option = self .fill_option_combo .get_active_text () or self .cf .fill_option
436
- change_wallpaper (self .cf .selected_wallpaper , self .cf , self .cf .selected_monitor , self .txt , self . missing_backends )
428
+ change_wallpaper (self .cf .selected_wallpaper , self .cf , self .cf .selected_monitor , self .txt )
437
429
self .cf .save ()
438
430
439
431
440
432
def clear_cache (self ):
441
433
"""Delete cache folder and reprocess the images"""
442
434
try :
443
- shutil .rmtree (self .cachePath )
444
- os .makedirs (self .cachePath )
435
+ shutil .rmtree (self .cf . cache_dir )
436
+ os .makedirs (self .cf . cache_dir )
445
437
except OSError as e :
446
- print (f"{ self .txt .err_cache } '{ self .cachePath } ': { e } " )
438
+ print (f"{ self .txt .err_cache } '{ self .cf . cache_dir } ': { e } " )
447
439
threading .Thread (target = self .process_images ).start ()
448
440
449
441
@@ -501,7 +493,7 @@ def on_key_pressed(self, widget, event):
501
493
print (self .txt .msg_path , self .cf .selected_wallpaper )
502
494
self .cf .backend = self .backend_option_combo .get_active_text ()
503
495
self .cf .fill_option = self .fill_option_combo .get_active_text () or self .cf .fill_option
504
- change_wallpaper (self .cf .selected_wallpaper , self .cf , self .cf .selected_monitor , self .txt , self . missing_backends )
496
+ change_wallpaper (self .cf .selected_wallpaper , self .cf , self .cf .selected_monitor , self .txt )
505
497
self .cf .save ()
506
498
507
499
# Prevent other default key handling:
0 commit comments