comparison bing4desktop/bing4desktop.py @ 17:3b8fd6a7f2d0

bing4desktop-0.240207-2
author prymula <prymula76@outlook.com>
date Wed, 07 Feb 2024 12:11:34 +0100
parents 2dea5bff9c0c
children e7a6488c02b7
comparison
equal deleted inserted replaced
16:2dea5bff9c0c 17:3b8fd6a7f2d0
20 import json 20 import json
21 import tempfile 21 import tempfile
22 import shutil 22 import shutil
23 import glob 23 import glob
24 24
25 ver = "0.240206-4" 25 ver = "0.240207-2"
26 26
27 BING_URI_BASE = "http://www.bing.com" 27 BING_URI_BASE = "http://www.bing.com"
28 BING_WALLPAPER_PATH = "/HPImageArchive.aspx?format=js&idx=1&n=1&mkt=en-US" 28 BING_WALLPAPER_PATH = "/HPImageArchive.aspx?format=js&idx=1&n=1&mkt=en-US"
29 full_path="" 29 full_path=""
30 actualImage = -1 30 actualImage = 1
31 COPYRIGHT_TXT = "" 31 COPYRIGHT_TXT = ""
32 TITLE = "" 32 TITLE = ""
33 TMP_COPYRIGHT = ""
34 TMP_TITLE = ""
33 35
34 tmp_path = tempfile.mkdtemp() 36 tmp_path = tempfile.mkdtemp()
35 37
36 class WPaper: 38 class WPaper:
37 def get(self): 39 def get(self):
70 COPYRIGHT_TXT = "[ERROR] non-200 response from Bing server for " + str(format(BING_URI_BASE + BING_WALLPAPER_PATH)) 72 COPYRIGHT_TXT = "[ERROR] non-200 response from Bing server for " + str(format(BING_URI_BASE + BING_WALLPAPER_PATH))
71 return False 73 return False
72 return True 74 return True
73 75
74 def set(self,file_loc, first_run): 76 def set(self,file_loc, first_run):
75 global full_path 77 global full_path, TMP_COPYRIGHT, COPYRIGHT_TXT, TMP_TITLE, TITLE
76 desktop_env = os.environ.get('DESKTOP_SESSION') 78 desktop_env = os.environ.get('DESKTOP_SESSION')
79
80 TMP_COPYRIGHT = COPYRIGHT_TXT
81 TMP_TITLE = TITLE
77 82
78 if len(full_path) == 0: 83 if len(full_path) == 0:
79 messagebox.showinfo("Błąd","Niewybrano obrazu, najpierw wybierz obraz") 84 messagebox.showinfo("Błąd","Niewybrano obrazu, najpierw wybierz obraz")
80 return 85 return
81 try: 86 try:
173 sys.stderr.write("ERROR: Failed to set wallpaper. There might be a bug.\n") 178 sys.stderr.write("ERROR: Failed to set wallpaper. There might be a bug.\n")
174 return False 179 return False
175 180
176 181
177 class Gui(): 182 class Gui():
178 global COPYRIGHT_TXT, TITLE 183 global TMP_COPYRIGHT, TMP_TITLE
179 184
180 def __init__(self): 185 def __init__(self):
181 self.window = tk.Tk() 186 self.window = tk.Tk()
182 self.image = None 187 self.image = None
183 for ico in ['./bing.ico', '/usr/share/bing4desktop/bing.ico']: 188 for ico in ['./bing.ico', '/usr/share/bing4desktop/bing.ico']:
192 self.tmp = None 197 self.tmp = None
193 self.menu = ( 198 self.menu = (
194 item("Ustaw Tapetę", lambda icon, item: wp.set(full_path, True)), 199 item("Ustaw Tapetę", lambda icon, item: wp.set(full_path, True)),
195 item('Tapeta poprzednia', lambda icon, item: self.change_pic(1)), 200 item('Tapeta poprzednia', lambda icon, item: self.change_pic(1)),
196 item('Tapeta następna', lambda icon, item: self.change_pic(-1)), 201 item('Tapeta następna', lambda icon, item: self.change_pic(-1)),
197 item('Opis zdjęcia', lambda icon, item: icon.notify(TITLE + ' --- ' + COPYRIGHT_TXT)), 202 item('Opis zdjęcia', lambda icon, item: icon.notify(TMP_TITLE + ' --- ' + TMP_COPYRIGHT)),
198 item('O Programie', lambda icon, item: self.about()), 203 item('O Programie', lambda icon, item: self.about()),
199 204
200 item('Wyjdź', self.quit_window) 205 item('Wyjdź', self.quit_window)
201 ) 206 )
202 self.frame = tk.Frame(self.window, width=600, height=400) 207 self.frame = tk.Frame(self.window, width=600, height=400)
218 223
219 def change_pic(self, n): 224 def change_pic(self, n):
220 global actualImage, BING_WALLPAPER_PATH 225 global actualImage, BING_WALLPAPER_PATH
221 BASE = "/HPImageArchive.aspx?format=js&idx=" 226 BASE = "/HPImageArchive.aspx?format=js&idx="
222 OFF = "&n=1&mkt=en-US" 227 OFF = "&n=1&mkt=en-US"
223 228
224 actualImage = actualImage + n; 229 actualImage = actualImage + n;
225 if (actualImage < 0): 230 if (actualImage < 0):
226 actualImage = 10 231 actualImage = 7
227 elif (actualImage > 10): 232 elif (actualImage > 7):
228 actualImage = 0 233 actualImage = 0
229 234
230 wp=WPaper() 235 wp=WPaper()
231 if wp.get(): 236 if wp.get():
232 BING_WALLPAPER_PATH = BASE+str(actualImage)+OFF 237 BING_WALLPAPER_PATH = BASE+str(actualImage)+OFF