-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature windows support (WIP) #292
Open
fquinner
wants to merge
9
commits into
varietywalls:master
Choose a base branch
from
fquinner:feature-windows-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
759eb04
Initial implementation of windows port for variety
96b460b
Merged latest master and added further fixes for windows
f85e584
Added support for filters
5922187
Added clock and date filters for windows
9272044
Fixes for dbus on Linux... hoping it doesn't break windows
a1e7e3f
Merge branch 'master' into feature-windows-support
8c29618
Added fix for latest upstream variety code and windows
1a1f159
Merge branch 'master' into feature-windows-support
fquinner 2cbc7a3
Merge remote-tracking branch 'upstream/master' into feature-windows-s…
fquinner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
import random | ||
import re | ||
import shutil | ||
import shlex | ||
import string | ||
import subprocess | ||
import sys | ||
|
@@ -739,8 +740,12 @@ def same_file_paths(f1, f2): | |
|
||
@staticmethod | ||
def collapseuser(path): | ||
home = os.path.expanduser("~") + "/" | ||
return re.sub("^" + home, "~/", path) | ||
# normpath used to avoid backslash mixing on windows | ||
home = os.path.normpath(os.path.expanduser('~')) + os.sep | ||
if os.name == 'nt': | ||
return path | ||
else: | ||
return re.sub('^' + home, '~' + os.sep, path) | ||
|
||
@staticmethod | ||
def compare_versions(v1, v2): | ||
|
@@ -774,6 +779,8 @@ def random_hash(): | |
|
||
@staticmethod | ||
def get_file_icon_name(path): | ||
if os.name == 'nt': | ||
return "folder" | ||
try: | ||
f = Gio.File.new_for_path(os.path.normpath(os.path.expanduser(path))) | ||
query_info = f.query_info("standard::icon", Gio.FileQueryInfoFlags.NONE, None) | ||
|
@@ -896,12 +903,67 @@ def copy_with_replace(from_path, to_path, search_replace_map): | |
with open(to_path + ".partial", "w") as file: | ||
file.write(data) | ||
file.flush() | ||
os.rename(to_path + ".partial", to_path) | ||
shutil.move(to_path + ".partial", to_path) | ||
|
||
@staticmethod | ||
def get_exec_path(): | ||
return os.path.abspath(sys.argv[0]) | ||
|
||
@staticmethod | ||
def set_windows_registry_key(path, name, value, dtype=None, master='HKEY_CURRENT_USER'): | ||
import winreg | ||
|
||
# Type is only used if creating a new value | ||
if not dtype or isinstance(value, str): | ||
dtype = winreg.REG_SZ | ||
elif isinstance(value, int): | ||
dtype = winreg.REG_DWORD | ||
else: | ||
dtype = winreg.REG_SZ | ||
|
||
# Translate key name to winreg key name | ||
registry = winreg.HKEY_CURRENT_USER | ||
if master == 'HKEY_CURRENT_USER': | ||
registry = winreg.HKEY_CURRENT_USER | ||
elif master == 'HKEY_LOCAL_MACHINE': | ||
registry = winreg.HKEY_LOCAL_MACHINE | ||
elif master == 'HKEY_USERS': | ||
registry = winreg.HKEY_USERS | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If no hives other than HKEY_CURRENT_USER are used we can probably remove those cases. AFAICT HKEY_LOCAL_MACHINE shouldn't be writable from an unprivileged account anyways. |
||
|
||
# This will throw FileNotFoundError if key does not exist - this is fatal for this function | ||
key = winreg.OpenKey( | ||
registry, | ||
path, | ||
0, | ||
winreg.KEY_WRITE | winreg.KEY_READ | ||
) | ||
|
||
# Try getting the explicit value, catch if doesn't exist | ||
try: | ||
val, val_type = winreg.QueryValueEx(key, "WallpaperStyle") | ||
# If the value is correct, ignore, otherwise set | ||
if val == value: | ||
pass | ||
else: | ||
winreg.SetValueEx(key, name, 0, val_type, value) | ||
except FileNotFoundError: | ||
# Couldn't find key, try creating | ||
try: | ||
winreg.SetValueEx(key, name, 0, dtype, value) | ||
except Exception as e: | ||
# Log failure here | ||
pass | ||
finally: | ||
winreg.CloseKey(key) | ||
|
||
@staticmethod | ||
def shlex_quote(s): | ||
if os.name != 'nt': | ||
return shlex.quote(s) | ||
else: | ||
# shlex.quote does not play nicely with windows shell, so just always-quote | ||
return '"%s"' % s | ||
|
||
@staticmethod | ||
def get_folder_size(start_path): | ||
total_size = 0 | ||
|
@@ -916,7 +978,6 @@ def get_folder_size(start_path): | |
def get_screen_width(): | ||
return Gdk.Screen.get_default().get_width() | ||
|
||
|
||
def on_gtk(f): | ||
@functools.wraps(f) | ||
def wrapped(*args): | ||
|
@@ -925,6 +986,7 @@ def wrapped(*args): | |
return wrapped | ||
|
||
|
||
|
||
def safe_print(text, ascii_text=None, file=sys.stdout): | ||
""" | ||
Python's print throws UnicodeEncodeError if the terminal encoding is borked. This version tries print, then logging, then printing the ascii text when one is present. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we can probably just collapse this into one check for
isinstance(value, int)
?