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