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