forked from Spinmob/spinmob
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_dialogs.py
More file actions
89 lines (61 loc) · 3.06 KB
/
_dialogs.py
File metadata and controls
89 lines (61 loc) · 3.06 KB
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
import PyQt4.QtGui as _qt
import os as _os
if __name__=='__main__':
import spinmob as _s
_settings = _s.settings
def save(filters='*.*', text='Save THIS, facehead!', default_directory='default_directory'):
"""
Pops up a save dialog and returns the string path of the selected file.
"""
# make sure the filters contains "*.*" as an option!
if filters.find('*.*') < 0: filters = filters + ";;All files (*.*)"
# if this type of pref doesn't exist, we need to make a new one
if _settings.has_key(default_directory): default = _settings[default_directory]
else: default = ""
# pop up the dialog
result = str(_qt.QFileDialog.getSaveFileName(None,text,default,filters))
if result == '': return None
else:
_settings[default_directory] = _os.path.split(result)[0]
return result
def open_single(filters="*.*", text='Select a file, FACEFACE!', default_directory='default_directory'):
"""
Pops up a dialog for opening a single file. Returns a string path or None.
"""
# make sure the filters contains "*.*" as an option!
if filters.find('*.*') < 0: filters = filters + ";;All files (*.*)"
# if this type of pref doesn't exist, we need to make a new one
if _settings.has_key(default_directory): default = _settings[default_directory]
else: default = ""
# pop up the dialog
result = str(_qt.QFileDialog.getOpenFileName(None,text,default,filters))
if result == '': return None
else:
_settings[default_directory] = _os.path.split(result)[0]
return result
def open_multiple(filters="*.*", text='Select some files, FACEFACE!', default_directory='default_directory'):
"""
Pops up a dialog for opening more than one file. Returns a list of string paths or None.
"""
# make sure the filters contains "*.*" as an option!
if filters.find('*.*') < 0: filters = filters + ";;All files (*.*)"
# if this type of pref doesn't exist, we need to make a new one
if _settings.has_key(default_directory): default = _settings[default_directory]
else: default = ""
# pop up the dialog
result = list(_qt.QFileDialog.getOpenFileNames(None,text,default,filters))
for n in range(len(result)): result[n] = str(result[n])
if len(result)==0: return
else:
_settings[default_directory] = _os.path.split(result[0])[0]
return result
def select_directory(text='Select a directory, POCKETPANTS!', default_directory='default_directory'):
# if this type of pref doesn't exist, we need to make a new one
if _settings.has_key(default_directory): default = _settings[default_directory]
else: default = ""
# pop up the dialog
result = str(_qt.QFileDialog.getExistingDirectory(None,text,default))
if result == '': return None
else:
_settings[default_directory] = _os.path.split(result)[0]
return result