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