Mercurial > hg > pub > prymula > scripts
comparison bing4desktop/bing4desktop.py @ 34:9bcb32b7526a
bing4desktop-0.240209-0
author | prymula <prymula76@outlook.com> |
---|---|
date | Fri, 09 Feb 2024 14:39:54 +0100 |
parents | 1d063d3bf7ff |
children |
comparison
equal
deleted
inserted
replaced
33:1d063d3bf7ff | 34:9bcb32b7526a |
---|---|
1 #!/usr/bin/env python3 | 1 #!/usr/bin/env python3 |
2 # bing4desktop.py - skrypt tray dla Cinnamon oraz Matte i innych WM | 2 # bing4desktop.py - skrypt tray dla Cinnamon LxQt, oraz Matte i innych WM |
3 # inspiracja: https://pystray.readthedocs.io/en/latest/usage.html | 3 # inspiracja: https://pystray.readthedocs.io/en/latest/usage.html |
4 # oraz 'zasłyszane' w internecie :) | 4 # oraz 'zasłyszane' w internecie :) |
5 # licencja: Public Domain | 5 # licencja: Public Domain |
6 # edytor: Geany | 6 # edytor: Geany |
7 # data: 05-II-2024 | 7 # data: 05-II-2024 |
18 import json | 18 import json |
19 import tempfile | 19 import tempfile |
20 import shutil | 20 import shutil |
21 import glob | 21 import glob |
22 | 22 |
23 ver = "0.240208-2" | 23 ver = "0.240209-0" |
24 | 24 |
25 BING_URI_BASE = "http://www.bing.com" | 25 BING_URI_BASE = "http://www.bing.com" |
26 BING_WALLPAPER_PATH = "/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=en-US" | 26 BING_WALLPAPER_PATH = "/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=en-US" |
27 full_path="" | 27 full_path="" |
28 actualImage = 0 | 28 actualImage = 0 |
75 global full_path, TMP_COPYRIGHT, COPYRIGHT_TXT, TMP_TITLE, TITLE | 75 global full_path, TMP_COPYRIGHT, COPYRIGHT_TXT, TMP_TITLE, TITLE |
76 desktop_env = os.environ.get('DESKTOP_SESSION') | 76 desktop_env = os.environ.get('DESKTOP_SESSION') |
77 | 77 |
78 TMP_COPYRIGHT = COPYRIGHT_TXT | 78 TMP_COPYRIGHT = COPYRIGHT_TXT |
79 TMP_TITLE = TITLE | 79 TMP_TITLE = TITLE |
80 | 80 |
81 if len(full_path) == 0: | 81 # zawiesza |
82 messagebox.showinfo("Błąd","Niewybrano obrazu, najpierw wybierz obraz") | 82 #if len(full_path) == 0: |
83 return | 83 # messagebox.showinfo("Błąd","Niewybrano obrazu, najpierw wybierz obraz") |
84 # return | |
84 try: | 85 try: |
85 if desktop_env in ["gnome-classic", "gnome", "unity", "default"]: | 86 if desktop_env in ["gnome-classic", "gnome", "unity", "default"]: |
86 uri = "'file://%s'" % file_loc | 87 uri = "'file://%s'" % file_loc |
87 try: | 88 try: |
88 SCHEMA = "org.gnome.desktop.background" | 89 SCHEMA = "org.gnome.desktop.background" |
180 | 181 |
181 | 182 |
182 class Gui(): | 183 class Gui(): |
183 global TMP_COPYRIGHT, TMP_TITLE | 184 global TMP_COPYRIGHT, TMP_TITLE |
184 | 185 |
185 def __init__(self): | 186 def __init__(self, succes_set): |
186 self.window = tk.Tk() | 187 self.window = tk.Tk() |
187 self.image = None | 188 self.image = None |
188 for ico in ['./bing.ico', '/usr/share/bing4desktop/bing.ico']: | 189 for ico in ['./bing.ico', '/usr/share/bing4desktop/bing.ico']: |
189 try: | 190 try: |
190 self.image = Image.open(ico) | 191 self.image = Image.open(ico) |
201 item('Tapeta następna', lambda icon, item: self.change_pic(-1, icon)), | 202 item('Tapeta następna', lambda icon, item: self.change_pic(-1, icon)), |
202 item('Opis zdjęcia', lambda icon, item: icon.notify(TMP_TITLE + ' --- ' + TMP_COPYRIGHT)), | 203 item('Opis zdjęcia', lambda icon, item: icon.notify(TMP_TITLE + ' --- ' + TMP_COPYRIGHT)), |
203 item('O Programie', lambda icon, item: self.about()), | 204 item('O Programie', lambda icon, item: self.about()), |
204 item('Wyjdź', self.quit_window) | 205 item('Wyjdź', self.quit_window) |
205 ) | 206 ) |
207 | |
206 self.frame = tk.Frame(self.window, width=600, height=400) | 208 self.frame = tk.Frame(self.window, width=600, height=400) |
207 self.frame.pack() | 209 self.frame.pack() |
208 self.frame.place(anchor='center', relx=0.5, rely=5) | 210 self.frame.place(anchor='center', relx=0.5, rely=5) |
209 | 211 |
210 #self.window.title("Bing4Desktop") | 212 #self.window.title("Bing4Desktop") |
211 #self.window.geometry('800x600') | 213 #self.window.geometry('800x600') |
212 #self.window.protocol('WM_DELETE_WINDOW', self.withdraw_window) | 214 #self.window.protocol('WM_DELETE_WINDOW', self.withdraw_window) |
213 self.withdraw_window() | 215 |
216 | |
217 #self.withdraw_window() | |
218 #self.window.withdraw() | |
219 self.window.withdraw() | |
220 self.icon = pystray.Icon("name", self.image, "Bing4Desktop", self.menu) | |
221 print ("SUCCES: ", succes_set) | |
222 | |
223 # FIXME - Nie działą notyfikacja tylko dialog boc | |
224 if succes_set == False: | |
225 #self.icon.notify("", "Nie udało połączyć się z serwerem") | |
226 self.net_info() | |
227 | |
228 self.icon.run() | |
214 self.window.mainloop() | 229 self.window.mainloop() |
230 | |
231 def net_info(self): | |
232 messagebox.showinfo("Bing4Desktop","Nieudało się połączyć z serwerem !") | |
233 # możliwe że nieprawidlowe po wyjściu z aplikacji zwróci bląd :( | |
234 self.window.destroy() | |
235 self.window.update() | |
236 | |
237 | |
215 | 238 |
216 def about(self): | 239 def about(self): |
217 global ver | 240 global ver |
218 messagebox.showinfo("Bing4Desktop","Inspiracja:\npystray.readthedocs.io/en/latest/usage.html\n\nNapisał: Prymula\n\nLuty 2024\n\nLicencja:\nPublic Domain\n\nWersja: "+ver) | 241 messagebox.showinfo("Bing4Desktop","Inspiracja:\npystray.readthedocs.io/en/latest/usage.html\n\nNapisał: Prymula\n\nLuty 2024\n\nLicencja:\nPublic Domain\n\nWersja: "+ver) |
219 # możliwe że nieprawidlowe po wyjściu z aplikacji zwróci bląd :( | 242 # możliwe że nieprawidlowe po wyjściu z aplikacji zwróci bląd :( |
228 actualImage = actualImage + n; | 251 actualImage = actualImage + n; |
229 if (actualImage < 0): | 252 if (actualImage < 0): |
230 actualImage = 7 | 253 actualImage = 7 |
231 elif (actualImage > 7): | 254 elif (actualImage > 7): |
232 actualImage = 0 | 255 actualImage = 0 |
233 | 256 |
234 wp=WPaper() | 257 wp=WPaper() |
235 if wp.get(): | 258 try: |
259 wp.get() | |
236 BING_WALLPAPER_PATH = BASE+str(actualImage)+OFF | 260 BING_WALLPAPER_PATH = BASE+str(actualImage)+OFF |
237 if wp.get() == False: | 261 if wp.get() == False: |
238 cleanup() | 262 cleanup() |
239 exit | 263 exit |
240 | 264 |
249 | 273 |
250 img = Image.open(full_path) #.convert('RGBA') # PIL solution | 274 img = Image.open(full_path) #.convert('RGBA') # PIL solution |
251 self.tmp = img.resize((600, 400), None, None, 3.0) | 275 self.tmp = img.resize((600, 400), None, None, 3.0) |
252 self.tmp.show() | 276 self.tmp.show() |
253 icon.notify(TITLE + ' --- ' + COPYRIGHT_TXT) | 277 icon.notify(TITLE + ' --- ' + COPYRIGHT_TXT) |
254 | 278 except: |
279 print ("Serewr niedostępny") | |
280 | |
255 def quit_window(self): | 281 def quit_window(self): |
256 self.icon.stop() | 282 self.icon.stop() |
257 self.window.destroy() | 283 self.window.destroy() |
258 | 284 |
259 def show_window(self): | 285 def show_window(self): |
260 self.icon.stop() | 286 self.icon.stop() |
261 self.window.protocol('WM_DELETE_WINDOW', self.withdraw_window) | 287 self.window.protocol('WM_DELETE_WINDOW', self.withdraw_window) |
262 self.window.after(0, self.window.deiconify) | 288 self.window.after(0, self.window.deiconify) |
263 | 289 """ |
264 def withdraw_window(self): | 290 def withdraw_window(self): |
265 self.window.withdraw() | 291 self.window.withdraw() |
266 self.icon = pystray.Icon("name", self.image, "title", self.menu) | 292 self.icon = pystray.Icon("name", self.image, "Bing4Desktop", self.menu) |
267 self.icon.run() | 293 self.icon.run() |
268 | 294 """ |
269 def cleanup(): | 295 def cleanup(): |
270 # NIEBEZPIECZNA ! lepiej niczym innym nie nadpisywać tych zmiennych | 296 # NIEBEZPIECZNA ! lepiej niczym innym nie nadpisywać tych zmiennych |
271 shutil.rmtree(tmp_path) | 297 shutil.rmtree(tmp_path) |
272 | 298 |
273 if __name__ in '__main__': | 299 if __name__ in '__main__': |
274 wp=WPaper() | 300 wp=WPaper() |
275 if wp.get(): | 301 w = False |
302 try: | |
303 w = wp.get() | |
276 wp.set(full_path, True) | 304 wp.set(full_path, True) |
277 g = Gui() | 305 except: |
278 cleanup() | 306 print ("Serewr niedostępny") |
307 #if w: | |
308 | |
309 g = Gui(w) | |
310 cleanup() |