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