-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
139 lines (106 loc) · 4.19 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import argparse
import configparser
import os
import platform
import sys
import ctypes
from pkg_resources import resource_string
width=0
height=0
wallpath = ''
confpath = ''
opsys = platform.system()
# initial config
def initial_conf():
try:
global wallpath
global confpath
if opsys == "Windows":
wallpath = os.path.expanduser("~\documents\pywall\images")
confpath = os.path.expanduser("~\documents\pywall\conf")
else:
print("Incompitable OS - Exiting!")
sys.exit(1)
print("Checking Wallpapers Path Exists:")
check_path(wallpath)
print("Checking Configuation Path Exists:")
check_path(confpath)
print("Checking Configuration:")
check_conf(confpath + '\config.conf')
parse_config()
except KeyboardInterrupt:
sys.exit(1)
# detect system config
def detect_system_config():
#################################################################
#DPI AWARENESS SOLUTION FROM: https://stackoverflow.com/a/44422362
# Query DPI Awareness (Windows 10 and 8)
awareness = ctypes.c_int()
errorCode = ctypes.windll.shcore.GetProcessDpiAwareness(0, ctypes.byref(awareness))
# Set DPI Awareness (Windows 10 and 8)
errorCode = ctypes.windll.shcore.SetProcessDpiAwareness(1)
# Set DPI Awareness (Windows 7 and Vista)
success = ctypes.windll.user32.SetProcessDPIAware()
#################################################################
# Monitor Resolution
monwidth = ctypes.windll.user32.GetSystemMetrics(0)
monheight = ctypes.windll.user32.GetSystemMetrics(1)
# Operating System Information
opsys = platform.system()
oprel = platform.release()
print("Detected OS: " + opsys + " " + oprel + "")
print("Resolution: " + str(monwidth) + "x" + str(monheight) + "")
print("\n")
detect_config_changes(monwidth, monheight)
# detect any differences between system and config file
def detect_config_changes(monwidth, monheight):
if monwidth != width or monheight != height:
print("Config differences found:")
print("Your resolution is: " + str(monwidth) + "x" + str(monheight) + " - Your configured resolution is: " + str(width) + "x" + str(height))
while True:
update_config = input("Would you like to update your configuration file? (Y/N)")
if update_config.lower() == "y":
print("Updating Configuration File")
update_config_file(monwidth, monheight)
break
elif update_config.lower() == "n":
print("Ignoring Configuration Differences")
break
else:
print("That is not a valid choice")
else:
print("No differences found in config")
# check path exists, otherwise create it
def check_path(path):
if not os.path.exists(path):
os.makedirs(path)
print(path + " does not exist! - Creating\n")
else:
print("That path appears to exist - Continuing!\n")
# check config file exists, otherwise install default
def check_conf(filepath):
if not os.path.isfile(filepath):
print("Config file not present - setting up default")
cfile = resource_string(__name__, 'conf/windows.conf')
with open(filepath, 'wb') as f:
f.write(cfile)
else:
print("Config file present - Continuing!")
# parse config from config file
def parse_config():
global width
global height
config = configparser.ConfigParser()
config.read(confpath + '\config.conf')
width = config.getint('Options', 'width', fallback=1920)
height = config.getint('Options', 'height', fallback=1080)
# updae config in config file
def update_config_file(monwidth, monheight):
config = configparser.ConfigParser()
config.read(confpath + '\config.conf')
print("" + str(monwidth) + " x " + str(monheight) + "")
config.set('Options', 'width', str(monwidth))
config.set('Options', 'height', str(monheight))
with open(confpath + '\config.conf', 'w') as configfile:
config.write(configfile)
parse_config()