-
Notifications
You must be signed in to change notification settings - Fork 1
/
SettingsDialog.py
488 lines (414 loc) · 19.9 KB
/
SettingsDialog.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
"""
Dialog for configuring FileExtractor and its modules
The GUI is wxDigit / wxPython based.
@see: http://wxpython.org for details on wxPython
Changes here are written through to the L{FESettings} module. After hitting the OK button,
the save function in there will be invoked as well to make the settings persistent.
FileExtractor is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
FileExtractor is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FileExtractor. If not, see <http://www.gnu.org/licenses/>.
"""
from wxPython.wx import *
import wx
import os
import os.path
import tools
import FileExtractor
import FESettings
from FESettings import getSettings
import imagegenerator
import FileExtractorCore
import signatures
DIR_CURRENT_ST = 'Working directory'
class SettingsDialog(wxDialog):
"""
Holding all the information about the dialog.
"""
def __init__(self, parent, ID, title):
"""
Initialises all controls and registers the event listeners.
"""
wxDialog.__init__(self, parent, ID, title, size=(600,400))
outerBox = wx.BoxSizer(wx.VERTICAL)
panel = wx.Panel(self, -1)
hbox = wx.BoxSizer(wx.HORIZONTAL)
vbox = wx.BoxSizer(wx.VERTICAL)
panel1 = wx.Panel(panel, -1)
panel_content = wx.Panel(panel, -1)
font_headings = wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.BOLD)
panel_top = wx.Panel(self, -1)
label = wxStaticText (panel_top, -1 , "Configure FileExtractor", style = wx.ALIGN_CENTRE )
label.SetFont(font_headings)
panel_fill1 = wx.Panel(panel_top, -1)
panel_fill2 = wx.Panel(panel_top, -1)
topBox = wx.BoxSizer(wx.HORIZONTAL)
topBox.Add(panel_fill1, 4, wx.ALIGN_CENTER | wx.ALIGN_CENTER_HORIZONTAL)
topBox.Add(label, 5, wx.ALIGN_CENTER)
topBox.Add(panel_fill2, 4, wx.ALIGN_CENTER | wx.ALIGN_CENTER_HORIZONTAL)
panel_top.SetSizer(topBox)
self.tree = wx.TreeCtrl(panel1, 1, wx.DefaultPosition, (-1,-1), wx.TR_HIDE_ROOT|wx.TR_HAS_BUTTONS | wxDOUBLE_BORDER)
root = self.tree.AddRoot('Settings')
fe = self.tree.AppendItem(root, 'FileExtractor')
mod = self.tree.AppendItem(root, 'Modules')
self.tree.Expand(fe)
self.tree.AppendItem(fe, 'General')
self.tree.AppendItem(fe, 'FileTypes')
self.tree.AppendItem(fe, 'Output Files')
self.tree.AppendItem(mod, 'ImageGenerator')
vbox.Add(self.tree, 1, wx.EXPAND)
panel1.SetSizer(vbox)
panel_fill_h1 = wx.Panel(panel, -1)
## panel_fill_h1.SetBackgroundColour(wx.RED)
panel_fill_h2 = wx.Panel(panel, -1)
## panel_fill_h2.SetBackgroundColour(wx.RED)
panel_fill_h3 = wx.Panel(panel, -1)
## panel_fill_h3.SetBackgroundColour(wx.RED)
hbox.Add(panel_fill_h1, 1, wx.EXPAND)
hbox.Add(panel1, 5, wx.EXPAND)
hbox.Add(panel_fill_h2, 1, wx.EXPAND)
hbox.Add(panel_content, 10, wx.EXPAND)
hbox.Add(panel_fill_h3, 1, wx.EXPAND)
panel.SetSizer(hbox)
panel_buttons = wx.Panel(self, -1)
panel_fill = wx.Panel(panel_buttons, -1)
## panel_fill.SetBackgroundColour(wx.RED)
bmApply = wx.Bitmap(os.path.join(FESettings.PATH_ICONS, "apply.png"), wx.BITMAP_TYPE_PNG);
b1 = wx.BitmapButton(panel_buttons, 601, bmApply, size=(30,25))
bmCancel = wx.Bitmap(os.path.join(FESettings.PATH_ICONS, "cancel.png"), wx.BITMAP_TYPE_PNG);
b2 = wx.BitmapButton(panel_buttons, 602, bmCancel, size=(30,25))
panel_fill1 = wx.Panel(panel_buttons, -1)
## panel_fill1.SetBackgroundColour(wx.RED)
box = wx.BoxSizer(wxHORIZONTAL)
box.Add(panel_fill, 8, wxEXPAND)
## panel_fill.SetBackgroundColour(wx.RED)
box.Add(b2, 2, wxALIGN_CENTER )
box.Add(b1, 2, wxALIGN_CENTER )
box.Add(panel_fill1, 1, wxEXPAND)
panel_buttons.SetAutoLayout(True)
panel_buttons.SetSizer(box)
panel_buttons.Layout()
#
# Content area
#
self._lastChild = None
self._topName = None
self._imageGenerator = None
self._general = None
self._fileTypes = None
self.content_swap_box = wx.BoxSizer(wxVERTICAL)
self.contentHeading = wx.TextCtrl(panel_content, -1, "Please choose an option from the tree", style = wxTE_MULTILINE | wxTE_READONLY | wxNO_BORDER )
panel_fill = wx.Panel(panel_content, -1)
## panel_fill.SetBackgroundColour(wx.RED)
self.panel_swap = wx.Panel(panel_content, -1)
self.panel_swap.SetSizer(self.content_swap_box)
contentBox = wx.BoxSizer(wxVERTICAL)
contentBox.Add(self.contentHeading, 2, wxALIGN_CENTER | wxEXPAND)
contentBox.Add(panel_fill, 1, wxEXPAND)
contentBox.Add(self.panel_swap, 8, wxEXPAND)
panel_content.SetAutoLayout(True)
panel_content.SetSizer(contentBox)
panel_content.Layout()
panel_fill0 = wx.Panel(self, -1)
## panel_fill0.SetBackgroundColour(wx.RED)
panel_fill1 = wx.Panel(self, -1)
## panel_fill1.SetBackgroundColour(wx.RED)
panel_fill2 = wx.Panel(self, -1)
## panel_fill2.SetBackgroundColour(wx.RED)
panel_fill3 = wx.Panel(self, -1)
## panel_fill3.SetBackgroundColour(wx.RED)
outerBox.Add(panel_fill0, 1, wx.EXPAND)
outerBox.Add(panel_top, 2, wx.EXPAND )
outerBox.Add(panel_fill1, 1, wx.EXPAND)
outerBox.Add(panel, 15, wx.EXPAND)
outerBox.Add(panel_fill2, 1, wx.EXPAND)
outerBox.Add(panel_buttons, 2, wx.EXPAND)
outerBox.Add(panel_fill3, 1, wx.EXPAND)
self.SetSizer(outerBox)
self.Centre()
self.CentreOnParent()
st = wx.StaticText(self.panel_swap, -1, "Content:\n* FileExtractor\n - General\n - File Types\n - Naming of output files\n* Modules\n - ImageGenerator")
self.content_swap_box.Add(st, 1, wx.ALIGN_TOP, wx.ALIGN_CENTER_HORIZONTAL)
self._lastChild = st
EVT_BUTTON(self, 602, self._OnExit)
EVT_BUTTON(self, 601, self._OnApply)
wx.EVT_TREE_SEL_CHANGED(self.tree, 1, self._OnSelChanged)
def _OnApply(self, event):
try:
val = self.if_dir.GetValue()
if val != DIR_CURRENT_ST:
getSettings().setValue('output_dir', val)
except AttributeError, msg:
pass
try:
val = ''
for x in range(0, self.signaturelist.GetCount()):
name = self.signaturelist.GetString(x)
if not self.signaturelist.IsChecked(x):
val += " %s |" %(name)
getSettings().setValue('signatues_off', val)
except AttributeError, msg:
pass
try:
val = self.if_dir_img.GetValue()
if val != DIR_CURRENT_ST:
getSettings().setValue('ig_output_dir', val)
except AttributeError, msg:
pass
try:
val = self._chCore.GetStringSelection()
getSettings().setValue('ig_default_core', val)
getSettings().setValue('ig_location_dd', tools.determineDDPathFromCoreName(val))
except AttributeError, msg:
pass
try:
val = self.spinDigits.GetValue()
getSettings().setValue('naming_digits', val)
except AttributeError, msg:
pass
try:
val = self.spinStart .GetValue()
getSettings().setValue('naming_start', val)
except AttributeError, msg:
pass
getSettings().save()
dlg = wxMessageDialog(self, "Your settings have been saved.",
"Save Setting Confirmation", wxOK | wxICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
self.EndModal(0)
self.Destroy()
def _OnSelChanged(self, event):
## self._save()
item = event.GetItem()
## print "Selected now: ", self.tree.GetItemText(item)
if self._lastChild:
self.content_swap_box.Remove(self._lastChild)
self._lastChild.Show(0)
if self.tree.GetItemText(item) == "ImageGenerator":
if FileExtractor._MODULE_IMAGE_GENERATOR:
self.contentHeading.SetValue("Apply the settings for the module 'ImageGenerator' here.")
self._putImageGeneratorOptionsContent()
else:
dlg = wx.MessageDialog(self, "The requested module was not found on this system.\n" \
" Check your installation.",
"Not installed", wxOK | wxICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
elif self.tree.GetItemText(item) == "Modules":
self.contentHeading.SetValue("Apply settings for FE modules.\nChoose a module from the tree.")
st = wx.StaticText(self.panel_swap, -1, "Available modules:\n - ImageGenerator")
self.content_swap_box.Add(st, 1, wx.ALIGN_TOP, wx.ALIGN_CENTER_HORIZONTAL)
self._lastChild = st
elif self.tree.GetItemText(item) == "FileExtractor":
self.contentHeading.SetValue("Settings for the FileExtractor.\nChoose a sub category from the tree.")
st = wx.StaticText(self.panel_swap, -1, "Available options:\n - General\n - File Types\n - Naming rules for output files")
self.content_swap_box.Add(st, 1, wx.ALIGN_TOP, wx.ALIGN_CENTER_HORIZONTAL)
self._lastChild = st
elif self.tree.GetItemText(item) == "General":
self.contentHeading.SetValue("Specify general options for the FileExtractor.")
self._putGeneralOptionsContent()
elif self.tree.GetItemText(item) == "FileTypes":
self.contentHeading.SetValue("Specify default behaviour for file types.")
self._putFiletypeOptionsContent()
elif self.tree.GetItemText(item) == "Output Files":
self.contentHeading.SetValue("Define the way your recovered files shall be named.")
self._putFilenameOptionsContent()
self.content_swap_box.Layout()
## def _save(self):
## if self._topName == 'image':
## self._imageGenerator = []
## self._imageGenerator.append()
## self._topName = None
def _putGeneralOptionsContent(self):
panel_top = wx.Panel(self.panel_swap, -1)
label_outputdir = wxStaticText (panel_top, -1, "Output Directory")
panel_dir = wxPanel(panel_top, -1)
try:
self.if_dir.Reparent(panel_dir)
except AttributeError, msg:
if getSettings().getValue('output_dir'):
self.if_dir = wxTextCtrl(panel_dir, -1, getSettings().getValue('output_dir'))
else:
self.if_dir = wxTextCtrl(panel_dir, -1, DIR_CURRENT_ST)
self.if_dir.SetEditable(false)
bmDir = wx.Bitmap(os.path.join(FESettings.PATH_ICONS, "browse.png"), wx.BITMAP_TYPE_PNG);
panel_fill = wxPanel(panel_dir, -1)
## panel_fill.SetBackgroundColour(wx.RED)
bChooseDir = wxBitmapButton(panel_dir, 701, bmDir, size=(25,25))
box = wxBoxSizer(wxHORIZONTAL)
box.Add(self.if_dir, 16, wxALIGN_CENTER)
box.Add(panel_fill, 1, wx.EXPAND)
box.Add(bChooseDir, 3, wxALIGN_CENTER)
panel_dir.SetAutoLayout(True)
panel_dir.SetSizer(box)
panel_dir.Layout()
panel_fill = wx.Panel(panel_top, -1)
## panel_fill.SetBackgroundColour(wx.RED)
topBox = wxBoxSizer(wxVERTICAL)
topBox.Add(label_outputdir, 1, wx.EXPAND)
topBox.Add(panel_dir, 1, wx.EXPAND | wx.TOP)
topBox.Add(panel_fill, 4, wx.EXPAND)
panel_top.SetAutoLayout(True)
panel_top.SetSizer(topBox)
panel_top.Layout()
self.content_swap_box.Add(panel_top, 1, wx.EXPAND)
EVT_BUTTON(self, 701, self._ChangeFEOutputDir)
self._lastChild = panel_top
def _ChangeFEOutputDir(self, event):
dirDialog = wxDirDialog(self, "Choose Output Directory")
if dirDialog.ShowModal() == wxID_OK:
path = dirDialog.GetPath()
self.dest_folder = path
self.if_dir.SetValue(path)
dirDialog.Destroy()
def _putImageGeneratorOptionsContent(self):
panel_top = wx.Panel(self.panel_swap, -1)
lCore = wx.StaticText(panel_top, -1, "Choose default core")
## choicesCore = CoreManager.getInstance().getListOfCoreNames()
choicesCore = imagegenerator.CoreManager.getInstance().getListOfCoreNames()
## choicesCore = ['Win32 dd clone', 'Linux / Unix']
try:
self._chCore.Reparent(panel_top)
except AttributeError, msg:
self._chCore = wx.Choice(panel_top, 721, choices = choicesCore)
self._chCore.SetSelection(0)
if getSettings().getValue('ig_default_core'):
for i in range(len(choicesCore)):
if choicesCore[i] == getSettings().getValue('ig_default_core'):
self._chCore.SetSelection(i)
label_outputdir = wxStaticText (panel_top, -1, "Directory for image")
panel_dir = wxPanel(panel_top, -1)
try:
self.if_dir_img.Reparent(panel_dir)
except AttributeError, msg:
if getSettings().getValue('ig_output_dir'):
self.if_dir_img = wxTextCtrl(panel_dir, -1, getSettings().getValue('ig_output_dir'))
else:
self.if_dir_img = wxTextCtrl(panel_dir, -1, DIR_CURRENT_ST)
self.if_dir_img.SetEditable(false)
bmDir = wx.Bitmap(os.path.join(FESettings.PATH_ICONS, "browse.png"), wx.BITMAP_TYPE_PNG);
panel_fill = wxPanel(panel_dir, -1)
## panel_fill.SetBackgroundColour(wx.RED)
bChooseDir = wxBitmapButton(panel_dir, 722, bmDir, size=(25,25))
box = wxBoxSizer(wxHORIZONTAL)
box.Add(self.if_dir_img, 16, wxALIGN_CENTER)
box.Add(panel_fill, 1, wx.EXPAND)
box.Add(bChooseDir, 3, wxALIGN_CENTER)
panel_dir.SetAutoLayout(True)
panel_dir.SetSizer(box)
panel_dir.Layout()
panel_fill0 = wx.Panel(panel_top, -1)
## panel_fill0.SetBackgroundColour(wx.RED)
panel_fill = wx.Panel(panel_top, -1)
## panel_fill.SetBackgroundColour(wx.RED)
topBox = wxBoxSizer(wxVERTICAL)
topBox.Add(lCore,1, wx.ALIGN_BOTTOM | wx.ALIGN_LEFT)
topBox.Add(self._chCore, 1, wx.EXPAND, wx.TOP)
topBox.Add(panel_fill0, 1, wx.EXPAND)
topBox.Add(label_outputdir, 1, wx.ALIGN_BOTTOM | wx.ALIGN_LEFT)
topBox.Add(panel_dir, 1, wx.EXPAND, wx.TOP)
topBox.Add(panel_fill, 1, wx.EXPAND)
panel_top.SetAutoLayout(True)
panel_top.SetSizer(topBox)
panel_top.Layout()
self.content_swap_box.Add(panel_top, 1, wx.EXPAND)
EVT_BUTTON(self, 722, self._ChangeIGOutputDir)
self._lastChild = panel_top
def _ChangeIGOutputDir(self, event):
dirDialog = wxDirDialog(self, "Choose Output Directory")
if dirDialog.ShowModal() == wxID_OK:
path = dirDialog.GetPath()
self.dest_folder = path
self.if_dir_img.SetValue(path)
dirDialog.Destroy()
def _putFiletypeOptionsContent(self):
panel_top = wx.Panel(self.panel_swap, -1)
label_signatures = wxStaticText (panel_top, -1 , "Select file types enabled by default")
try:
#self.signaturelist.Reparent(panel_top)
oldList = self.signaturelist
self.signaturelist = wxCheckListBox(panel_top, -1, style = wxLC_REPORT|wxSUNKEN_BORDER)
self.signaturelist.Set(self.sigcontent)
for i in range(len(self.sigcontent)):
self.signaturelist.Check(i, oldList.IsChecked(i))
except AttributeError, msg:
self.signaturelist = wxCheckListBox(panel_top, -1, style = wxLC_REPORT|wxSUNKEN_BORDER)
thesignatures = FileExtractorCore.getAvailableSignatures()
self.sigDict = {}
for sig in thesignatures:
name = sig[signatures.name]
self.sigDict[name] = sig
self.sigcontent = self.sigDict.keys()
self.signaturelist.Set(self.sigcontent)
st = getSettings().getValue('signatues_off')
d = {}
if st:
for x in st.split('|'):
d[x.strip()] = x.strip()
for i in range(0, len(self.sigcontent)):
if d.has_key(self.signaturelist.GetString(i)):
self.signaturelist.Check(i, false)
else:
self.signaturelist.Check(i)
## panel_fill = wx.Panel(panel_top, -1)
topBox = wxBoxSizer(wxVERTICAL)
topBox.Add(label_signatures,1, wx.ALIGN_BOTTOM | wx.ALIGN_LEFT)
topBox.Add(self.signaturelist, 5, wx.EXPAND, wx.TOP)
## topBox.Add(panel_fill, 1, wx.EXPAND)
panel_top.SetAutoLayout(True)
panel_top.SetSizer(topBox)
panel_top.Layout()
self.content_swap_box.Add(panel_top, 1, wx.EXPAND)
self._lastChild = panel_top
def _putFilenameOptionsContent(self):
panel_top = wx.Panel(self.panel_swap, -1)
lDigits = wxStaticText (panel_top, -1 , "Number of numeric digits in the filename")
if getSettings().getValue('naming_digits'):
initial = int(getSettings().getValue('naming_digits'))
else:
initial = 5
self.spinDigits = wx.SpinCtrl (panel_top, 801, str(initial), min = 1, max=100, initial = initial)
lStart = wxStaticText (panel_top, -1 , "Number to start with")
if getSettings().getValue('naming_start'):
start = int(getSettings().getValue('naming_start'))
else:
start = 0
self.spinStart = wx.SpinCtrl (panel_top, 802, str(start), min = 0, max=10000, initial = start)
self.nameExample = wx.TextCtrl(panel_top, -1, "Example: ", style = wx.TE_READONLY )
self.nameExample.Enable(0)
self.nameExample.SetBackgroundColour(self.GetBackgroundColour())
self._updateNameExample()
panel_fill0 = wx.Panel(panel_top, -1)
## panel_fill0.SetBackgroundColour(wx.RED)
panel_fill = wx.Panel(panel_top, -1)
## panel_fill.SetBackgroundColour(wx.RED)
topBox = wxBoxSizer(wxVERTICAL)
topBox.Add(lDigits,1, wx.ALIGN_BOTTOM | wx.ALIGN_LEFT)
topBox.Add(self.spinDigits, 1, wx.EXPAND, wx.TOP)
topBox.Add(panel_fill0, 1, wx.EXPAND)
topBox.Add(lStart, 1, wx.ALIGN_BOTTOM | wx.ALIGN_LEFT)
topBox.Add(self.spinStart, 1, wx.EXPAND, wx.TOP)
topBox.Add(panel_fill, 1, wx.EXPAND)
topBox.Add(self.nameExample, 1, wx.EXPAND)
panel_top.SetAutoLayout(True)
panel_top.SetSizer(topBox)
panel_top.Layout()
self.content_swap_box.Add(panel_top, 1, wx.EXPAND)
EVT_SPINCTRL(self, 801, self._updateNameExample)
EVT_SPINCTRL(self, 802, self._updateNameExample)
self._lastChild = panel_top
def _updateNameExample(self, event = None):
digits = int (self.spinDigits.GetValue())
first = int ( self.spinStart.GetValue())
st = "0" * (digits - len(str(first))) + str (first)
self.nameExample.SetValue("Example: JPEG_%s.jpg" %(st))
def _OnExit(self, event):
self.EndModal(0)
self.Destroy()