Mercurial > hg > pub > prymula > scripts
diff bing4desktop/bing4desktop.py @ 11:c01d7edb9cb9
bing4desktop-0.240206-0
author | prymula <prymula76@outlook.com> |
---|---|
date | Tue, 06 Feb 2024 11:58:47 +0100 |
parents | ed9556d0c5d7 |
children | 73fd89b46da4 |
line wrap: on
line diff
--- a/bing4desktop/bing4desktop.py Tue Feb 06 00:30:36 2024 +0100 +++ b/bing4desktop/bing4desktop.py Tue Feb 06 11:58:47 2024 +0100 @@ -20,22 +20,22 @@ import json import tempfile import shutil +import glob -ver = "0.240205-4" +ver = "0.240206-0" BING_URI_BASE = "http://www.bing.com" -BING_WALLPAPER_PATH = "/HPImageArchive.aspx?format=js&idx=50&n=1&mkt=en-US" +BING_WALLPAPER_PATH = "/HPImageArchive.aspx?format=js&idx=1&n=1&mkt=en-US" full_path="" actualImage = -1 COPYRIGHT_TXT = "" +TITLE = "" tmp_path = tempfile.mkdtemp() - - class WPaper: def get(self): - global full_path, COPYRIGHT_TXT + global full_path, COPYRIGHT_TXT, TITLE # open the Bing HPImageArchive URI and ask for a JSON response resp = requests.get(BING_URI_BASE + BING_WALLPAPER_PATH) @@ -43,6 +43,8 @@ json_response = json.loads(resp.content) wallpaper_path = json_response['images'][0]['url'] COPYRIGHT_TXT = json_response['images'][0]['copyright'] + TITLE = json_response['images'][0]['title'] + filename = wallpaper_path.split('/')[-1] wallpaper_uri = BING_URI_BASE + wallpaper_path filename_short = filename.split('&') @@ -173,16 +175,28 @@ class Gui(): - global COPYRIGHT_TXT + global COPYRIGHT_TXT, TITLE def __init__(self): self.window = tk.Tk() - self.image = Image.open("bing.ico") + self.image = None + for ico in ['./bing.ico', '/usr/share/bing4desktop/bing.ico']: + try: + self.image = Image.open(ico) + except FileNotFoundError as fs: + print ('W bieżącym katalogu, brak ikony, ', fs) + finally: + break + + #if self.image != None: + # break + + self.tmp = None self.menu = ( item("Ustaw Tapetę", lambda icon, item: wp.set(full_path, True)), item('Tapeta poprzednia', lambda icon, item: self.change_pic(1)), item('Tapeta następna', lambda icon, item: self.change_pic(-1)), - item('Opis zdjęcia', lambda icon, item: icon.notify(COPYRIGHT_TXT)), + item('Opis zdjęcia', lambda icon, item: icon.notify(TITLE + ' --- ' + COPYRIGHT_TXT)), item('O Programie', lambda icon, item: self.about()), item('Wyjdź', self.quit_window) @@ -204,7 +218,6 @@ self.window.destroy() self.window.update() - def change_pic(self, n): global actualImage, BING_WALLPAPER_PATH BASE = "/HPImageArchive.aspx?format=js&idx=" @@ -216,8 +229,6 @@ elif (actualImage > 10): actualImage = 0 - print ("FULL: ", len(full_path)) - wp=WPaper() if wp.get(): BING_WALLPAPER_PATH = BASE+str(actualImage)+OFF @@ -225,21 +236,28 @@ cleanup() exit + # Wszystko pięknie tylko metoda 'show', zmienia nazwę pliku przechowywanego w TMP + # Pozatym nie ubija a nie znalazłem nic lepszego + print ("GLOB: ", glob.glob( os.path.join('/tmp', '*.PNG'))) + for infile in glob.glob( os.path.join('/tmp', '*.PNG')): + print ("INFILE: ", infile) + viewer = subprocess.Popen(['/usr/bin/eom', infile]) + viewer.terminate() + viewer.kill() # make sure the viewer is gone; not needed on Windows + img = Image.open(full_path) #.convert('RGBA') # PIL solution - tmp = img.resize((600, 400), None, None, 3.0) - tmp.show() + self.tmp = img.resize((600, 400), None, None, 3.0) + self.tmp.show() def quit_window(self): self.icon.stop() self.window.destroy() - def show_window(self): self.icon.stop() self.window.protocol('WM_DELETE_WINDOW', self.withdraw_window) self.window.after(0, self.window.deiconify) - def withdraw_window(self): self.window.withdraw() self.icon = pystray.Icon("name", self.image, "title", self.menu)