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 wx
27
28
29 import dep_check
30 from gui.fonts import font
31 from gui.string_conv import bool_to_gui, gui_to_bool
32 from lib.errors import RelaxError
33 from status import Status; status = Status()
34
35
37 """Wizard GUI element for boolean selection."""
38
39 - def __init__(self, name=None, parent=None, element_type='default', sizer=None, desc=None, tooltip=None, divider=None, padding=0, spacer=None, height_element=27, default=True):
40 """Build the boolean selector widget for selecting between True and False.
41
42 @keyword name: The name of the element to use in titles, etc.
43 @type name: str
44 @keyword parent: The wizard GUI element.
45 @type parent: wx.Panel instance
46 @keyword element_type: The type of GUI element to create. This is currently unused, but can in the future specify alternative selector widgets.
47 @type element_type: str
48 @keyword sizer: The sizer to put the combo box widget into.
49 @type sizer: wx.Sizer instance
50 @keyword desc: The text description.
51 @type desc: str
52 @keyword tooltip: The tooltip which appears on hovering over the text or input field.
53 @type tooltip: str
54 @keyword divider: The position of the divider.
55 @type divider: int
56 @keyword padding: Spacing to the left and right of the widgets.
57 @type padding: int
58 @keyword spacer: The amount of spacing to add below the field in pixels. If None, a stretchable spacer will be used.
59 @type spacer: None or int
60 @keyword height_element: The height in pixels of the GUI element.
61 @type height_element: int
62 @keyword default: The default boolean value.
63 @type default: bool
64 """
65
66
67 self.default = default
68 self.name = name
69 self.element_type = element_type
70
71
72 sub_sizer = wx.BoxSizer(wx.HORIZONTAL)
73
74
75 sub_sizer.AddSpacer(padding)
76
77
78 text = wx.StaticText(parent, -1, desc, style=wx.ALIGN_LEFT)
79 text.SetFont(font.normal)
80 sub_sizer.Add(text, 0, wx.LEFT|wx.ALIGN_CENTER_VERTICAL, 0)
81
82
83 if not divider:
84 raise RelaxError("The divider position has not been supplied.")
85
86
87 dc = wx.ScreenDC()
88 dc.SetFont(font.normal)
89 x, y = dc.GetTextExtent(desc)
90 if dep_check.wx_classic:
91 sub_sizer.AddSpacer((divider - x, 0))
92 else:
93 sub_sizer.AddSpacer(int(divider - x))
94
95
96 style = wx.CB_DROPDOWN | wx.CB_READONLY
97 self.combo = wx.ComboBox(parent, -1, value=bool_to_gui(default), style=style, choices=['True', 'False'])
98 self.combo.SetMinSize((50, height_element))
99 self.combo.SetFont(font.normal)
100 sub_sizer.Add(self.combo, 1, wx.ADJUST_MINSIZE|wx.ALIGN_CENTER_VERTICAL, 0)
101
102
103 sub_sizer.AddSpacer(padding)
104
105
106 sizer.Add(sub_sizer, 1, wx.EXPAND|wx.ALL, 0)
107
108
109 if spacer == None:
110 sizer.AddStretchSpacer()
111 else:
112 sizer.AddSpacer(spacer)
113
114
115 if tooltip:
116 text.SetToolTip(wx.ToolTip(tooltip))
117 self.combo.SetToolTip(wx.ToolTip(tooltip))
118
119
121 """Special method for clearing or resetting the GUI element."""
122
123
124 self.combo.SetStringSelection(bool_to_gui(self.default))
125
126
128 """Special method for returning the value of the GUI element.
129
130 @return: The string list value.
131 @rtype: list of str
132 """
133
134
135 return gui_to_bool(self.combo.GetValue())
136
137
139 """Special method for setting the value of the GUI element.
140
141 @param value: The value to set.
142 @type value: list of str
143 """
144
145
146 self.combo.SetStringSelection(bool_to_gui(value))
147