annotate bing4desktop/bing4desktop.py @ 37:ec5ca25ee7e4

bing4desktop-0.240209-0_rm_CzytajTo
author prymula <prymula76@outlook.com>
date Fri, 09 Feb 2024 23:32:13 +0100
parents 9bcb32b7526a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
1 #!/usr/bin/env python3
34
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
2 # bing4desktop.py - skrypt tray dla Cinnamon LxQt, oraz Matte i innych WM
10
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
3 # inspiracja: https://pystray.readthedocs.io/en/latest/usage.html
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
4 # oraz 'zasłyszane' w internecie :)
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
5 # licencja: Public Domain
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
6 # edytor: Geany
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
7 # data: 05-II-2024
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
8 # napisał: Prymula
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
9
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
10 import pystray
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
11 from pystray import Icon as icon, Menu as menu, MenuItem as item
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
12 import tkinter as tk
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
13 from tkinter import messagebox
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
14 from PIL import ImageTk, Image
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
15
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
16 import os, sys, subprocess
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
17 import requests
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
18 import json
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
19 import tempfile
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
20 import shutil
11
c01d7edb9cb9 bing4desktop-0.240206-0
prymula <prymula76@outlook.com>
parents: 10
diff changeset
21 import glob
10
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
22
34
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
23 ver = "0.240209-0"
10
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
24
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
25 BING_URI_BASE = "http://www.bing.com"
31
c1061f0721d7 bing4desktop-0.240208-1.2
prymula <prymula76@outlook.com>
parents: 30
diff changeset
26 BING_WALLPAPER_PATH = "/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=en-US"
10
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
27 full_path=""
31
c1061f0721d7 bing4desktop-0.240208-1.2
prymula <prymula76@outlook.com>
parents: 30
diff changeset
28 actualImage = 0
10
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
29 COPYRIGHT_TXT = ""
11
c01d7edb9cb9 bing4desktop-0.240206-0
prymula <prymula76@outlook.com>
parents: 10
diff changeset
30 TITLE = ""
17
3b8fd6a7f2d0 bing4desktop-0.240207-2
prymula <prymula76@outlook.com>
parents: 16
diff changeset
31 TMP_COPYRIGHT = ""
3b8fd6a7f2d0 bing4desktop-0.240207-2
prymula <prymula76@outlook.com>
parents: 16
diff changeset
32 TMP_TITLE = ""
10
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
33
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
34 tmp_path = tempfile.mkdtemp()
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
35
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
36 class WPaper:
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
37 def get(self):
11
c01d7edb9cb9 bing4desktop-0.240206-0
prymula <prymula76@outlook.com>
parents: 10
diff changeset
38 global full_path, COPYRIGHT_TXT, TITLE
10
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
39 # open the Bing HPImageArchive URI and ask for a JSON response
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
40 resp = requests.get(BING_URI_BASE + BING_WALLPAPER_PATH)
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
41
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
42 if resp.status_code == 200:
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
43 json_response = json.loads(resp.content)
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
44 wallpaper_path = json_response['images'][0]['url']
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
45 COPYRIGHT_TXT = json_response['images'][0]['copyright']
11
c01d7edb9cb9 bing4desktop-0.240206-0
prymula <prymula76@outlook.com>
parents: 10
diff changeset
46 TITLE = json_response['images'][0]['title']
c01d7edb9cb9 bing4desktop-0.240206-0
prymula <prymula76@outlook.com>
parents: 10
diff changeset
47
10
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
48 filename = wallpaper_path.split('/')[-1]
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
49 wallpaper_uri = BING_URI_BASE + wallpaper_path
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
50 filename_short = filename.split('&')
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
51 print ("filemname_short", filename_short[0])
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
52 # open the actual wallpaper uri, and write the response as an image on the filesystem
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
53 response = requests.get(wallpaper_uri)
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
54 if resp.status_code == 200:
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
55 desktop_env = os.environ.get('DESKTOP_SESSION')
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
56 if desktop_env=="windows":
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
57 messagebox.showinfo("Błąd","Brak wsparcia dla Windows i Mac !")
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
58 cleanup()
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
59 exit
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
60 else:
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
61 full_path = tmp_path + filename_short[0]
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
62 with open(full_path, 'wb') as f:
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
63 f.write(response.content)
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
64 else:
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
65 raise ValueError("[ERROR] non-200 response from Bing server for '{}'".format(wallpaper_uri))
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
66 COPYRIGHT_TXT = "[ERROR] non-200 response from Bing server for " + str(format(wallpaper_uri))
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
67 return False
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
68 else:
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
69 raise ValueError("[ERROR] non-200 response from Bing server for '{}'".format(BING_URI_BASE + BING_WALLPAPER_PATH))
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
70 COPYRIGHT_TXT = "[ERROR] non-200 response from Bing server for " + str(format(BING_URI_BASE + BING_WALLPAPER_PATH))
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
71 return False
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
72 return True
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
73
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
74 def set(self,file_loc, first_run):
17
3b8fd6a7f2d0 bing4desktop-0.240207-2
prymula <prymula76@outlook.com>
parents: 16
diff changeset
75 global full_path, TMP_COPYRIGHT, COPYRIGHT_TXT, TMP_TITLE, TITLE
10
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
76 desktop_env = os.environ.get('DESKTOP_SESSION')
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
77
17
3b8fd6a7f2d0 bing4desktop-0.240207-2
prymula <prymula76@outlook.com>
parents: 16
diff changeset
78 TMP_COPYRIGHT = COPYRIGHT_TXT
3b8fd6a7f2d0 bing4desktop-0.240207-2
prymula <prymula76@outlook.com>
parents: 16
diff changeset
79 TMP_TITLE = TITLE
34
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
80
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
81 # zawiesza
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
82 #if len(full_path) == 0:
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
83 # messagebox.showinfo("Błąd","Niewybrano obrazu, najpierw wybierz obraz")
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
84 # return
10
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
85 try:
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
86 if desktop_env in ["gnome-classic", "gnome", "unity", "default"]:
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
87 uri = "'file://%s'" % file_loc
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
88 try:
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
89 SCHEMA = "org.gnome.desktop.background"
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
90 KEY = "picture-uri"
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
91 gsettings = Gio.Settings.new(SCHEMA)
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
92 gsettings.set_string(KEY, uri)
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
93 except:
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
94 args = ["gsettings", "set", "org.gnome.desktop.background", "picture-uri", uri]
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
95 subprocess.Popen(args)
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
96 elif desktop_env in ["cinnamon"]:
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
97 uri = "'file://%s'" % file_loc
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
98 try:
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
99 SCHEMA = "org.cinnamon.desktop.background"
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
100 KEY = "picture-uri"
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
101 gsettings = Gio.Settings.new(SCHEMA)
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
102 gsettings.set_string(KEY, uri)
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
103 except:
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
104 args = ["gsettings", "set", "org.cinnamon.desktop.background", "picture-uri", uri]
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
105 subprocess.Popen(args)
21
7f02682ff5ed bing4desktop-0.240207-4
prymula <prymula76@outlook.com>
parents: 19
diff changeset
106 elif desktop_env in ['mate', 'lightdm-xsession']:
10
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
107 try: # MATE >= 1.6
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
108 # info from http://wiki.mate-desktop.org/docs:gsettings
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
109 args = ["gsettings", "set", "org.mate.background", "picture-filename", "'%s'" % file_loc]
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
110 subprocess.Popen(args)
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
111 except: # MATE < 1.6
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
112 # From https://bugs.launchpad.net/variety/+bug/1033918
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
113 args = ["mateconftool-2","-t","string","--set","/desktop/mate/background/picture_filename",'"%s"' %file_loc]
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
114 subprocess.Popen(args)
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
115 elif desktop_env=="gnome2": # Not tested
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
116 # From https://bugs.launchpad.net/variety/+bug/1033918
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
117 args = ["gconftool-2","-t","string","--set","/desktop/gnome/background/picture_filename", '"%s"' %file_loc]
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
118 subprocess.Popen(args)
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
119 ## KDE4 is difficult
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
120 ## see http://blog.zx2c4.com/699 for a solution that might work
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
121 elif desktop_env in ["kde3", "trinity"]:
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
122 # From http://ubuntuforums.org/archive/index.php/t-803417.html
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
123 args = 'dcop kdesktop KBackgroundIface setWallpaper 0 "%s" 6' % file_loc
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
124 subprocess.Popen(args,shell=True)
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
125
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
126 elif desktop_env=="xfce4":
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
127 #From http://www.commandlinefu.com/commands/view/2055/change-wallpaper-for-xfce4-4.6.0
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
128 if first_run:
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
129 args0 = ["xfconf-query", "-c", "xfce4-desktop", "-p", "/backdrop/screen0/monitor0/image-path", "-s", file_loc]
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
130 args1 = ["xfconf-query", "-c", "xfce4-desktop", "-p", "/backdrop/screen0/monitor0/image-style", "-s", "3"]
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
131 args2 = ["xfconf-query", "-c", "xfce4-desktop", "-p", "/backdrop/screen0/monitor0/image-show", "-s", "true"]
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
132 subprocess.Popen(args0)
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
133 subprocess.Popen(args1)
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
134 subprocess.Popen(args2)
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
135 args = ["xfdesktop","--reload"]
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
136 subprocess.Popen(args)
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
137
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
138 elif desktop_env in ["fluxbox","jwm","openbox","afterstep"]:
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
139 #http://fluxbox-wiki.org/index.php/Howto_set_the_background
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
140 # used fbsetbg on jwm too since I am too lazy to edit the XML configuration
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
141 # now where fbsetbg does the job excellent anyway.
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
142 # and I have not figured out how else it can be set on Openbox and AfterSTep
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
143 # but fbsetbg works excellent here too.
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
144 try:
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
145 args = ["fbsetbg", file_loc]
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
146 subprocess.Popen(args)
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
147 except:
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
148 sys.stderr.write("ERROR: Failed to set wallpaper with fbsetbg!\n")
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
149 sys.stderr.write("Please make sre that You have fbsetbg installed.\n")
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
150 elif desktop_env=="icewm":
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
151 # command found at http://urukrama.wordpress.com/2007/12/05/desktop-backgrounds-in-window-managers/
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
152 args = ["icewmbg", file_loc]
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
153 subprocess.Popen(args)
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
154 elif desktop_env=="blackbox":
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
155 # command found at http://blackboxwm.sourceforge.net/BlackboxDocumentation/BlackboxBackground
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
156 args = ["bsetbg", "-full", file_loc]
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
157 subprocess.Popen(args)
32
40f51ad1e9ba bing4desktop-0.240208-2
prymula <prymula76@outlook.com>
parents: 31
diff changeset
158 elif desktop_env in ['xqt', 'Lubuntu']:
40f51ad1e9ba bing4desktop-0.240208-2
prymula <prymula76@outlook.com>
parents: 31
diff changeset
159 #args = "pcmanfm --set-wallpaper %s --wallpaper-mode=scaled" % file_loc
40f51ad1e9ba bing4desktop-0.240208-2
prymula <prymula76@outlook.com>
parents: 31
diff changeset
160 args = "pcmanfm-qt --set-wallpaper=" + file_loc + " --wallpaper-mode=fit"
40f51ad1e9ba bing4desktop-0.240208-2
prymula <prymula76@outlook.com>
parents: 31
diff changeset
161 print ("ALOCHA: "+args)
10
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
162 subprocess.Popen(args,shell=True)
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
163 elif desktop_env=="WindowMaker":
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
164 # From http://www.commandlinefu.com/commands/view/3857/set-wallpaper-on-windowmaker-in-one-line
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
165 args = "wmsetbg -s -u %s" % file_loc
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
166 subprocess.Popen(args,shell=True)
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
167 elif desktop_env=="windows": #Not tested since I do not run this on Windows
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
168 #From https://stackoverflow.com/questions/1977694/change-desktop-background
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
169 import ctypes
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
170 SPI_SETDESKWALLPAPER = 20
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
171 ctypes.windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, file_loc , 0)
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
172 else:
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
173 if first_run: #don't spam the user with the same message over and over again
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
174 sys.stderr.write("Warning: Failed to set wallpaper. Your desktop environment is not supported.")
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
175 sys.stderr.write("You can try manually to set Your wallpaper to %s" % file_loc)
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
176 return False
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
177 return True
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
178 except:
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
179 sys.stderr.write("ERROR: Failed to set wallpaper. There might be a bug.\n")
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
180 return False
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
181
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
182
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
183 class Gui():
17
3b8fd6a7f2d0 bing4desktop-0.240207-2
prymula <prymula76@outlook.com>
parents: 16
diff changeset
184 global TMP_COPYRIGHT, TMP_TITLE
10
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
185
34
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
186 def __init__(self, succes_set):
10
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
187 self.window = tk.Tk()
11
c01d7edb9cb9 bing4desktop-0.240206-0
prymula <prymula76@outlook.com>
parents: 10
diff changeset
188 self.image = None
c01d7edb9cb9 bing4desktop-0.240206-0
prymula <prymula76@outlook.com>
parents: 10
diff changeset
189 for ico in ['./bing.ico', '/usr/share/bing4desktop/bing.ico']:
c01d7edb9cb9 bing4desktop-0.240206-0
prymula <prymula76@outlook.com>
parents: 10
diff changeset
190 try:
c01d7edb9cb9 bing4desktop-0.240206-0
prymula <prymula76@outlook.com>
parents: 10
diff changeset
191 self.image = Image.open(ico)
13
73fd89b46da4 bing4desktop-0.240206-3
prymula <prymula76@outlook.com>
parents: 11
diff changeset
192 except:
73fd89b46da4 bing4desktop-0.240206-3
prymula <prymula76@outlook.com>
parents: 11
diff changeset
193 print ('W bieżącym katalogu, brak ikony ' + ico)
11
c01d7edb9cb9 bing4desktop-0.240206-0
prymula <prymula76@outlook.com>
parents: 10
diff changeset
194 finally:
13
73fd89b46da4 bing4desktop-0.240206-3
prymula <prymula76@outlook.com>
parents: 11
diff changeset
195 if self.image != None:
73fd89b46da4 bing4desktop-0.240206-3
prymula <prymula76@outlook.com>
parents: 11
diff changeset
196 break
11
c01d7edb9cb9 bing4desktop-0.240206-0
prymula <prymula76@outlook.com>
parents: 10
diff changeset
197
c01d7edb9cb9 bing4desktop-0.240206-0
prymula <prymula76@outlook.com>
parents: 10
diff changeset
198 self.tmp = None
10
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
199 self.menu = (
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
200 item("Ustaw Tapetę", lambda icon, item: wp.set(full_path, True)),
19
e7a6488c02b7 bing4desktop-0.240207-3
prymula <prymula76@outlook.com>
parents: 17
diff changeset
201 item('Tapeta poprzednia', lambda icon, item: self.change_pic(1, icon)),
e7a6488c02b7 bing4desktop-0.240207-3
prymula <prymula76@outlook.com>
parents: 17
diff changeset
202 item('Tapeta następna', lambda icon, item: self.change_pic(-1, icon)),
17
3b8fd6a7f2d0 bing4desktop-0.240207-2
prymula <prymula76@outlook.com>
parents: 16
diff changeset
203 item('Opis zdjęcia', lambda icon, item: icon.notify(TMP_TITLE + ' --- ' + TMP_COPYRIGHT)),
10
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
204 item('O Programie', lambda icon, item: self.about()),
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
205 item('Wyjdź', self.quit_window)
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
206 )
34
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
207
10
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
208 self.frame = tk.Frame(self.window, width=600, height=400)
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
209 self.frame.pack()
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
210 self.frame.place(anchor='center', relx=0.5, rely=5)
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
211
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
212 #self.window.title("Bing4Desktop")
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
213 #self.window.geometry('800x600')
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
214 #self.window.protocol('WM_DELETE_WINDOW', self.withdraw_window)
34
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
215
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
216
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
217 #self.withdraw_window()
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
218 #self.window.withdraw()
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
219 self.window.withdraw()
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
220 self.icon = pystray.Icon("name", self.image, "Bing4Desktop", self.menu)
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
221 print ("SUCCES: ", succes_set)
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
222
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
223 # FIXME - Nie działą notyfikacja tylko dialog boc
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
224 if succes_set == False:
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
225 #self.icon.notify("", "Nie udało połączyć się z serwerem")
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
226 self.net_info()
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
227
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
228 self.icon.run()
10
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
229 self.window.mainloop()
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
230
34
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
231 def net_info(self):
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
232 messagebox.showinfo("Bing4Desktop","Nieudało się połączyć z serwerem !")
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
233 # możliwe że nieprawidlowe po wyjściu z aplikacji zwróci bląd :(
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
234 self.window.destroy()
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
235 self.window.update()
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
236
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
237
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
238
10
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
239 def about(self):
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
240 global ver
15
18816a0c1fc2 bing4desktop-0.240206-4
prymula <prymula76@outlook.com>
parents: 13
diff changeset
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)
13
73fd89b46da4 bing4desktop-0.240206-3
prymula <prymula76@outlook.com>
parents: 11
diff changeset
242 # możliwe że nieprawidlowe po wyjściu z aplikacji zwróci bląd :(
10
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
243 self.window.destroy()
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
244 self.window.update()
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
245
19
e7a6488c02b7 bing4desktop-0.240207-3
prymula <prymula76@outlook.com>
parents: 17
diff changeset
246 def change_pic(self, n, icon):
e7a6488c02b7 bing4desktop-0.240207-3
prymula <prymula76@outlook.com>
parents: 17
diff changeset
247 global actualImage, BING_WALLPAPER_PATH, TITLE, COPYRIGHT_TXT
10
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
248 BASE = "/HPImageArchive.aspx?format=js&idx="
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
249 OFF = "&n=1&mkt=en-US"
17
3b8fd6a7f2d0 bing4desktop-0.240207-2
prymula <prymula76@outlook.com>
parents: 16
diff changeset
250
10
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
251 actualImage = actualImage + n;
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
252 if (actualImage < 0):
17
3b8fd6a7f2d0 bing4desktop-0.240207-2
prymula <prymula76@outlook.com>
parents: 16
diff changeset
253 actualImage = 7
3b8fd6a7f2d0 bing4desktop-0.240207-2
prymula <prymula76@outlook.com>
parents: 16
diff changeset
254 elif (actualImage > 7):
10
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
255 actualImage = 0
34
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
256
10
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
257 wp=WPaper()
34
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
258 try:
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
259 wp.get()
10
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
260 BING_WALLPAPER_PATH = BASE+str(actualImage)+OFF
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
261 if wp.get() == False:
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
262 cleanup()
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
263 exit
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
264
11
c01d7edb9cb9 bing4desktop-0.240206-0
prymula <prymula76@outlook.com>
parents: 10
diff changeset
265 # Wszystko pięknie tylko metoda 'show', zmienia nazwę pliku przechowywanego w TMP
32
40f51ad1e9ba bing4desktop-0.240208-2
prymula <prymula76@outlook.com>
parents: 31
diff changeset
266 ## Pozatym nie ubija a nie znalazłem nic lepszego
40f51ad1e9ba bing4desktop-0.240208-2
prymula <prymula76@outlook.com>
parents: 31
diff changeset
267 #print ("GLOB: ", glob.glob( os.path.join('/tmp', '*.PNG')))
40f51ad1e9ba bing4desktop-0.240208-2
prymula <prymula76@outlook.com>
parents: 31
diff changeset
268 #for infile in glob.glob( os.path.join('/tmp', '*.PNG')):
40f51ad1e9ba bing4desktop-0.240208-2
prymula <prymula76@outlook.com>
parents: 31
diff changeset
269 # print ("INFILE: ", infile)
40f51ad1e9ba bing4desktop-0.240208-2
prymula <prymula76@outlook.com>
parents: 31
diff changeset
270 # viewer = subprocess.Popen(['/usr/bin/eom', infile])
40f51ad1e9ba bing4desktop-0.240208-2
prymula <prymula76@outlook.com>
parents: 31
diff changeset
271 # viewer.terminate()
40f51ad1e9ba bing4desktop-0.240208-2
prymula <prymula76@outlook.com>
parents: 31
diff changeset
272 # viewer.kill() # make sure the viewer is gone; not needed on Windows
11
c01d7edb9cb9 bing4desktop-0.240206-0
prymula <prymula76@outlook.com>
parents: 10
diff changeset
273
10
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
274 img = Image.open(full_path) #.convert('RGBA') # PIL solution
11
c01d7edb9cb9 bing4desktop-0.240206-0
prymula <prymula76@outlook.com>
parents: 10
diff changeset
275 self.tmp = img.resize((600, 400), None, None, 3.0)
c01d7edb9cb9 bing4desktop-0.240206-0
prymula <prymula76@outlook.com>
parents: 10
diff changeset
276 self.tmp.show()
19
e7a6488c02b7 bing4desktop-0.240207-3
prymula <prymula76@outlook.com>
parents: 17
diff changeset
277 icon.notify(TITLE + ' --- ' + COPYRIGHT_TXT)
34
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
278 except:
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
279 print ("Serewr niedostępny")
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
280
10
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
281 def quit_window(self):
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
282 self.icon.stop()
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
283 self.window.destroy()
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
284
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
285 def show_window(self):
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
286 self.icon.stop()
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
287 self.window.protocol('WM_DELETE_WINDOW', self.withdraw_window)
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
288 self.window.after(0, self.window.deiconify)
34
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
289 """
10
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
290 def withdraw_window(self):
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
291 self.window.withdraw()
34
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
292 self.icon = pystray.Icon("name", self.image, "Bing4Desktop", self.menu)
10
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
293 self.icon.run()
34
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
294 """
10
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
295 def cleanup():
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
296 # NIEBEZPIECZNA ! lepiej niczym innym nie nadpisywać tych zmiennych
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
297 shutil.rmtree(tmp_path)
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
298
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
299 if __name__ in '__main__':
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
300 wp=WPaper()
34
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
301 w = False
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
302 try:
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
303 w = wp.get()
10
ed9556d0c5d7 bing4desktop-0.240205-4
prymula <prymula76@outlook.com>
parents:
diff changeset
304 wp.set(full_path, True)
34
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
305 except:
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
306 print ("Serewr niedostępny")
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
307 #if w:
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
308
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
309 g = Gui(w)
9bcb32b7526a bing4desktop-0.240209-0
prymula <prymula76@outlook.com>
parents: 33
diff changeset
310 cleanup()