1
-
2
-
3
-
4
-
5
- import pystray , PIL .Image , PIL .ImageTk
6
-
7
1
import json
8
2
import tkinter as tk
9
3
from tkinter import filedialog
10
- from notifypy import Notify
11
-
12
- import os
13
- import shutil
14
- import mimetypes
15
-
16
4
5
+ import PIL .Image
6
+ import PIL .ImageTk
7
+ import pystray
8
+ from notifypy import Notify
17
9
18
10
image = PIL .Image .open ("ico.png" )
19
11
20
12
enable_notifications = True
21
13
22
14
destination = ""
23
15
16
+
24
17
def create_settings ():
25
18
root = tk .Tk ()
26
19
root .withdraw ()
@@ -41,10 +34,12 @@ def create_settings():
41
34
json .dump (settings , settings_file )
42
35
43
36
37
+ import os
38
+ import shutil
39
+ import mimetypes
44
40
45
41
46
42
def sort_files (directory ):
47
-
48
43
folders = {
49
44
"Images" : os .path .join (directory , "Images" ),
50
45
"Audio" : os .path .join (directory , "Audio" ),
@@ -55,7 +50,6 @@ def sort_files(directory):
55
50
"Other" : os .path .join (directory , "Other" )
56
51
}
57
52
58
-
59
53
for folder in folders .values ():
60
54
os .makedirs (folder , exist_ok = True )
61
55
@@ -64,11 +58,9 @@ def sort_files(directory):
64
58
for filename in os .listdir (directory ):
65
59
file_path = os .path .join (directory , filename )
66
60
67
-
68
61
if os .path .isdir (file_path ):
69
62
continue
70
63
71
-
72
64
if filename .lower ().endswith ('.exe' ):
73
65
target_folder = folders ["Other" ]
74
66
else :
@@ -93,7 +85,6 @@ def sort_files(directory):
93
85
else :
94
86
target_folder = folders ["Other" ]
95
87
96
-
97
88
shutil .move (file_path , os .path .join (target_folder , filename ))
98
89
print (f"Перемещен: { filename } в { target_folder } " )
99
90
moved_files_count += 1
@@ -104,7 +95,6 @@ def sort_files(directory):
104
95
105
96
106
97
def sort (icon , item ):
107
-
108
98
if enable_notifications :
109
99
notification = Notify ()
110
100
notification .application_name = "Sorty!"
@@ -120,8 +110,7 @@ def sort(icon, item):
120
110
print ("sorted!" )
121
111
122
112
123
- def exit_action (icon :pystray .Icon ):
124
-
113
+ def exit_action (icon : pystray .Icon ):
125
114
icon .stop ()
126
115
exit (0 )
127
116
@@ -132,20 +121,19 @@ def change_settings():
132
121
with open ("settings.sorty" , "r" ) as settings_file :
133
122
settings = json .load (settings_file )
134
123
135
-
136
124
enable_notifications = settings .get ("notificationsenabled" , enable_notifications )
137
125
destination = settings .get ("download_folder" , destination )
138
126
139
127
print (destination )
140
128
print (enable_notifications )
141
129
142
- icon = pystray .Icon ("Sorty" , image , menu = pystray .Menu (
130
+
131
+ icon = pystray .Icon ("Sorty" , image , menu = pystray .Menu (
143
132
pystray .MenuItem ("Sort!" , sort ),
144
133
pystray .MenuItem ("Сhange Directory" , change_settings ),
145
- pystray .MenuItem ("Exit" , lambda : exit_action (icon ))
134
+ pystray .MenuItem ("Exit" , lambda : exit_action (icon ))
146
135
))
147
136
148
-
149
137
if os .path .exists ("settings.sorty" ):
150
138
with open ("settings.sorty" , "r" ) as settings_file :
151
139
settings = json .load (settings_file )
@@ -161,4 +149,3 @@ def change_settings():
161
149
print (enable_notifications )
162
150
163
151
icon .run ()
164
-
0 commit comments