1
|
|
|
import PySimpleGUI as gui |
2
|
|
|
|
3
|
|
|
from dirutility import desktop |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
def _line(char='_', width=100, size=(70, 1)): |
7
|
|
|
return gui.Text(char * width, size=size) |
8
|
|
|
|
9
|
|
|
|
10
|
|
View Code Duplication |
class WalkGUI: |
|
|
|
|
11
|
|
|
|
12
|
|
|
def __init__(self): |
13
|
|
|
"""GUI window for inputing DirPaths parameters""" |
14
|
|
|
self.title = 'DirPaths' |
15
|
|
|
self.params = {} |
16
|
|
|
|
17
|
|
|
def __iter__(self): |
18
|
|
|
return iter(self.params) |
19
|
|
|
|
20
|
|
|
def __str__(self): |
21
|
|
|
return str(self.params) |
22
|
|
|
|
23
|
|
|
def _saving(self): |
24
|
|
|
"""Parameters for saving results to file""" |
25
|
|
|
with gui.FlexForm(self.title, auto_size_text=True, default_element_size=(40, 1)) as form: |
26
|
|
|
layout = [ |
27
|
|
|
[gui.Text('Results Saving Settings', size=(30, 1), font=("Helvetica", 25), text_color='blue')], |
28
|
|
|
# Source |
29
|
|
|
[ |
30
|
|
|
gui.Text('Destination Folder', size=(15, 1), auto_size_text=False), |
31
|
|
|
gui.InputText(desktop()), |
32
|
|
|
gui.FolderBrowse() |
33
|
|
|
], |
34
|
|
|
|
35
|
|
|
# File types |
36
|
|
|
[gui.Text('Select file types you would like to save output to.')], |
37
|
|
|
[gui.Checkbox('CSV', default=True), gui.Checkbox('JSON')], |
38
|
|
|
[_line()], |
39
|
|
|
|
40
|
|
|
# Save results to file |
41
|
|
|
[gui.Submit(), gui.Cancel()] |
42
|
|
|
] |
43
|
|
|
|
44
|
|
|
(button, (values)) = form.LayoutAndShow(layout) |
45
|
|
|
|
46
|
|
|
# gui.MsgBox(self.title, 'Parameters set', 'The results of the form are... ', |
47
|
|
|
# 'The button clicked was "{}"'.format(button), 'The values are', values, auto_close=True) |
48
|
|
|
|
49
|
|
|
self.params['save'] = { |
50
|
|
|
'directory': values[0], |
51
|
|
|
'csv': values[1], |
52
|
|
|
'json': values[2], |
53
|
|
|
} |
54
|
|
|
return self.params |
55
|
|
|
|
56
|
|
|
def parsing(self): |
57
|
|
|
"""Parameters for parsing directory trees""" |
58
|
|
|
with gui.FlexForm(self.title, auto_size_text=True, default_element_size=(40, 1)) as form: |
59
|
|
|
layout = [ |
60
|
|
|
[gui.Text('Directory Paths utility', size=(30, 1), font=("Helvetica", 25), text_color='blue')], |
61
|
|
|
# Source |
62
|
|
|
[ |
63
|
|
|
gui.Text('Source Folder', size=(15, 1), auto_size_text=False), |
64
|
|
|
gui.InputText('Source'), |
65
|
|
|
gui.FolderBrowse() |
66
|
|
|
], |
67
|
|
|
|
68
|
|
|
# Parallel / Sequential |
69
|
|
|
[ |
70
|
|
|
gui.Text('Parallel or Sequential Processing. Larger directory trees are typically parsed faster ' |
71
|
|
|
'using parallel processing.') |
72
|
|
|
], |
73
|
|
|
[ |
74
|
|
|
gui.Radio('Parallel Processing', "RADIO1"), |
75
|
|
|
gui.Radio('Sequential Processing', "RADIO1", default=True) |
76
|
|
|
], |
77
|
|
|
[_line()], |
78
|
|
|
|
79
|
|
|
# Files and non-empty-folders |
80
|
|
|
[gui.Text('Return files or folders, returning folders is useful for creating inventories.')], |
81
|
|
|
[ |
82
|
|
|
gui.Radio('Return Files', "RADIO2", default=True), |
83
|
|
|
gui.Radio('Return Non-Empty Directories', "RADIO2") |
84
|
|
|
], |
85
|
|
|
[_line()], |
86
|
|
|
|
87
|
|
|
# max_level |
88
|
|
|
[gui.Text('Max Depth.... Max number of sub directory depths to traverse (starting directory is 0)')], |
89
|
|
|
[gui.InputCombo(list(reversed(range(0, 13))), size=(20, 3))], |
90
|
|
|
[_line()], |
91
|
|
|
|
92
|
|
|
# Relative and absolute |
93
|
|
|
[ |
94
|
|
|
gui.Text( |
95
|
|
|
'Relative or Absolute Paths. Relative paths are saved relative to the starting directory. ' |
96
|
|
|
'Absolute paths are saved as full paths.') |
97
|
|
|
], |
98
|
|
|
[gui.Radio('Relative Paths', "RADIO3", default=True), |
99
|
|
|
gui.Radio('Absolute Paths', "RADIO3")], |
100
|
|
|
[_line()], |
101
|
|
|
|
102
|
|
|
# Topdown and output |
103
|
|
|
[gui.Checkbox('Topdown Parse', default=True), |
104
|
|
|
gui.Checkbox('Live output results')], |
105
|
|
|
[_line()], |
106
|
|
|
|
107
|
|
|
# Save results to file |
108
|
|
|
[gui.Checkbox('Save Results to File', default=False)], |
109
|
|
|
[gui.Submit(), gui.Cancel()] |
110
|
|
|
] |
111
|
|
|
|
112
|
|
|
(button, (values)) = form.LayoutAndShow(layout) |
113
|
|
|
|
114
|
|
|
# gui.MsgBox(self.title, 'Parameters set', 'The results of the form are... ', |
115
|
|
|
# 'The button clicked was "{}"'.format(button), 'The values are', values, auto_close=True) |
116
|
|
|
|
117
|
|
|
self.params['parse'] = { |
118
|
|
|
'directory': values[0], |
119
|
|
|
'parallelize': values[1], |
120
|
|
|
'sequential': values[2], |
121
|
|
|
'yield_files': values[3], |
122
|
|
|
'non_empty_folders': values[4], |
123
|
|
|
'max_level': int(values[5]), |
124
|
|
|
'_relative': values[6], |
125
|
|
|
'full_paths': values[7], |
126
|
|
|
'topdown': values[8], |
127
|
|
|
'console_stream': values[9], |
128
|
|
|
'save_file': values[10], |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
if self.params['parse']['save_file']: |
132
|
|
|
self._saving() |
133
|
|
|
|
134
|
|
|
return self.params |
135
|
|
|
|
136
|
|
|
|
137
|
|
View Code Duplication |
class BackupZipGUI: |
|
|
|
|
138
|
|
|
|
139
|
|
|
def __init__(self): |
140
|
|
|
"""GUI window for saving zip backups""" |
141
|
|
|
self.title = 'ZipBackup' |
142
|
|
|
|
143
|
|
|
@property |
144
|
|
|
def source(self): |
145
|
|
|
"""Parameters for saving zip backups""" |
146
|
|
|
with gui.FlexForm(self.title, auto_size_text=True, default_element_size=(40, 1)) as form: |
147
|
|
|
layout = [ |
148
|
|
|
[gui.Text('Zip Backup utility', size=(30, 1), font=("Helvetica", 30), text_color='blue')], |
149
|
|
|
[ |
150
|
|
|
gui.Text('Create a zip backup of a file or directory.', |
151
|
|
|
size=(50, 1), |
152
|
|
|
font=("Helvetica", 18), |
153
|
|
|
text_color='black') |
154
|
|
|
], |
155
|
|
|
[gui.Text('-' * 200)], |
156
|
|
|
|
157
|
|
|
# Source |
158
|
|
|
[ |
159
|
|
|
gui.Text('Select source folder', size=(20, 1), font=("Helvetica", 25), auto_size_text=False), |
160
|
|
|
gui.InputText('', key='source', font=("Helvetica", 20)), |
161
|
|
|
gui.FolderBrowse() |
162
|
|
|
], |
163
|
|
|
[gui.Submit(), gui.Cancel()] |
164
|
|
|
] |
165
|
|
|
|
166
|
|
|
button, values = form.LayoutAndRead(layout) |
167
|
|
|
if button == 'Submit': |
168
|
|
|
return values['source'] |
169
|
|
|
else: |
170
|
|
|
exit() |
171
|
|
|
|
172
|
|
|
|
173
|
|
View Code Duplication |
class CompareTreesGUI: |
|
|
|
|
174
|
|
|
|
175
|
|
|
def __init__(self): |
176
|
|
|
self.title = 'CompareTrees' |
177
|
|
|
self.params = {} |
178
|
|
|
|
179
|
|
|
def _saving(self): |
180
|
|
|
with gui.FlexForm(self.title, auto_size_text=True, default_element_size=(40, 1)) as form: |
181
|
|
|
layout = [ |
182
|
|
|
[gui.Text('Results Saving Settings', size=(30, 1), font=("Helvetica", 25), text_color='blue')], |
183
|
|
|
# Source |
184
|
|
|
[ |
185
|
|
|
gui.Text('Destination Folder', size=(15, 1), auto_size_text=False), |
186
|
|
|
gui.InputText(desktop()), |
187
|
|
|
gui.FolderBrowse() |
188
|
|
|
], |
189
|
|
|
|
190
|
|
|
# File types |
191
|
|
|
[gui.Text('Select file types you would like to save output to.')], |
192
|
|
|
[gui.Checkbox('CSV', default=True), gui.Checkbox('JSON')], |
193
|
|
|
[_line()], |
194
|
|
|
|
195
|
|
|
# Save results to file |
196
|
|
|
[gui.Submit(), gui.Cancel()] |
197
|
|
|
] |
198
|
|
|
|
199
|
|
|
(button, (values)) = form.LayoutAndShow(layout) |
200
|
|
|
|
201
|
|
|
self.params['save'] = { |
202
|
|
|
'directory': values[0], |
203
|
|
|
'csv': values[1], |
204
|
|
|
'json': values[2], |
205
|
|
|
} |
206
|
|
|
return self.params |
207
|
|
|
|
208
|
|
|
@property |
209
|
|
|
def sources(self): |
210
|
|
|
with gui.FlexForm(self.title, auto_size_text=True, default_element_size=(40, 1)) as form: |
211
|
|
|
layout = [ |
212
|
|
|
[gui.Text('Compare Trees utility', size=(30, 1), font=("Helvetica", 25), text_color='blue')], |
213
|
|
|
|
214
|
|
|
# Source 1 |
215
|
|
|
[ |
216
|
|
|
gui.Text('Select source #1 folder', size=(15, 1), auto_size_text=False), |
217
|
|
|
gui.InputText('Source'), |
218
|
|
|
gui.FolderBrowse() |
219
|
|
|
], |
220
|
|
|
|
221
|
|
|
# Source 2 |
222
|
|
|
[ |
223
|
|
|
gui.Text('Select source #2 folder', size=(15, 1), auto_size_text=False), |
224
|
|
|
gui.InputText('Source'), |
225
|
|
|
gui.FolderBrowse() |
226
|
|
|
], |
227
|
|
|
|
228
|
|
|
# Save results to file |
229
|
|
|
[gui.Checkbox('Save Results to File', default=False)], |
230
|
|
|
[gui.Submit(), gui.Cancel()] |
231
|
|
|
] |
232
|
|
|
|
233
|
|
|
(button, (values)) = form.LayoutAndShow(layout) |
234
|
|
|
|
235
|
|
|
print(values) |
236
|
|
|
self.params['source'] = { |
237
|
|
|
'dir1': values[0], |
238
|
|
|
'dir2': values[1], |
239
|
|
|
'save_file': values[2], |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
if self.params['source']['save_file']: |
243
|
|
|
self._saving() |
244
|
|
|
return self.params |
245
|
|
|
|