From ed1b7d83861cfc40abcb0fffe17b1863a0ac077f Mon Sep 17 00:00:00 2001 From: Redume Date: Fri, 29 Jul 2022 15:56:24 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=20=D0=B0?= =?UTF-8?q?=D0=B2=D1=82=D0=BE=D0=B7=D0=B0=D0=BF=D1=83=D1=81=D0=BA=20=D0=B8?= =?UTF-8?q?=D0=B7-=D0=B7=D0=B0=20=D0=B1=D0=B0=D0=B3=D0=B0=20=D0=BA=D0=BE?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D1=8B=D0=B9=20=D0=BD=D0=B5=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=BB=D1=83=D1=87=D0=B0=D0=BB=D0=BE=D1=81=D1=8C=20=D0=B8=D1=81?= =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=B8=D1=82=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.py | 41 ----------------------------------------- main.py | 53 ----------------------------------------------------- 2 files changed, 94 deletions(-) delete mode 100644 config.py diff --git a/config.py b/config.py deleted file mode 100644 index 88aa2a7..0000000 --- a/config.py +++ /dev/null @@ -1,41 +0,0 @@ -import configparser -import os - - -class Config: - - def create_config(self, path): - if not os.path.exists(path): - config = configparser.ConfigParser() - config.add_section("Settings") - - config.set("Settings", "autorun", "False") - with open(path, "w") as file: - config.write(file) - else: - return print("The file exists") - - def get_config(self, path): - if not os.path.exists(path): - self.create_config(path) - - config = configparser.ConfigParser() - config.read(path) - return config - - def get_setting(self, path, section, setting): - config = self.get_config(path) - value = config.get(section, setting) - return value - - def update_setting(self, path, section, setting, value): - config = self.get_config(path) - config.set(section, setting, value) - with open(path, "w") as file: - config.write(file) - - def delete_setting(self, path, section, setting): - config = self.get_config(path) - config.remove_option(section, setting) - with open(path, "w") as file: - config.write(file) diff --git a/main.py b/main.py index c90a448..e1ff919 100644 --- a/main.py +++ b/main.py @@ -41,67 +41,15 @@ class Nasa(Config): 'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36'} self.photoName = "everydayphotonasa.jpg" self.toaster = ToastNotifier() - self.state = json.loads( - Config.get_setting(self, - path="config.ini", - section="Settings", - setting="autorun") - .lower()) def resource_path(self, relative_path): base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__))) return os.path.join(base_path, relative_path) - def autorun(self): - self.state = not MenuItem.checked - - if not ctypes.windll.shell32.IsUserAnAdmin() != 0: - elevate(show_console=False) - - if self.state is False: - print("Автозапуск включен.") - path = os.path.dirname(os.path.realpath(__file__)) - address = os.path.join(path, "start.bat") - key_value = "SOFTWARE\Microsoft\Windows\CurrentVersion\Run" - user = getpass.getuser() - key = reg.OpenKey(reg.HKEY_LOCAL_MACHINE, key_value, 0, reg.KEY_ALL_ACCESS) - reg.SetValueEx(key, user, 0, reg.REG_SZ, address) - reg.CloseKey(key) - Config.update_setting(self, - path="config.ini", - section="Settings", - setting="autorun", - value="True") - - self.toaster.show_toast("EveryDayPhotoNasa", - "Программа добавлена в автозапуск.", - duration=3, - icon_path=self.resource_path("nasa.ico")) - else: - print("Программа удалена из автозапуска.") - key_value = "SOFTWARE\Microsoft\Windows\CurrentVersion\Run" - user = getpass.getuser() - key = reg.OpenKey(reg.HKEY_LOCAL_MACHINE, key_value, 0, reg.KEY_ALL_ACCESS) - reg.DeleteValue(key, user) - reg.CloseKey(key) - Config.update_setting(self, - path="config.ini", - section="Settings", - setting="autorun", - value="False") - - self.toaster.show_toast("EveryDayPhotoNasa", - "Программа удалена из автозапуска.", - duration=3, - icon_path=self.resource_path("nasa.ico")) - def tray(self): tray = Icon("EveryDayPhotoNasa", title="EveryDayPhotoNasa", icon=Image.open(self.resource_path("nasa.ico")), menu=Menu( - MenuItem("Автозапуск", - self.autorun, - checked=lambda item: self.state), MenuItem("Выход", self.tray_close), )) @@ -131,7 +79,6 @@ class Nasa(Config): icon_path=self.resource_path("nasa.ico")) def set_wallpaper(self): - print(self.state) path = os.path.abspath(self.photoName) ctypes.windll.user32.SystemParametersInfoW(20, 0, path, 0) self.toaster.show_toast("EveryDayPhotoNasa",