1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 """relax specific file and directory dialogs."""
25
26
27 from os import chdir, getcwd
28 import wx
29
30
31 from status import Status; status = Status()
32
33
34 from gui.string_conv import gui_to_str, str_to_gui
35
36
38 """relax specific replacement directory dialog for selecting directories."""
39
40 - def __init__(self, parent, field=None, message=wx.DirSelectorPromptStr, defaultPath=wx.EmptyString, style=wx.DD_DEFAULT_STYLE|wx.DD_NEW_DIR_BUTTON, pos=wx.DefaultPosition, size=wx.DefaultSize, name=wx.DirDialogNameStr):
41 """Setup the class and store the field.
42
43 @param parent: The parent wx window object.
44 @type parent: Window
45 @keyword field: The field to update with the file selection.
46 @type field: wx object or None
47 @keyword message: The path selector prompt string.
48 @type message: String
49 @keyword defaultPath: The default directory to open in.
50 @type defaultPath: String
51 @keyword style: The dialog style.
52 @type style: long
53 @keyword pos: The window position.
54 @type pos: Point
55 @keyword size: The default window size.
56 @type size: Size
57 @keyword name: The title for the dialog.
58 @type name: String
59 """
60
61
62 self.field = field
63
64
65 if defaultPath == wx.EmptyString:
66 defaultPath = getcwd()
67
68
69 super(RelaxDirDialog, self).__init__(parent, message=message, defaultPath=defaultPath, style=style, pos=pos, size=size, name=name)
70
71
73 """Return the selected path.
74
75 @return: The name of the selected path.
76 @rtype: str
77 """
78
79
80 path = gui_to_str(self.GetPath())
81
82
83 chdir(path)
84
85
86 return path
87
88
90 """The path selector GUI element.
91
92 @param event: The wx event.
93 @type event: wx event
94 """
95
96
97 if status.show_gui and self.ShowModal() != wx.ID_OK:
98 return
99
100
101 path = self.get_path()
102
103
104 self.field.SetValue(str_to_gui(path))
105
106
107 self.field.SetInsertionPoint(len(path))
108
109
110
112 """relax specific replacement file dialog for opening and closing files.
113
114 This class provides the select() method so that this class can be used with a wx event.
115 """
116
117 - def __init__(self, parent, field=None, message=wx.FileSelectorPromptStr, defaultDir=wx.EmptyString, defaultFile=wx.EmptyString, wildcard=wx.FileSelectorDefaultWildcardStr, style=wx.FD_DEFAULT_STYLE, pos=wx.DefaultPosition):
118 """Setup the class and store the field.
119
120 @param parent: The parent wx window object.
121 @type parent: Window
122 @keyword field: The field to update with the file selection.
123 @type field: wx object or None
124 @keyword message: The file selector prompt string.
125 @type message: String
126 @keyword defaultDir: The directory to open in.
127 @type defaultDir: String
128 @keyword defaultFile: The file to default selection to.
129 @type defaultFile: String
130 @keyword wildcard: The file wildcard pattern. For example for opening PDB files, this could be "PDB files (*.pdb)|*.pdb;*.PDB".
131 @type wildcard: String
132 @keyword style: The dialog style. To open a single file, set to wx.FD_OPEN. To open multiple files, set to wx.FD_OPEN|wx.FD_MULTIPLE. To save a single file, set to wx.FD_SAVE. To save multiple files, set to wx.FD_SAVE|wx.FD_MULTIPLE.
133 @type style: long
134 @keyword pos: The window position.
135 @type pos: Point
136 """
137
138
139 self.field = field
140 self.style = style
141
142
143 if defaultDir == wx.EmptyString:
144 defaultDir = getcwd()
145
146
147 super(RelaxFileDialog, self).__init__(parent, message=message, defaultDir=defaultDir, defaultFile=defaultFile, wildcard=wildcard, style=style, pos=pos)
148
149
151 """Return the selected file.
152
153 @return: The name of the selected file(s).
154 @rtype: str or list of str
155 """
156
157
158 if self.style in [wx.FD_OPEN|wx.FD_MULTIPLE, wx.FD_SAVE|wx.FD_MULTIPLE]:
159 file = self.GetPaths()
160
161
162 else:
163 file = self.GetPath()
164
165
166 chdir(self.GetDirectory())
167
168
169 return file
170
171
173 """The file selector GUI element.
174
175 @param event: The wx event.
176 @type event: wx event
177 """
178
179
180 if status.show_gui and self.ShowModal() != wx.ID_OK:
181 return
182
183
184 file = self.get_file()
185
186
187 self.field.SetValue(str_to_gui(file))
188
189
190 self.field.SetInsertionPoint(len(file))
191