-
Notifications
You must be signed in to change notification settings - Fork 0
/
M_BingWallPaper.py
95 lines (79 loc) · 2.63 KB
/
M_BingWallPaper.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
##############################
# import
##############################
import wx
import requests
import json
import PIL.Image
import win32api,win32con,win32gui
import os
import threading
import GUI_BingWallPaper
##############################
# GUI的函数桥接
##############################
class CalcFrame(GUI_BingWallPaper.Main):
def __init__(self, parent):
# 定义主函数
GUI_BingWallPaper.Main.__init__(self, parent)
self.Is_First_Boost = False
def MainOnShow(self, event):
thr = threading.Thread(target=self.MainOnShow_threading)
thr.start()
def MainOnShow_threading(self,*event):
wait = wx.BusyCursor()
self.Enable(False)
if self.Is_First_Boost == False:
print('正在获取下载信息')
data_url = "https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=4&mkt=zh-CN"
res = requests.get(data_url, timeout=3600)
with open("./Cache/BingWallPaper.json", "wb") as f:
f.write(res.content)
jsonData = open("./Cache/BingWallPaper.json",encoding='utf-8').read()
jsonData = json.loads(jsonData)
for i in range(0,4):
print('正在下载图片',i)
net_path = 'https://cn.bing.com' + jsonData['images'][i]['url']
res = requests.get(net_path, timeout=3600)
with open('./Cache/BingWallPaper_' + str(i) + '.jpg', "wb") as f:
f.write(res.content)
for i in range(0,4):
print('正在处理图片',i)
PLC = PIL.Image.open('./Cache/BingWallPaper_' + str(i) + '.jpg')
PLC = PLC.resize((192,108))
PLC.save('./Cache/BingWallPaper_' + str(i) + 'R.jpg')
self.Picture1.SetBitmap(wx.Bitmap('./Cache/BingWallPaper_0R.jpg'))
self.Picture2.SetBitmap(wx.Bitmap('./Cache/BingWallPaper_1R.jpg'))
self.Picture3.SetBitmap(wx.Bitmap('./Cache/BingWallPaper_2R.jpg'))
self.Picture4.SetBitmap(wx.Bitmap('./Cache/BingWallPaper_3R.jpg'))
self.Is_First_Boost = True
self.Enable(True)
del wait
def B_SETOnButtonClick(self, event):
imagepath = './Cache/BingWallPaper_' + str(self.M_Choise.GetSelection()) + '.jpg'
keyex = win32api.RegOpenKeyEx(
win32con.HKEY_CURRENT_USER,
"Control Panel\\Desktop",
0,
win32con.KEY_SET_VALUE,
)
win32api.RegSetValueEx(keyex, "WallpaperStyle", 0, win32con.REG_SZ, "2")
win32api.RegSetValueEx(keyex, "TileWallpaper", 0, win32con.REG_SZ, "0")
win32gui.SystemParametersInfo(
win32con.SPI_SETDESKWALLPAPER,
os.path.abspath(".") + imagepath,
win32con.SPIF_SENDWININICHANGE,
)
def Close(self, event):
self.Destroy()
##############################
# 主函数
##############################
def main():
global app
app = wx.App(False)
frame = CalcFrame(None)
frame.Show(True)
app.MainLoop()
if __name__ == "__main__":
main()