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