1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 """The molecule user function GUI elements."""
25
26
27 from generic_fns.mol_res_spin import ALLOWED_MOL_TYPES, generate_spin_id, molecule_loop
28 from generic_fns.pipes import cdp_name, get_pipe, pipe_names
29
30
31 from base import UF_base, UF_page
32 from gui.paths import WIZARD_IMAGE_PATH
33 from gui.misc import gui_to_str, str_to_gui
34
35
36
38 """The container class for holding all GUI elements."""
39
46
47
54
55
56 - def delete(self, mol_name=None):
57 """The molecule.delete user function.
58
59 @param mol_name: The starting molecule name.
60 @type mol_name: str
61 """
62
63
64 wizard, page = self.create_wizard(size_x=700, size_y=400, name='molecule.delete', uf_page=Delete_page, return_page=True)
65
66
67 if mol_name:
68 page.mol.SetValue(str_to_gui(mol_name))
69
70
71 wizard.run()
72
73
74
75 -class Copy_page(UF_page):
76 """The molecule.copy() user function page."""
77
78
79 image_path = WIZARD_IMAGE_PATH + 'molecule.png'
80 uf_path = ['molecule', 'copy']
81
82 - def add_contents(self, sizer):
83 """Add the molecule specific GUI elements.
84
85 @param sizer: A sizer object.
86 @type sizer: wx.Sizer instance
87 """
88
89
90 self.pipe_from = self.combo_box(sizer, "The source data pipe:", [], evt_fn=self.update_mol_list, tooltip=self.uf._doc_args_dict['pipe_from'])
91
92
93 self.mol_from = self.combo_box(sizer, "The source molecule:", [], tooltip=self.uf._doc_args_dict['mol_from'])
94
95
96 self.pipe_to = self.combo_box(sizer, "The destination data pipe name:", [], tooltip=self.uf._doc_args_dict['pipe_to'])
97
98
99 self.mol_to = self.input_field(sizer, "The new molecule name:", tooltip=self.uf._doc_args_dict['mol_to'])
100
101
102 - def on_display(self):
103 """Update the pipe name lists."""
104
105
106 if not gui_to_str(self.pipe_from.GetValue()):
107 self.pipe_from.SetValue(str_to_gui(cdp_name()))
108 if not gui_to_str(self.pipe_to.GetValue()):
109 self.pipe_to.SetValue(str_to_gui(cdp_name()))
110
111
112 self.pipe_from.Clear()
113 self.pipe_to.Clear()
114
115
116 for name in pipe_names():
117 self.pipe_from.Append(str_to_gui(name))
118 self.pipe_to.Append(str_to_gui(name))
119
120
121 self.update_mol_list()
122
123
124 - def on_execute(self):
125 """Execute the user function."""
126
127
128 pipe_from = gui_to_str(self.pipe_from.GetValue())
129 pipe_to = gui_to_str(self.pipe_to.GetValue())
130
131
132 mol_from = gui_to_str(self.mol_from.GetValue())
133 if mol_from:
134 mol_from = "#" + mol_from
135 mol_to = gui_to_str(self.mol_to.GetValue())
136 if mol_to:
137 mol_to = "#" + mol_to
138
139
140 self.execute('molecule.copy', pipe_from=pipe_from, mol_from=mol_from, pipe_to=pipe_to, mol_to=mol_to)
141
142
143 - def update_mol_list(self, event=None):
144 """Update the list of molecules.
145
146 @param event: The wx event.
147 @type event: wx event
148 """
149
150
151 pipe_from = gui_to_str(self.pipe_from.GetValue())
152
153
154 self.mol_from.Clear()
155
156
157 if cdp_name():
158 for mol in molecule_loop(pipe=pipe_from):
159 self.mol_from.Append(str_to_gui(mol.name))
160
161
162
163 -class Create_page(UF_page):
164 """The molecule.create() user function page."""
165
166
167 image_path = WIZARD_IMAGE_PATH + 'molecule.png'
168 uf_path = ['molecule', 'create']
169
170
171 - def add_contents(self, sizer):
172 """Add the molecule specific GUI elements.
173
174 @param sizer: A sizer object.
175 @type sizer: wx.Sizer instance
176 """
177
178
179 self.mol_name = self.input_field(sizer, "Molecule name:", tooltip=self.uf._doc_args_dict['mol_name'])
180
181
182 self.mol_type = self.combo_box(sizer, "Molecule type:", ALLOWED_MOL_TYPES, tooltip=self.uf._doc_args_dict['mol_type'])
183
184
185 - def on_execute(self):
186 """Execute the user function."""
187
188
189 mol_name = str(self.mol_name.GetValue())
190 mol_type = str(self.mol_type.GetValue())
191
192
193 self.execute('molecule.create', mol_name=mol_name, mol_type=mol_type)
194
195
196
197 -class Delete_page(UF_page):
198 """The molecule.delete() user function page."""
199
200
201 image_path = WIZARD_IMAGE_PATH + 'molecule.png'
202 uf_path = ['molecule', 'delete']
203
204
205 - def add_contents(self, sizer):
206 """Add the molecule specific GUI elements.
207
208 @param sizer: A sizer object.
209 @type sizer: wx.Sizer instance
210 """
211
212
213 self.mol_id = self.combo_box(sizer, "Molecule ID:", [], tooltip=self.uf._doc_args_dict['mol_id'])
214
215
216 - def on_display(self):
217 """Clear and update the molecule list."""
218
219
220 self.mol_id.Clear()
221
222
223 if cdp_name():
224 for mol, mol_id in molecule_loop(return_id=True):
225 self.mol_id.Append(str_to_gui(mol_id))
226
227
228 - def on_execute(self):
229 """Execute the user function."""
230
231
232 mol_id = gui_to_str(self.mol_id.GetValue())
233
234
235 self.execute('molecule.delete', mol_id=mol_id)
236