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
33
35 """The analysis specific spin control."""
36
37 - 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):
38 """Create a text selection element using a spinner for the frame.
39
40 This consists of a horizontal layout with a static text element and a spin control
41
42 @param box: The box element to pack the structure file selection GUI element into.
43 @type box: wx.BoxSizer instance
44 @param parent: The parent GUI element.
45 @type parent: wx object
46 @keyword text: The static text.
47 @type text: str
48 @keyword default: The default value of the control.
49 @type default: int
50 @keyword min: The minimum value allowed.
51 @type min: int
52 @keyword max: The maximum value allowed.
53 @type max: int
54 @keyword tooltip: The tooltip which appears on hovering over the text or spin control.
55 @type tooltip: str
56 @keyword control: The control class to use.
57 @type control: wx.SpinCtrl derived class
58 @keyword width_text: The width of the text element.
59 @type width_text: int
60 @keyword width_button: The width of the button.
61 @type width_button: int
62 @keyword spacer: The horizontal spacing between the elements.
63 @type spacer: int
64 """
65
66
67 sizer = wx.BoxSizer(wx.HORIZONTAL)
68
69
70 self.label = wx.StaticText(parent, -1, text)
71 self.label.SetMinSize((width_text, -1))
72 self.label.SetFont(font.normal)
73 sizer.Add(self.label, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
74
75
76 size = self.label.GetSize()
77 size_horizontal = size[1] + 8
78
79
80 sizer.AddSpacer((spacer, -1))
81
82
83 self.control = control(parent, -1, text, min=min, max=max)
84 self.control.SetMinSize((-1, size_horizontal))
85 self.control.SetFont(font.normal)
86 sizer.Add(self.control, 1, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
87 self.control.SetValue(default)
88
89
90 sizer.AddSpacer((spacer, -1))
91
92
93 sizer.AddSpacer((width_button, -1))
94
95
96 if tooltip:
97 self.label.SetToolTipString(tooltip)
98 self.control.SetToolTipString(tooltip)
99
100
101 box.Add(sizer, 0, wx.ALL|wx.EXPAND, 0)
102
103
104 - def Enable(self, enable=True):
105 """Enable or disable the window for user input.
106
107 @keyword enable: The flag specifying if the control should be enabled or disabled.
108 @type enable: bool
109 """
110
111
112 self.control.Enable(enable)
113
114
116 """Set the value of the control.
117
118 @return: The value of the spin control.
119 @rtype: int
120 """
121
122
123 return self.control.GetValue()
124
125
127 """Set the value of the control.
128
129 @param value: The value to set the spin control to.
130 @type value: int
131 """
132
133
134 return self.control.SetValue(value)
135