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