Skip to content

Commit

Permalink
variety for window
Browse files Browse the repository at this point in the history
  • Loading branch information
shih-liang committed Mar 15, 2021
1 parent f7b7a1b commit dd666cf
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 93 deletions.
44 changes: 22 additions & 22 deletions bin/variety
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions data/config/variety.conf
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ stats_enabled = True
# Folder to copy the wallpaper image to and make it world-readable. Provides LightDM support.
# copyto_enabled = <True or False>, default is False
# copyto_folder = <Default or Path to a custom 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

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion variety/Options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion variety/ThumbsWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down
7 changes: 5 additions & 2 deletions variety/Util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
65 changes: 9 additions & 56 deletions variety/VarietyWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import time
import urllib.parse
import webbrowser
import ctypes

from PIL import Image as PILImage

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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"):
Expand Down
2 changes: 1 addition & 1 deletion variety/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:]

Expand Down
3 changes: 2 additions & 1 deletion variety/plugins/builtin/quotes/FortuneSource.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion variety/plugins/builtin/quotes/UrbanDictionarySource.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
# with this program. If not, see <http://www.gnu.org/licenses/>.
### END LICENSE

from locale import gettext as _
from gettext import gettext as _
#from locale import gettext as _

import requests

Expand Down
13 changes: 7 additions & 6 deletions variety_lib/varietyconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit dd666cf

Please sign in to comment.