1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """Module containing a set of special GUI elements to be used in the relax wizards."""
24
25
26 import sys
27 import wx
28 import wx.lib.mixins.listctrl
29
30
31 from gui.input_elements.sequence import Sequence, Sequence_list_ctrl, Sequence_window
32 from status import Status; status = Status()
33
34
36 """Wizard GUI element for the input of all types of 2D Python sequence objects.
37
38 The supported Python types include:
39 - list of floats
40 - list of integers
41 - list of strings
42 - tuple of floats
43 - tuple of integers
44 - tuple of strings
45 """
46
47 - def __init__(self, name=None, default=None, parent=None, sizer=None, element_type='default', seq_type=None, value_type=None, dim=None, min=0, max=1000, titles=None, desc=None, combo_choices=None, combo_data=None, combo_list_min=None, tooltip=None, divider=None, padding=0, spacer=None, height_element=27, read_only=False, can_be_none=False):
48 """Set up the element.
49
50 @keyword name: The name of the element to use in titles, etc.
51 @type name: str
52 @keyword default: The default value of the element.
53 @type default: 2D sequence object
54 @keyword parent: The wizard GUI element.
55 @type parent: wx.Panel instance
56 @keyword sizer: The sizer to put the input field widget into.
57 @type sizer: wx.Sizer instance
58 @keyword element_type: The type of GUI element to create. If set to 'default', the wx.TextCtrl element with a button to bring up a dialog with ListCtrl will be used. If set to 'combo_list', the special gui.components.combo_list.Combo_list element will be used.
59 @type element_type: str
60 @keyword seq_type: The type of Python sequence. This should be one of 'list' or 'tuple'.
61 @type seq_type: str
62 @keyword value_type: The type of Python object that the value should be. This can be one of 'float', 'int', or 'str'.
63 @type value_type: str
64 @keyword dim: The dimensions that a list or tuple must conform to. For a 1D sequence, this can be a single value or a tuple of possible sizes. For a 2D sequence (a numpy matrix or list of lists), this must be a tuple of the fixed dimension sizes, e.g. a 3x5 matrix should be specified as (3, 5).
65 @type dim: int, tuple of int or None
66 @keyword min: For a SpinCtrl, the minimum value allowed.
67 @type min: int
68 @keyword max: For a SpinCtrl, the maximum value allowed.
69 @type max: int
70 @keyword titles: The titles of each of the elements of the fixed width second dimension.
71 @type titles: list of str
72 @keyword desc: The text description.
73 @type desc: str
74 @keyword combo_choices: The list of choices to present to the user. This is only used if the element_type is set to 'combo'.
75 @type combo_choices: list of str
76 @keyword combo_data: The data returned by a call to GetValue(). This is only used if the element_type is set to 'combo'. If supplied, it should be the same length at the combo_choices list. If not supplied, the combo_choices list will be used for the returned data.
77 @type combo_data: list
78 @keyword combo_list_min: The minimum length for the Combo_list object.
79 @type combo_list_min: int or None
80 @keyword tooltip: The tooltip which appears on hovering over the text or input field.
81 @type tooltip: str
82 @keyword divider: The optional position of the divider. If None, the class variable _div_left will be used.
83 @type divider: None or int
84 @keyword padding: Spacing to the left and right of the widgets.
85 @type padding: int
86 @keyword spacer: The amount of spacing to add below the field in pixels. If None, a stretchable spacer will be used.
87 @type spacer: None or int
88 @keyword height_element: The height in pixels of the GUI element.
89 @type height_element: int
90 @keyword read_only: A flag which if True means that the text of the element cannot be edited.
91 @type read_only: bool
92 @keyword can_be_none: A flag which specifies if the element is allowed to have the None value.
93 @type can_be_none: bool
94 """
95
96
97 self.titles = titles
98
99
100 Sequence.__init__(self, name=name, default=default, parent=parent, sizer=sizer, element_type=element_type, seq_type=seq_type, value_type=value_type, dim=dim, min=min, max=max, desc=desc, combo_choices=combo_choices, combo_data=combo_data, combo_list_min=combo_list_min, tooltip=tooltip, divider=divider, padding=padding, spacer=spacer, height_element=height_element, read_only=read_only, can_be_none=can_be_none)
101
102
134
135
136
138 """The Python 2D sequence object editor window."""
139
140 - def __init__(self, name='', seq_type='list', value_type='str', dim=None, titles=None):
141 """Set up the string list editor window.
142
143 @keyword name: The name of the window.
144 @type name: str
145 @keyword seq_type: The type of Python sequence. This should be one of 'list' or 'tuple'.
146 @type seq_type: str
147 @keyword value_type: The type of Python data expected in the sequence. This should be one of 'float', 'int', or 'str'.
148 @type value_type: str
149 @keyword dim: The fixed dimensions that the sequence must conform to.
150 @type dim: tuple of int or None
151 @keyword titles: The titles of each of the elements of the fixed width second dimension. If the dim argument is given, the length of this list must match the second number.
152 @type titles: list of str
153 """
154
155
156 self.titles = titles
157 if titles == None:
158 self.titles = [wx.EmptyString] * dim[1]
159
160
161 if dim == None:
162 dim = (None, len(self.titles))
163
164
165 Sequence_window.__init__(self, name=name, seq_type=seq_type, value_type=value_type, dim=dim)
166
167
169 """Return the values as a 2D sequence of values.
170
171 @return: The list of lists of values.
172 @rtype: list of lists of str
173 """
174
175
176 values = []
177
178
179 for i in range(self.sequence.GetItemCount()):
180
181 values.append([])
182
183
184 for j in range(self.dim[1]):
185
186 item = self.sequence.GetItem(i, j)
187
188
189 values[-1].append(self.convert_from_gui(item.GetText()))
190
191
192 if self.seq_type == 'tuple':
193 values[-1] = tuple(values[-1])
194
195
196 if self.seq_type == 'tuple':
197 values = tuple(values)
198
199
200 return values
201
202
204 """Set up the list of lists values.
205
206 @param values: The list of lists of values to add to the list.
207 @type values: list of lists of str or None
208 """
209
210
211 if values == None:
212 return
213
214
215 for i in range(len(values)):
216
217 if self.dim[0] != None:
218 self.sequence.SetStringItem(index=i, col=0, label=self.convert_to_gui(values[i][0]))
219
220
221 else:
222 self.sequence.InsertStringItem(sys.maxint, self.convert_to_gui(values[i][0]))
223
224
225 for j in range(1, self.dim[1]):
226
227 self.sequence.SetStringItem(i, j, self.convert_to_gui(values[i][j]))
228
229
230 self.Refresh()
231
232
234 """Set up the list control.
235
236 @param sizer: A sizer object.
237 @type sizer: wx.Sizer instance
238 """
239
240
241 self.sequence = Sequence_list_ctrl(self)
242
243
244 title = "%s%s" % (self.name[0].upper(), self.name[1:])
245
246
247 for i in range(self.dim[1]):
248 self.sequence.InsertColumn(i, self.titles[i])
249 self.sequence.SetColumnWidth(i, self.width/self.dim[1])
250
251
252 sizer.Add(self.sequence, 1, wx.ALL|wx.EXPAND, 0)
253
254
255 if self.dim[0] != None:
256 for i in range(self.dim[0]):
257 self.append_row(None)
258