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 the base class for all frames."""
25
26
27 import wx
28 import wx.lib.buttons
29
30
31 from gui.fonts import font
32 from gui.paths import icon_16x16
33 from gui.string_conv import str_to_gui
34
35
37 """The analysis specific spin control."""
38
39 - def __init__(self, box, parent, text="", default=0, min=0, max=1000, tooltip=None, control=wx.SpinCtrl, width_text=200, width_button=80, spacer=0):
40 """Create a text selection element using a spinner for the frame.
41
42 This consists of a horizontal layout with a static text element and a spin control
43
44 @param box: The box element to pack the structure file selection GUI element into.
45 @type box: wx.BoxSizer instance
46 @param parent: The parent GUI element.
47 @type parent: wx object
48 @keyword text: The static text.
49 @type text: str
50 @keyword default: The default value of the control.
51 @type default: int
52 @keyword min: The minimum value allowed.
53 @type min: int
54 @keyword max: The maximum value allowed.
55 @type max: int
56 @keyword tooltip: The tooltip which appears on hovering over the text or spin control.
57 @type tooltip: str
58 @keyword control: The control class to use.
59 @type control: wx.SpinCtrl derived class
60 @keyword width_text: The width of the text element.
61 @type width_text: int
62 @keyword width_button: The width of the button.
63 @type width_button: int
64 @keyword spacer: The horizontal spacing between the elements.
65 @type spacer: int
66 """
67
68
69 sizer = wx.BoxSizer(wx.HORIZONTAL)
70
71
72 self.label = wx.StaticText(parent, -1, text)
73 self.label.SetMinSize((width_text, -1))
74 self.label.SetFont(font.normal)
75 sizer.Add(self.label, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
76
77
78 size = self.label.GetSize()
79 size_horizontal = size[1] + 8
80
81
82 sizer.AddSpacer((spacer, -1))
83
84
85 self.control = control(parent, -1, text, min=min, max=max)
86 self.control.SetMinSize((-1, size_horizontal))
87 self.control.SetFont(font.normal)
88 sizer.Add(self.control, 1, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
89 self.control.SetValue(default)
90
91
92 sizer.AddSpacer((spacer, -1))
93
94
95 sizer.AddSpacer((width_button, -1))
96
97
98 if tooltip:
99 self.label.SetToolTipString(tooltip)
100 self.control.SetToolTipString(tooltip)
101
102
103 box.Add(sizer, 0, wx.ALL|wx.EXPAND, 0)
104
105
106 - def Enable(self, enable=True):
107 """Enable or disable the window for user input.
108
109 @keyword enable: The flag specifying if the control should be enabled or disabled.
110 @type enable: bool
111 """
112
113
114 self.control.Enable(enable)
115
116
118 """Set the value of the control.
119
120 @return: The value of the spin control.
121 @rtype: int
122 """
123
124
125 return self.control.GetValue()
126
127
129 """Set the value of the control.
130
131 @param value: The value to set the spin control to.
132 @type value: int
133 """
134
135
136 return self.control.SetValue(value)
137
138
140 """The analysis specific text control.
141
142 This consists of three elements: wx.StaticText, wx.TextCtrl, and wx.Button.
143 """
144
145 - def __init__(self, box, parent, text="", default="", tooltip=None, button_text=" Change", control=wx.TextCtrl, icon=icon_16x16.open, fn=None, editable=True, button=False, width_text=200, width_button=80, spacer=0):
146 """Create a text selection element for the frame.
147
148 This consists of a horizontal layout with a static text element, a text control, and an optional button.
149
150 @param box: The box element to pack the structure file selection GUI element into.
151 @type box: wx.BoxSizer instance
152 @param parent: The parent GUI element.
153 @type parent: wx object
154 @keyword text: The static text.
155 @type text: str
156 @keyword default: The default text of the control.
157 @type default: str
158 @keyword tooltip: The tooltip which appears on hovering over the text or input field.
159 @type tooltip: str
160 @keyword button_text: The text to display on the button.
161 @type button_text: str
162 @keyword control: The control class to use.
163 @type control: wx.TextCtrl derived class
164 @keyword icon: The path of the icon to use for the button.
165 @type icon: str
166 @keyword fn: The function or method to execute when clicking on the button. If this is a string, then an equivalent function will be searched for in the control object.
167 @type fn: func or str
168 @keyword editable: A flag specifying if the control is editable or not.
169 @type editable: bool
170 @keyword button: A flag which if True will cause a button to appear.
171 @type button: bool
172 @keyword width_text: The width of the text element.
173 @type width_text: int
174 @keyword width_button: The width of the button.
175 @type width_button: int
176 @keyword spacer: The horizontal spacing between the elements.
177 @type spacer: int
178 """
179
180
181 sizer = wx.BoxSizer(wx.HORIZONTAL)
182
183
184 self.label = wx.StaticText(parent, -1, text)
185 self.label.SetMinSize((width_text, -1))
186 self.label.SetFont(font.normal)
187 sizer.Add(self.label, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
188
189
190 size = self.label.GetSize()
191 size_horizontal = size[1] + 8
192
193
194 sizer.AddSpacer((spacer, -1))
195
196
197 self.field = control(parent, -1, str_to_gui(default))
198 self.field.SetMinSize((-1, size_horizontal))
199 self.field.SetFont(font.normal)
200 self.field.SetEditable(editable)
201 if not editable:
202 colour = parent.GetBackgroundColour()
203 self.field.SetOwnBackgroundColour(colour)
204 sizer.Add(self.field, 1, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
205
206
207 sizer.AddSpacer((spacer, -1))
208
209
210 if button:
211
212 if isinstance(fn, str):
213
214 fn = getattr(field, fn)
215
216
217 self.button = wx.lib.buttons.ThemedGenBitmapTextButton(parent, -1, None, str_to_gui(button_text))
218 self.button.SetBitmapLabel(wx.Bitmap(icon, wx.BITMAP_TYPE_ANY))
219 self.button.SetMinSize((width_button, size_horizontal))
220 self.button.SetFont(font.normal)
221 parent.Bind(wx.EVT_BUTTON, fn, self.button)
222 sizer.Add(self.button, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
223
224
225 else:
226 sizer.AddSpacer((width_button, -1))
227
228
229 box.Add(sizer, 0, wx.ALL|wx.EXPAND, 0)
230
231
232 if tooltip:
233 self.label.SetToolTipString(tooltip)
234 self.field.SetToolTipString(tooltip)
235 if button:
236 self.button.SetToolTipString(tooltip)
237
238
239 - def Enable(self, enable=True):
240 """Enable or disable the element for user input.
241
242 @keyword enable: The flag specifying if the element should be enabled or disabled.
243 @type enable: bool
244 """
245
246
247 self.field.Enable(enable)
248 if hasattr(self, 'button'):
249 self.button.Enable(enable)
250
251
252 - def GetValue(self):
253 """Set the value of the control.
254
255 @return: The value of the text control.
256 @rtype: int
257 """
258
259
260 return self.field.GetValue()
261
262
263 - def SetValue(self, value):
264 """Set the value of the control.
265
266 @param value: The value to set the text control to.
267 @type value: text
268 """
269
270
271 return self.field.SetValue(value)
272