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 graphics import fetch_icon
33 from gui.fonts import font
34 from gui.string_conv import str_to_gui
35
36
38 """The analysis specific text control.
39
40 This consists of three elements: wx.StaticText, wx.TextCtrl, and wx.Button.
41 """
42
43 - def __init__(self, box, parent, text="", default=True, tooltip=None, tooltip_button=None, button_text=" Toggle", control=wx.TextCtrl, width_text=200, width_button=80, spacer=0):
44 """Create a text selection element for the frame.
45
46 This consists of a horizontal layout with a static text element, a text control, and an optional button.
47
48 @param box: The box element to pack the structure file selection GUI element into.
49 @type box: wx.BoxSizer instance
50 @param parent: The parent GUI element.
51 @type parent: wx object
52 @keyword text: The static text.
53 @type text: str
54 @keyword default: The default value of the control.
55 @type default: bool
56 @keyword tooltip: The tooltip which appears on hovering over the text or input field.
57 @type tooltip: str
58 @keyword tooltip_button: The separate tooltip for the button.
59 @type tooltip_button: str
60 @keyword button_text: The text to display on the button.
61 @type button_text: str
62 @keyword control: The control class to use.
63 @type control: wx.TextCtrl derived class
64 @keyword width_text: The width of the text element.
65 @type width_text: int
66 @keyword width_button: The width of the button.
67 @type width_button: int
68 @keyword spacer: The horizontal spacing between the elements.
69 @type spacer: int
70 """
71
72
73 self.state = default
74
75
76 sizer = wx.BoxSizer(wx.HORIZONTAL)
77
78
79 self.label = wx.StaticText(parent, -1, text)
80 self.label.SetMinSize((width_text, -1))
81 self.label.SetFont(font.normal)
82 sizer.Add(self.label, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
83
84
85 dc = wx.ScreenDC()
86 dc.SetFont(font.normal)
87 x, y = dc.GetTextExtent(text)
88 size_horizontal = y + 8
89
90
91 if dep_check.wx_classic:
92 sizer.AddSpacer((spacer, -1))
93 else:
94 sizer.AddSpacer(spacer)
95
96
97 self.field = control(parent, -1, str_to_gui(default))
98 self.field.SetMinSize((-1, size_horizontal))
99 self.field.SetFont(font.normal)
100 colour = parent.GetBackgroundColour()
101 self.field.SetOwnBackgroundColour(colour)
102 sizer.Add(self.field, 1, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
103
104
105 if dep_check.wx_classic:
106 sizer.AddSpacer((spacer, -1))
107 else:
108 sizer.AddSpacer(spacer)
109
110
111 self.button = wx.lib.buttons.ThemedGenBitmapTextButton(parent, -1, None, str_to_gui(button_text))
112 if default == True:
113 self.button.SetBitmapLabel(wx.Bitmap(fetch_icon('oxygen.actions.media-record-relax-green'), wx.BITMAP_TYPE_ANY))
114 else:
115 self.button.SetBitmapLabel(wx.Bitmap(fetch_icon('oxygen.actions.media-record'), wx.BITMAP_TYPE_ANY))
116 self.button.SetMinSize((width_button, size_horizontal))
117 self.button.SetFont(font.normal)
118 parent.Bind(wx.EVT_BUTTON, self.toggle, self.button)
119 sizer.Add(self.button, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
120
121
122 box.Add(sizer, 0, wx.ALL|wx.EXPAND, 0)
123
124
125 if tooltip:
126 self.label.SetToolTip(wx.ToolTip(tooltip))
127 self.field.SetToolTip(wx.ToolTip(tooltip))
128 if tooltip_button:
129 self.button.SetToolTip(wx.ToolTip(tooltip_button))
130
131
132 - def Enable(self, enable=True):
133 """Enable or disable the element for user input.
134
135 @keyword enable: The flag specifying if the element should be enabled or disabled.
136 @type enable: bool
137 """
138
139
140 self.button.Enable(enable)
141
142
144 """Set the value of the control.
145
146 @return: The value of the text control.
147 @rtype: int
148 """
149
150
151 return self.state
152
153
155 """Set the value of the control.
156
157 @param value: The value to set the boolean control to.
158 @type value: bool
159 """
160
161
162 if value == True:
163 self.field.SetValue('True')
164 self.button.SetBitmapLabel(wx.Bitmap(fetch_icon('oxygen.actions.media-record-relax-green'), wx.BITMAP_TYPE_ANY))
165 self.state = True
166
167
168 else:
169 self.field.SetValue('False')
170 self.button.SetBitmapLabel(wx.Bitmap(fetch_icon('oxygen.actions.media-record'), wx.BITMAP_TYPE_ANY))
171 self.state = False
172
173
174 - def toggle(self, event=None):
175 """Switch the state."""
176
177
178 if self.state == False:
179 self.field.SetValue('True')
180 self.button.SetBitmapLabel(wx.Bitmap(fetch_icon('oxygen.actions.media-record-relax-green'), wx.BITMAP_TYPE_ANY))
181 self.state = True
182
183
184 else:
185 self.field.SetValue('False')
186 self.button.SetBitmapLabel(wx.Bitmap(fetch_icon('oxygen.actions.media-record'), wx.BITMAP_TYPE_ANY))
187 self.state = False
188