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