1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 import sys
25 import wx
26 import wx.lib.buttons
27 import wx.lib.scrolledpanel
28
29
30 from graphics import fetch_icon
31 import gui
32 from gui.fonts import font
33 from gui.icons import Relax_icons
34 from gui.misc import bitmap_setup
35 from status import Status; status = Status()
36
37
39 """Message box for general errors.
40
41 @param msg: The message to display.
42 @type msg: str
43 """
44
45
46 if status.show_gui:
47 wx.MessageBox(msg, caption=caption, style=wx.OK|wx.ICON_ERROR)
48
49
50 else:
51
52 if caption:
53 msg = "%s: %s" % (caption, msg)
54
55
56 sys.stderr.write(msg + "\n")
57 sys.stderr.flush()
58
59
60
62 """Message box GUI element for when a setup is incomplete or there is missing data."""
63
64 - def __init__(self, missing=[], parent=None):
65 """Set up the dialog.
66
67 @keyword missing: The list of missing data types.
68 @type missing: list of str
69 @keyword parent: The parent wx element.
70 @type parent: wx object
71 """
72
73
74 wx.Dialog.__init__(self, parent, title='Missing data', style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER|wx.STAY_ON_TOP)
75
76
77 self.SetIcons(Relax_icons())
78
79
80 self.SetSize((600, 400))
81
82
83 self.Centre()
84
85
86 main_sizer = wx.BoxSizer(wx.HORIZONTAL)
87 self.SetSizer(main_sizer)
88
89
90 sizer = gui.misc.add_border(main_sizer, border=10, packing=wx.HORIZONTAL)
91
92
93 bitmap = wx.StaticBitmap(self, -1, bitmap_setup(fetch_icon('oxygen.status.user-busy', "48x48")))
94 sizer.Add(bitmap)
95
96
97 sizer.AddSpacer(20)
98
99
100 panel = wx.lib.scrolledpanel.ScrolledPanel(self, -1)
101 panel.SetAutoLayout(1)
102 panel.SetupScrolling()
103 sizer.Add(panel, 1, wx.ALL|wx.EXPAND, 0)
104
105
106 panel_sizer = wx.BoxSizer(wx.HORIZONTAL)
107 panel.SetSizer(panel_sizer)
108
109
110 msg = "The set up is incomplete.\n\n"
111 if not len(missing):
112 msg = msg + "Please check for missing data.\n"
113 else:
114 msg = msg + "Please check for the following missing information:\n"
115 for data in missing:
116 msg = msg + " %s\n" % data
117
118
119 text = wx.StaticText(panel, -1, msg, style=wx.TE_MULTILINE)
120 panel_sizer.Add(text)
121
122
123 if status.show_gui:
124 self.ShowModal()
125
126
127 else:
128 sys.stderr.write("Missing data: %s\n" % msg)
129 sys.stderr.flush()
130
131
132
134 """Question box GUI element for obtaining a yes/no response from the user."""
135
136
137 border = 10
138 spacer_button = 10
139 spacer_main = 20
140 height_button = 30
141 width_button = 100
142
143 - def __init__(self, msg, parent=None, title='', size=(350, 125), default=False):
144 """A generic question box.
145
146 @param msg: The text message to display.
147 @type msg: str
148 @keyword parent: The parent wx object.
149 @type parent: wx.object instance
150 @keyword title: The window title.
151 @type title: str
152 @keyword default: If True, the default button will be 'yes', otherwise it will be 'no'.
153 @type default: bool
154 @return: The answer.
155 @rtype: bool
156 """
157
158
159 wx.Dialog.__init__(self, parent, title=title, size=size, style=wx.DEFAULT_DIALOG_STYLE|wx.STAY_ON_TOP)
160
161
162 self.pressed = False
163
164
165 if default:
166 self.answer = wx.ID_YES
167 else:
168 self.answer = wx.ID_NO
169
170
171 self.SetIcons(Relax_icons())
172
173
174 self.Centre()
175
176
177 main_sizer = wx.BoxSizer(wx.HORIZONTAL)
178 self.SetSizer(main_sizer)
179
180
181 sizer = gui.misc.add_border(main_sizer, border=self.border, packing=wx.HORIZONTAL)
182
183
184 bitmap = wx.StaticBitmap(self, -1, bitmap_setup(fetch_icon('oxygen.status.dialog-warning-relax-blue', "48x48")))
185 sizer.Add(bitmap)
186
187
188 sizer.AddSpacer(self.spacer_main)
189
190
191 sub_sizer = wx.BoxSizer(wx.VERTICAL)
192 sizer.Add(sub_sizer, 1, wx.ALL|wx.EXPAND, 0)
193
194
195 text = wx.StaticText(self, -1, msg, style=wx.TE_MULTILINE)
196 text.SetFont(font.normal)
197 sub_sizer.Add(text, 1, wx.ALL|wx.EXPAND, 0)
198
199
200 button_sizer = wx.BoxSizer(wx.HORIZONTAL)
201 sub_sizer.Add(button_sizer, 0, wx.ALIGN_RIGHT, 0)
202
203
204 button_yes = wx.lib.buttons.ThemedGenBitmapTextButton(self, -1, None, " Yes")
205 button_yes.SetBitmapLabel(wx.Bitmap(fetch_icon('oxygen.actions.dialog-ok', "22x22"), wx.BITMAP_TYPE_ANY))
206 button_yes.SetFont(font.normal)
207 button_yes.SetMinSize((self.width_button, self.height_button))
208 button_sizer.Add(button_yes, 0, wx.ADJUST_MINSIZE|wx.ALIGN_CENTER_VERTICAL, 0)
209 self.Bind(wx.EVT_BUTTON, self.yes, button_yes)
210
211
212 button_sizer.AddSpacer(self.spacer_button)
213
214
215 button_no = wx.lib.buttons.ThemedGenBitmapTextButton(self, -1, None, " No")
216 button_no.SetBitmapLabel(wx.Bitmap(fetch_icon('oxygen.actions.dialog-cancel', "22x22"), wx.BITMAP_TYPE_ANY))
217 button_no.SetFont(font.normal)
218 button_no.SetMinSize((self.width_button, self.height_button))
219 button_sizer.Add(button_no, 0, wx.ADJUST_MINSIZE|wx.ALIGN_CENTER_VERTICAL, 0)
220 self.Bind(wx.EVT_BUTTON, self.no, button_no)
221
222
223 if self.answer == wx.ID_YES:
224 button_yes.SetFocus()
225 else:
226 button_no.SetFocus()
227
228
229 self.Bind(wx.EVT_CLOSE, self.handler_close)
230
231
233 """Replacement ShowModal method.
234
235 @return: The answer to the question, either wx.ID_YES or wx.ID_NO.
236 @rtype: int
237 """
238
239
240 if status.show_gui:
241 super(Question, self).ShowModal()
242
243
244 return self.answer
245
246
248 """Event handler for the close window action.
249
250 @param event: The wx event.
251 @type event: wx event
252 """
253
254
255 if not self.pressed:
256 self.answer = wx.ID_NO
257
258
259 event.Skip()
260
261
262 - def no(self, event):
263 """No selection.
264
265 @param event: The wx event.
266 @type event: wx event
267 """
268
269
270 self.pressed = True
271
272
273 self.answer = wx.ID_NO
274
275
276 self.Close()
277
278
279 - def yes(self, event):
280 """Yes selection.
281
282 @param event: The wx event.
283 @type event: wx event
284 """
285
286
287 self.pressed = True
288
289
290 self.answer = wx.ID_YES
291
292
293 self.Close()
294