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