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