From c8144de0999f53d7ca2c1692564aa927965130af Mon Sep 17 00:00:00 2001 From: xiaochi Date: Sun, 7 Feb 2021 00:29:15 +0800 Subject: [PATCH 1/5] win10 --- README.md | 5 ++++ himawaripy/utils.py | 30 ++++++++++++++++++++++-- setup.py | 2 +- win/auto.bat | 1 + win/install.bat | 3 +++ win/run_silently.vbs | 6 +++++ win/task.xml | 55 ++++++++++++++++++++++++++++++++++++++++++++ win/uninstall.bat | 3 +++ 8 files changed, 102 insertions(+), 3 deletions(-) create mode 100644 win/auto.bat create mode 100644 win/install.bat create mode 100644 win/run_silently.vbs create mode 100644 win/task.xml create mode 100644 win/uninstall.bat diff --git a/README.md b/README.md index d97e7b1..80635e0 100644 --- a/README.md +++ b/README.md @@ -143,6 +143,11 @@ Finally, to launch it, enter this into the console: launchctl load ~/Library/LaunchAgents/org.boramalper.himawaripy.plist +### For Win10 Users + +1. Edit `win\auto.bat` if you like. +2. `win\install.bat` to install a schedule. +3. `win\uninstall.bat` to uninstall the schedule. ## Uninstallation diff --git a/himawaripy/utils.py b/himawaripy/utils.py index d91e62e..7673cd1 100644 --- a/himawaripy/utils.py +++ b/himawaripy/utils.py @@ -5,10 +5,33 @@ from distutils.version import LooseVersion +def set_wallpaper_from_bmp(bmp_path): + import win32api + import win32gui + from win32.lib import win32con + #打开指定注册表路径 + reg_key = win32api.RegOpenKeyEx( + win32con.HKEY_CURRENT_USER, "Control Panel\\Desktop", 0, win32con.KEY_SET_VALUE) + #最后的参数:2拉伸,0居中,6适应,10填充,0平铺 + win32api.RegSetValueEx(reg_key, "WallpaperStyle", 0, win32con.REG_SZ, "2") + #最后的参数:1表示平铺,拉伸居中等都是0 + win32api.RegSetValueEx(reg_key, "TileWallpaper", 0, win32con.REG_SZ, "0") + #刷新桌面 + win32gui.SystemParametersInfo( + win32con.SPI_SETDESKWALLPAPER, bmp_path, win32con.SPIF_SENDWININICHANGE) + + def set_background(file_path): de = get_desktop_environment() - - if de == "mac": + if de == "windows": + import PIL.Image + img_path = file_path + img_dir = os.path.dirname(img_path) + bmpImage = PIL.Image.open(img_path) + new_bmp_path = os.path.join(img_dir, 'wallpaper.bmp') + bmpImage.save(new_bmp_path, "BMP") + set_wallpaper_from_bmp(new_bmp_path) + elif de == "mac": subprocess.call( [ "osascript", @@ -249,3 +272,6 @@ def fetch_envvar(varname): os.environ[varname] = val else: print("Could NOT retrieve env. var. {}".format(varname)) + +if __name__ == "__main__": + set_background("D:\data\hima\himawari-20210206T121000.png") diff --git a/setup.py b/setup.py index 10c0d18..a34a3a3 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import setup, find_packages -with open("README.md", "r") as f: +with open("README.md", "r", encoding='UTF-8') as f: long_description = f.read() setup( diff --git a/win/auto.bat b/win/auto.bat new file mode 100644 index 0000000..f4f77b1 --- /dev/null +++ b/win/auto.bat @@ -0,0 +1 @@ +himawaripy --auto-offset --output-dir e:\data\hima \ No newline at end of file diff --git a/win/install.bat b/win/install.bat new file mode 100644 index 0000000..fbf198b --- /dev/null +++ b/win/install.bat @@ -0,0 +1,3 @@ +@Echo off +schtasks /Create /XML ./task.xml /TN himawari8 +pause \ No newline at end of file diff --git a/win/run_silently.vbs b/win/run_silently.vbs new file mode 100644 index 0000000..43de7e9 --- /dev/null +++ b/win/run_silently.vbs @@ -0,0 +1,6 @@ +Dim path +set oShell = CreateObject("WScript.Shell") +set fso = CreateObject("Scripting.FileSystemObject") +path = fso.GetAbsolutePathName("./auto.bat") +' msgbox path +oShell.run path, 0, ture diff --git a/win/task.xml b/win/task.xml new file mode 100644 index 0000000..0a04b64 --- /dev/null +++ b/win/task.xml @@ -0,0 +1,55 @@ + + + + konosubakonoakua + get himawari8 images and set as background + \himawari8 + + + + + PT1H + P1D + false + + 2019-12-03T11:25:30 + true + + 1 + + + + + + InteractiveToken + LeastPrivilege + + + + IgnoreNew + true + true + true + false + false + + true + false + + true + true + false + false + false + true + false + PT72H + 7 + + + + D:\doc\repo\himawaripy\win\run_silently.vbs + D:\doc\repo\himawaripy\win + + + \ No newline at end of file diff --git a/win/uninstall.bat b/win/uninstall.bat new file mode 100644 index 0000000..cdbb8c7 --- /dev/null +++ b/win/uninstall.bat @@ -0,0 +1,3 @@ +schtasks /Delete /TN himawari8 + +pause \ No newline at end of file From 0da7ceb660b67e69dd0692a54d7081ba31fe6965 Mon Sep 17 00:00:00 2001 From: xiaochi Date: Sun, 7 Feb 2021 00:53:08 +0800 Subject: [PATCH 2/5] schedule --- README.md | 3 +-- win/install.bat | 3 --- win/task.xml | 55 ----------------------------------------------- win/uninstall.bat | 3 --- 4 files changed, 1 insertion(+), 63 deletions(-) delete mode 100644 win/install.bat delete mode 100644 win/task.xml delete mode 100644 win/uninstall.bat diff --git a/README.md b/README.md index 80635e0..7b0f1b9 100644 --- a/README.md +++ b/README.md @@ -146,8 +146,7 @@ Finally, to launch it, enter this into the console: ### For Win10 Users 1. Edit `win\auto.bat` if you like. -2. `win\install.bat` to install a schedule. -3. `win\uninstall.bat` to uninstall the schedule. +2. add `win\run_silently.vbs` to schedule, and config it to once an hour. ## Uninstallation diff --git a/win/install.bat b/win/install.bat deleted file mode 100644 index fbf198b..0000000 --- a/win/install.bat +++ /dev/null @@ -1,3 +0,0 @@ -@Echo off -schtasks /Create /XML ./task.xml /TN himawari8 -pause \ No newline at end of file diff --git a/win/task.xml b/win/task.xml deleted file mode 100644 index 0a04b64..0000000 --- a/win/task.xml +++ /dev/null @@ -1,55 +0,0 @@ - - - - konosubakonoakua - get himawari8 images and set as background - \himawari8 - - - - - PT1H - P1D - false - - 2019-12-03T11:25:30 - true - - 1 - - - - - - InteractiveToken - LeastPrivilege - - - - IgnoreNew - true - true - true - false - false - - true - false - - true - true - false - false - false - true - false - PT72H - 7 - - - - D:\doc\repo\himawaripy\win\run_silently.vbs - D:\doc\repo\himawaripy\win - - - \ No newline at end of file diff --git a/win/uninstall.bat b/win/uninstall.bat deleted file mode 100644 index cdbb8c7..0000000 --- a/win/uninstall.bat +++ /dev/null @@ -1,3 +0,0 @@ -schtasks /Delete /TN himawari8 - -pause \ No newline at end of file From 4f10e5549d3b6c0586f9a04e178f4e10f15cd794 Mon Sep 17 00:00:00 2001 From: xiaochi Date: Sun, 7 Feb 2021 00:54:41 +0800 Subject: [PATCH 3/5] 10 minutes --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7b0f1b9..b8a3def 100644 --- a/README.md +++ b/README.md @@ -146,7 +146,7 @@ Finally, to launch it, enter this into the console: ### For Win10 Users 1. Edit `win\auto.bat` if you like. -2. add `win\run_silently.vbs` to schedule, and config it to once an hour. +2. add `win\run_silently.vbs` to schedule, and config it to once per 10 minutes. ## Uninstallation From 844fc91c9208a3d13c3be979c12fe63dab335888 Mon Sep 17 00:00:00 2001 From: xiaochi Date: Thu, 11 Feb 2021 12:29:34 +0800 Subject: [PATCH 4/5] pypiwin32 if windows --- setup.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index a34a3a3..e2355ab 100644 --- a/setup.py +++ b/setup.py @@ -1,8 +1,14 @@ from setuptools import setup, find_packages +import platform with open("README.md", "r", encoding='UTF-8') as f: long_description = f.read() +install_requires = ["appdirs", "pillow", "python-dateutil"] +sys = platform.system() +if sys == "Windows": + install_requires.append("pypiwin32") + setup( name="himawaripy", version="2.2.0", @@ -14,7 +20,7 @@ "as its taken by Himawari 8 (ひまわり8号) and sets it as your desktop background.", long_description=long_description, long_description_content_type="text/markdown", - install_requires=["appdirs", "pillow", "python-dateutil"], + install_requires=install_requires, packages=find_packages(), entry_points={"console_scripts": ["himawaripy=himawaripy.__main__:main"]}, ) From 3baa3293fc8c6c44ef4f8f353f729cf67c9f53d1 Mon Sep 17 00:00:00 2001 From: xiaochi Date: Thu, 11 Feb 2021 12:31:41 +0800 Subject: [PATCH 5/5] center --- himawaripy/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/himawaripy/utils.py b/himawaripy/utils.py index 7673cd1..81c68be 100644 --- a/himawaripy/utils.py +++ b/himawaripy/utils.py @@ -13,7 +13,7 @@ def set_wallpaper_from_bmp(bmp_path): reg_key = win32api.RegOpenKeyEx( win32con.HKEY_CURRENT_USER, "Control Panel\\Desktop", 0, win32con.KEY_SET_VALUE) #最后的参数:2拉伸,0居中,6适应,10填充,0平铺 - win32api.RegSetValueEx(reg_key, "WallpaperStyle", 0, win32con.REG_SZ, "2") + win32api.RegSetValueEx(reg_key, "WallpaperStyle", 0, win32con.REG_SZ, "0") #最后的参数:1表示平铺,拉伸居中等都是0 win32api.RegSetValueEx(reg_key, "TileWallpaper", 0, win32con.REG_SZ, "0") #刷新桌面 @@ -274,4 +274,4 @@ def fetch_envvar(varname): print("Could NOT retrieve env. var. {}".format(varname)) if __name__ == "__main__": - set_background("D:\data\hima\himawari-20210206T121000.png") + set_background("e:\data\hima\himawari-20210211T021000.png")