Added Linux support

This commit is contained in:
Данил 2022-08-25 10:20:13 +03:00
parent be9c3c2093
commit 8240cb1fba

63
src/linux/main.py Normal file
View file

@ -0,0 +1,63 @@
from pystray import MenuItem, Menu, Icon
from PIL import Image
import notify2
import schedule
import os
import sys
import psutil
import time
path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, path)
# noinspection PyUnresolvedReferences
from functions.wallpaper import Wallpaper
class Nasa(Wallpaper):
def __init__(self):
super().__init__()
@staticmethod
def resource_path(relative_path):
base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__)))
return os.path.join(base_path, relative_path)
def tray(self):
tray = Icon("EveryNasa",
title="EveryNasa",
icon=Image.open(self.resource_path("./icons/icon.ico")),
menu=Menu(
MenuItem("Выход",
self.kill_program),
))
tray.run()
def kill_program(self):
for proc in psutil.process_iter():
if proc.name() == "EveryNasa":
proc.kill()
@staticmethod
def notify(title, message):
notify2.init("EveryNasa")
notice = notify2.Notification(title, message)
notice.show()
return
def main(self):
wall_check = Wallpaper.check(self)
Wallpaper.download(self)
wall_set = Wallpaper.set()
self.notify("EveryNasa", wall_check or wall_set)
nasa = Nasa()
nasa.main()
schedule.every(3).hours.do(nasa.main)
while True:
schedule.run_pending()
nasa.tray()
time.sleep(1)