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="", tooltip=None, tooltip_button=None, button_text=" Change", control=wx.TextCtrl, icon=fetch_icon('oxygen.actions.document-open', "16x16"), fn=None, editable=True, button=False, 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 text of the control.
55 @type default: str
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 icon: The path of the icon to use for the button.
65 @type icon: str
66 @keyword fn: The function or method to execute when clicking on the button. If this is a string, then an equivalent function will be searched for in the control object.
67 @type fn: func or str
68 @keyword editable: A flag specifying if the control is editable or not.
69 @type editable: bool
70 @keyword button: A flag which if True will cause a button to appear.
71 @type button: bool
72 @keyword width_text: The width of the text element.
73 @type width_text: int
74 @keyword width_button: The width of the button.
75 @type width_button: int
76 @keyword spacer: The horizontal spacing between the elements.
77 @type spacer: int
78 """
79
80
81 sizer = wx.BoxSizer(wx.HORIZONTAL)
82
83
84 self.label = wx.StaticText(parent, -1, text)
85 self.label.SetMinSize((width_text, -1))
86 self.label.SetFont(font.normal)
87 sizer.Add(self.label, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
88
89
90 dc = wx.ScreenDC()
91 dc.SetFont(font.normal)
92 x, y = dc.GetTextExtent(text)
93 size_horizontal = y + 8
94
95
96 if dep_check.wx_classic:
97 sizer.AddSpacer((spacer, -1))
98 else:
99 sizer.AddSpacer(spacer)
100
101
102 self.field = control(parent, -1, str_to_gui(default))
103 self.field.SetMinSize((-1, size_horizontal))
104 self.field.SetFont(font.normal)
105 self.field.SetEditable(editable)
106 if not editable:
107 colour = parent.GetBackgroundColour()
108 self.field.SetOwnBackgroundColour(colour)
109 sizer.Add(self.field, 1, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
110
111
112 if dep_check.wx_classic:
113 sizer.AddSpacer((spacer, -1))
114 else:
115 sizer.AddSpacer(spacer)
116
117
118 if button:
119
120 if isinstance(fn, str):
121
122 fn = getattr(field, fn)
123
124
125 self.button = wx.lib.buttons.ThemedGenBitmapTextButton(parent, -1, None, str_to_gui(button_text))
126 self.button.SetBitmapLabel(wx.Bitmap(icon, wx.BITMAP_TYPE_ANY))
127 self.button.SetMinSize((width_button, size_horizontal))
128 self.button.SetFont(font.normal)
129 parent.Bind(wx.EVT_BUTTON, fn, self.button)
130 sizer.Add(self.button, 0, wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
131
132
133 else:
134 if dep_check.wx_classic:
135 sizer.AddSpacer((width_button, -1))
136 else:
137 sizer.AddSpacer(width_button)
138
139
140 box.Add(sizer, 0, wx.ALL|wx.EXPAND, 0)
141
142
143 if tooltip:
144 self.label.SetToolTip(wx.ToolTip(tooltip))
145 self.field.SetToolTip(wx.ToolTip(tooltip))
146 if button and tooltip_button:
147 self.button.SetToolTip(wx.ToolTip(tooltip_button))
148
149
150 - def Enable(self, enable=True):
151 """Enable or disable the element for user input.
152
153 @keyword enable: The flag specifying if the element should be enabled or disabled.
154 @type enable: bool
155 """
156
157
158 self.field.Enable(enable)
159 if hasattr(self, 'button'):
160 self.button.Enable(enable)
161
162
163 - def GetValue(self):
164 """Set the value of the control.
165
166 @return: The value of the text control.
167 @rtype: int
168 """
169
170
171 return self.field.GetValue()
172
173
174 - def SetValue(self, value):
175 """Set the value of the control.
176
177 @param value: The value to set the text control to.
178 @type value: text
179 """
180
181
182 return self.field.SetValue(value)
183