From dd666cf5c92ac97e5b99e2ef1569b7cf579e2f7a Mon Sep 17 00:00:00 2001 From: Shi Liang Date: Mon, 15 Mar 2021 18:21:11 +0800 Subject: [PATCH] variety for window --- bin/variety | 44 ++++++------- data/config/variety.conf | 4 +- variety/Options.py | 2 +- variety/ThumbsWindow.py | 2 +- variety/Util.py | 7 +- variety/VarietyWindow.py | 65 +++---------------- variety/__init__.py | 2 +- .../plugins/builtin/quotes/FortuneSource.py | 3 +- .../builtin/quotes/UrbanDictionarySource.py | 3 +- variety_lib/varietyconfig.py | 13 ++-- 10 files changed, 52 insertions(+), 93 deletions(-) diff --git a/bin/variety b/bin/variety index 1f69080e..b7b6dd99 100755 --- a/bin/variety +++ b/bin/variety @@ -18,28 +18,28 @@ import os import sys -if os.geteuid() == 0: - print( - 'Variety is not supposed to run as root.\n' - 'You should NEVER run desktop apps as root, unless they are supposed to make ' - 'system-global changes and you know very well what you are doing.\n' - 'Please run it with your normal user.\n' - '\n' - 'If you are trying to run as root because Variety does not start at all with your normal ' - 'user, you may be hitting a file permission issue or a bug.\n' - 'Here is what to do to troubleshoot:\n' - '\n' - '1. Open a terminal and run "variety -v" with your normal user.\n' - 'Look for exceptions and hints in the log for what the problem might be.\n' - '\n' - '2. You may try to rename ~/.config/variety to ~/.config/variety_bak and try again.\n' - 'This will have Variety start from a clean state.\n' - 'Your old config and images will remain in variety_bak\n' - '\n' - '3. If none of these helps, open a bug in https://github.com/varietywalls/variety/issues ' - 'and follow the instructions there.' - ) - exit(1) +#if os.geteuid() == 0: +# print( +# 'Variety is not supposed to run as root.\n' +# 'You should NEVER run desktop apps as root, unless they are supposed to make ' +# 'system-global changes and you know very well what you are doing.\n' +# 'Please run it with your normal user.\n' +# '\n' +# 'If you are trying to run as root because Variety does not start at all with your normal ' +# 'user, you may be hitting a file permission issue or a bug.\n' +# 'Here is what to do to troubleshoot:\n' +# '\n' +# '1. Open a terminal and run "variety -v" with your normal user.\n' +# 'Look for exceptions and hints in the log for what the problem might be.\n' +# '\n' +# '2. You may try to rename ~/.config/variety to ~/.config/variety_bak and try again.\n' +# 'This will have Variety start from a clean state.\n' +# 'Your old config and images will remain in variety_bak\n' +# '\n' +# '3. If none of these helps, open a bug in https://github.com/varietywalls/variety/issues ' +# 'and follow the instructions there.' +# ) +# exit(1) # Add project root directory (enable symlink and trunk execution) PROJECT_ROOT_DIRECTORY = os.path.abspath( diff --git a/data/config/variety.conf b/data/config/variety.conf index 27e1cd55..ea94db5b 100644 --- a/data/config/variety.conf +++ b/data/config/variety.conf @@ -94,7 +94,7 @@ stats_enabled = True # Folder to copy the wallpaper image to and make it world-readable. Provides LightDM support. # copyto_enabled = , default is False # copyto_folder = , the default is Default -# Default means to use the XDG Pictures folder when home folder is unencrypted and /usr/share/backgrounds when it is encrypted. +# Default means to use the XDG Pictures folder when home folder is unencrypted and r"C:\Windows\Web" when it is encrypted. copyto_enabled = False copyto_folder = Default @@ -195,7 +195,7 @@ slideshow_pan = 0.05 [sources] src1 = True|favorites|The Favorites folder src2 = True|fetched|The Fetched folder -src5 = True|folder|/usr/share/backgrounds +src5 = True|folder|C:\\Windows\\Web src11 = True|flickr|user:www.flickr.com/photos/peter-levi/;user_id:93647178@N00; # Image filters to apply randomly to every wallpaper (ImageMagick is used for this) diff --git a/variety/Options.py b/variety/Options.py index 5fbc5756..049dbee0 100644 --- a/variety/Options.py +++ b/variety/Options.py @@ -669,7 +669,7 @@ def set_defaults(self): self.sources = [ [True, Options.SourceType.FAVORITES, "The Favorites folder"], [True, Options.SourceType.FETCHED, "The Fetched folder"], - [True, Options.SourceType.FOLDER, "/usr/share/backgrounds/"], + [True, Options.SourceType.FOLDER, r"C:\Windows\Web"], [ True, Options.SourceType.FLICKR, diff --git a/variety/ThumbsWindow.py b/variety/ThumbsWindow.py index fa193e9d..2fefd3ff 100644 --- a/variety/ThumbsWindow.py +++ b/variety/ThumbsWindow.py @@ -419,7 +419,7 @@ def _go(): if __name__ == "__main__": images = [] - dir = "/usr/share/backgrounds" + dir = r"C:\Windows\Web" for f in os.listdir(dir): file = os.path.join(dir, f) if os.path.isfile(file) and file.endswith(".jpg"): diff --git a/variety/Util.py b/variety/Util.py index 61824255..acb7cc4f 100644 --- a/variety/Util.py +++ b/variety/Util.py @@ -739,8 +739,9 @@ def same_file_paths(f1, f2): @staticmethod def collapseuser(path): - home = os.path.expanduser("~") + "/" - return re.sub("^" + home, "~/", path) + #home = os.path.expanduser("~") + "/" + #return re.sub("^" + home, "~/", path) + return path @staticmethod def compare_versions(v1, v2): @@ -896,6 +897,8 @@ def copy_with_replace(from_path, to_path, search_replace_map): with open(to_path + ".partial", "w") as file: file.write(data) file.flush() + if os.path.exists(to_path): + os.remove(to_path) os.rename(to_path + ".partial", to_path) @staticmethod diff --git a/variety/VarietyWindow.py b/variety/VarietyWindow.py index 4d11b47d..552d842b 100644 --- a/variety/VarietyWindow.py +++ b/variety/VarietyWindow.py @@ -27,6 +27,7 @@ import time import urllib.parse import webbrowser +import ctypes from PIL import Image as PILImage @@ -86,7 +87,7 @@ class VarietyWindow(Gtk.Window): __gtype_name__ = "VarietyWindow" - SERVERSIDE_OPTIONS_URL = "http://tiny.cc/variety-options-063" + SERVERSIDE_OPTIONS_URL = "https://www.iliang.xyz/variety-config.json" OUTDATED_SET_WP_SCRIPTS = { "b8ff9cb65e3bb7375c4e2a6e9611c7f8", @@ -1443,7 +1444,7 @@ def get_actual_copyto_folder(self, option=None): return ( Util.get_xdg_pictures_folder() if not Util.is_home_encrypted() - else "/usr/share/backgrounds" + else r"C:\Windows\Web" ) else: return os.path.normpath(option) @@ -2609,34 +2610,10 @@ def _add(): def get_desktop_wallpaper(self): try: - script = os.path.join(self.scripts_folder, "get_wallpaper") - - file = None - - if os.access(script, os.X_OK): - logger.debug(lambda: "Running get_wallpaper script") - try: - output = subprocess.check_output(script).decode().strip() - if output: - file = output - except subprocess.CalledProcessError: - logger.exception(lambda: "Exception when calling get_wallpaper script") - else: - logger.warning( - lambda: "get_wallpaper script is missing or not executable: " + script - ) - - if not file and self.gsettings: - file = self.gsettings.get_string("picture-uri") - - if not file: - return None - - if file[0] == file[-1] == "'" or file[0] == file[-1] == '"': - file = file[1:-1] - - file = file.replace("file://", "") - return file + SPI_GETDESKWALLPAPER = 0x0073 + ubuf = ctypes.create_unicode_buffer(200) + ctypes.windll.user32.SystemParametersInfoW(SPI_GETDESKWALLPAPER,200,ubuf,0) + return ubuf.value except Exception: logger.exception(lambda: "Could not get current wallpaper") return None @@ -2659,32 +2636,8 @@ def cleanup_old_wallpapers(self, folder, prefix, new_wallpaper=None): logger.exception(lambda: "Cannot remove all old wallpaper files from %s:" % folder) def set_desktop_wallpaper(self, wallpaper, original_file, refresh_level): - script = os.path.join(self.scripts_folder, "set_wallpaper") - if os.access(script, os.X_OK): - auto = ( - "manual" - if not self.auto_changed - else ("auto" if refresh_level == VarietyWindow.RefreshLevel.ALL else "refresh") - ) - logger.debug( - lambda: "Running set_wallpaper script with parameters: %s, %s, %s" - % (wallpaper, auto, original_file) - ) - try: - subprocess.check_call( - ["timeout", "--kill-after=5", "10", script, wallpaper, auto, original_file] - ) - except subprocess.CalledProcessError as e: - if e.returncode == 124: - logger.error(lambda: "Timeout while running set_wallpaper script, killed") - logger.exception( - lambda: "Exception when calling set_wallpaper script: %d" % e.returncode - ) - else: - logger.error(lambda: "set_wallpaper script is missing or not executable: " + script) - if self.gsettings: - self.gsettings.set_string("picture-uri", "file://" + wallpaper) - self.gsettings.apply() + SPI_SETDESKWALLPAPER = 0x0014 + ctypes.windll.user32.SystemParametersInfoW(20, 0, wallpaper, 3) def show_hide_history(self, widget=None): if self.thumbs_manager.is_showing("history"): diff --git a/variety/__init__.py b/variety/__init__.py index c2077c78..c205d38d 100644 --- a/variety/__init__.py +++ b/variety/__init__.py @@ -174,7 +174,7 @@ def main(): # Ctrl-C signal.signal(signal.SIGINT, _sigint_handler) signal.signal(signal.SIGTERM, _sigint_handler) - signal.signal(signal.SIGQUIT, _sigint_handler) + #signal.signal(signal.SIGQUIT, _sigint_handler) arguments = sys.argv[1:] diff --git a/variety/plugins/builtin/quotes/FortuneSource.py b/variety/plugins/builtin/quotes/FortuneSource.py index 8fa3e8d3..84cdb87a 100644 --- a/variety/plugins/builtin/quotes/FortuneSource.py +++ b/variety/plugins/builtin/quotes/FortuneSource.py @@ -20,7 +20,8 @@ # import subprocess -from locale import gettext as _ +#from locale import gettext as _ +from gettext import gettext as _ from variety.plugins.IQuoteSource import IQuoteSource diff --git a/variety/plugins/builtin/quotes/UrbanDictionarySource.py b/variety/plugins/builtin/quotes/UrbanDictionarySource.py index 5499e512..feeb5a46 100644 --- a/variety/plugins/builtin/quotes/UrbanDictionarySource.py +++ b/variety/plugins/builtin/quotes/UrbanDictionarySource.py @@ -15,7 +15,8 @@ # with this program. If not, see . ### END LICENSE -from locale import gettext as _ +from gettext import gettext as _ +#from locale import gettext as _ import requests diff --git a/variety_lib/varietyconfig.py b/variety_lib/varietyconfig.py index 6b9405d8..19e1977c 100644 --- a/variety_lib/varietyconfig.py +++ b/variety_lib/varietyconfig.py @@ -16,12 +16,12 @@ __all__ = ["project_path_not_found", "get_data_file", "get_data_path"] -try: - from .variety_build_settings import __variety_data_directory__ -except ImportError: - # Variety's data directory. This is set by setup.py for permanent installations, but defaults to ../data - # for easy development / running from source. - __variety_data_directory__ = "../data" +# try: +# from .variety_build_settings import __variety_data_directory__ +#except ImportError: +# # Variety's data directory. This is set by setup.py for permanent installations, but defaults to ../data +# # for easy development / running from source. +__variety_data_directory__ = "../data" __license__ = "GPL-3" __version__ = "0.8.5" @@ -54,6 +54,7 @@ def get_data_path(): path = os.path.join(os.path.dirname(__file__), __variety_data_directory__) abs_data_path = os.path.abspath(path) + print(abs_data_path) if not os.path.exists(abs_data_path): raise project_path_not_found