1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 import os, codecs
17 import wx
18 from i18n import ChandlerMessageFactory as _
19
20
21 """
22 Note: need to migrate translation logic to a base wx dialog class that can
23 handle all the work for sub classes
24 """
25
27 """
28 Given an item and a list of attributes, display a modal dialog with
29 a text field per attribute, with each field populated directly from
30 the item's attribute values. If the user OK's the dialog, the new
31 values are applied to the item's attributes.
32
33 @param frame: A wx parent frame
34 @type frame: wx frame
35 @param title: The title string for the dialog
36 @type title: String
37 @param item: A chandler item
38 @type item: Item
39 @param attrList: A list of dictionaries, each one having the following
40 keys::
41
42 "attr": an attribute name
43 "label": a label to display for the field
44 "password": an optional key, set to True if you want this field to
45 be displayed like a password (with asterisks)
46
47 """
48
49 win = ItemValuesDialog(title, item, attrList)
50 win.CenterOnScreen()
51 val = win.ShowModal()
52
53 if val == wx.ID_OK:
54
55 win.AssignNewValues()
56
57 win.Destroy()
58 return val == wx.ID_OK
59
61 - def __init__(self, title, item, attrList, size=wx.DefaultSize,
62 pos=wx.DefaultPosition, style=wx.DEFAULT_DIALOG_STYLE):
63
64
65
66
67
68 pre = wx.PreDialog()
69 pre.Create(None, -1, title, pos, size, style)
70
71
72
73
74 self.this = pre.this
75
76
77
78 sizer = wx.BoxSizer(wx.VERTICAL)
79
80 textControls = []
81 for valueDict in attrList:
82 box = wx.BoxSizer(wx.HORIZONTAL)
83
84 label = wx.StaticText(self, -1, valueDict["label"])
85 box.Add(label, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
86
87 if valueDict.get("password", False):
88 text = wx.TextCtrl(self, -1,
89 getattr(item, valueDict["attr"]),
90 wx.DefaultPosition, [400,-1], wx.TE_PASSWORD)
91 else:
92 text = wx.TextCtrl(self, -1,
93 getattr(item, valueDict["attr"]),
94 wx.DefaultPosition, [400,-1])
95 box.Add(text, 1, wx.ALIGN_CENTRE|wx.ALL, 5)
96
97 sizer.AddSizer(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
98 textControls.append(text)
99
100 line = wx.StaticLine(self, -1, size=(20,-1), style=wx.LI_HORIZONTAL)
101 sizer.Add(line, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.RIGHT|wx.TOP, 5)
102
103 box = wx.BoxSizer(wx.HORIZONTAL)
104
105 btn = wx.Button(self, wx.ID_OK)
106 btn.SetDefault()
107 box.Add(btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
108
109 btn = wx.Button(self, wx.ID_CANCEL)
110 box.Add(btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
111
112 sizer.Add(box, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
113
114 self.SetSizer(sizer)
115 self.SetAutoLayout(True)
116 sizer.Fit(self)
117
118
119
120 self.chandlerTextControls = textControls
121 self.chandlerItem = item
122 self.chandlerAttrs = attrList
123
125 i = 0
126 for (valueDict) in self.chandlerAttrs:
127 setattr(self.chandlerItem, valueDict["attr"],
128 self.chandlerTextControls[i].GetValue())
129 i += 1
130
131
132
133
135 """
136 Prompt the user to enter in a string. Return None if cancel is hit.
137
138 @param title: The title string for the dialog
139 @type title: String
140 @param message: A message prompting the user for input
141 @type message: String
142 @param defaultValue: A value to populate the text field with
143 @type defaultValue: String
144 """
145 win = promptUserDialog(title, message, defaultValue)
146 win.CenterOnScreen()
147 val = win.ShowModal()
148
149 if val == wx.ID_OK:
150
151 value = win.GetValue()
152
153 else:
154 value = None
155
156 win.Destroy()
157
158 return value
159
160 -def promptUserAction(title, message,
161 okayTitle=wx.EmptyString, cancelTitle=wx.EmptyString):
162 """
163 Prompt the user to choose between two actions, as defined by
164 the two buttons in the dialog. No text entry is provided for.
165
166 @param title: The title string for the dialog
167 @type title: String
168 @param message: A message prompting the user for input
169 @type message: String
170 @param defaultValue: A value to populate the text field with
171 @type defaultValue: String
172 @param okayTitle: The title for the first button, selecting which
173 will return the value wx.ID_OK
174 @type okayTitle: String
175 @param cancelTitle: The title for the second button, selecting which
176 will return the value wx.ID_CANCEL
177 @type cancelTitle: String
178 """
179 win = promptUserDialog(title, message, None, size=(500,-1),
180 button1Title=okayTitle, button2Title=cancelTitle)
181 win.CenterOnScreen()
182 val = win.ShowModal()
183
184 win.Destroy()
185
186 return val
187
201
202
204 message = _(u"You have addressed this message to invalid email addresses.")
205 win = MailAddressErrorDialog(message)
206 win.CenterOnScreen()
207 val = win.ShowModal()
208
209 win.Destroy()
210
211 if val == wx.ID_OK:
212 return False
213
214 return True
215
218 size = wx.DefaultSize
219 pos = wx.DefaultPosition
220 style = wx.DEFAULT_DIALOG_STYLE
221
222
223
224
225
226 pre = wx.PreDialog()
227 pre.Create(None, -1, _(u"Mail Error"), pos, size, style)
228
229
230
231
232 self.this = pre.this
233
234
235
236 sizer = wx.BoxSizer(wx.VERTICAL)
237 label = wx.StaticText(self, -1, message)
238 sizer.Add(label, 0, wx.ALIGN_CENTER|wx.ALL, 55)
239
240 box = wx.BoxSizer(wx.HORIZONTAL)
241
242 self.addButtons(box)
243
244 sizer.Add(box, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
245
246 self.SetSizer(sizer)
247 self.SetAutoLayout(True)
248 sizer.Fit(self)
249
252
261
262
271
272
274 - def __init__(self, title, message, value, isPassword=False,
275 size=wx.DefaultSize, pos=wx.DefaultPosition,
276 style=wx.DEFAULT_DIALOG_STYLE,
277 button1Title=wx.EmptyString, button2Title=wx.EmptyString):
278
279
280
281
282
283 pre = wx.PreDialog()
284 pre.Create(None, -1, title, pos, size, style)
285
286
287
288
289 self.this = pre.this
290
291
292
293 sizer = wx.BoxSizer(wx.VERTICAL)
294 label = wx.StaticText(self, -1, message, size=[500,-1])
295 sizer.Add(label, 0, wx.ALIGN_CENTER|wx.ALL, 5)
296
297 box = wx.BoxSizer(wx.HORIZONTAL)
298
299 if value is not None:
300 if isPassword:
301 text = wx.TextCtrl(self, -1, value, wx.DefaultPosition, [500,-1],
302 wx.TE_PASSWORD)
303 else:
304 text = wx.TextCtrl(self, -1, value, wx.DefaultPosition, [500,-1])
305 box.Add(text, 1, wx.ALIGN_CENTRE|wx.ALL, 5)
306 else:
307 text = None
308
309 sizer.Add(box, 0, wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
310
311
312
313
314 box = wx.BoxSizer(wx.HORIZONTAL)
315
316 btn = wx.Button(self, wx.ID_OK, button1Title)
317 btn.SetDefault()
318 box.Add(btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
319
320 btn = wx.Button(self, wx.ID_CANCEL, button2Title)
321 box.Add(btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
322
323 sizer.Add(box, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
324
325 self.SetSizer(sizer)
326 self.SetAutoLayout(True)
327 sizer.Fit(self)
328
329
330
331 self.textControl = text
332 if text is not None:
333 text.SetFocus()
334
336 val = None
337 if self.textControl is not None:
338 val = self.textControl.GetValue()
339 return val
340
341
343 - def __init__(self, parent, title, message, value,
344 size=wx.DefaultSize, pos=wx.DefaultPosition,
345 style=wx.DEFAULT_DIALOG_STYLE):
346
347
348
349
350
351 pre = wx.PreDialog()
352 pre.Create(parent, -1, title, pos, size, style)
353
354
355
356
357 self.this = pre.this
358
359
360
361 sizer = wx.BoxSizer(wx.VERTICAL)
362 label = wx.StaticText(self, -1, message)
363 label.Wrap(400)
364 sizer.Add(label, 0, wx.ALIGN_CENTER|wx.ALL, 5)
365
366
367
368 row = wx.BoxSizer(wx.HORIZONTAL)
369
370 box = wx.BoxSizer(wx.HORIZONTAL)
371
372 checkbox = wx.CheckBox(self, -1, value, wx.DefaultPosition)
373
374 box.Add(checkbox, 1, wx.ALIGN_LEFT|wx.ALL, 5)
375
376 row.Add(box, 1, wx.ALIGN_LEFT|wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
377
378
379
380
381 box = wx.BoxSizer(wx.HORIZONTAL)
382
383 btn = wx.Button(self, wx.ID_YES)
384 btn.SetDefault()
385 box.Add(btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
386
387 btn = wx.Button(self, wx.ID_NO)
388 box.Add(btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
389
390 row.Add(box, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL|wx.ALL, 5)
391 sizer.Add(row, 0, wx.GROW|wx.ALL, 5)
392
393 self.SetSizer(sizer)
394 self.SetAutoLayout(True)
395 sizer.Fit(self)
396
397
398
399 self.checkbox = checkbox
400
401
402
403 self.Bind(wx.EVT_BUTTON, self.End, id=wx.ID_YES)
404 self.Bind(wx.EVT_BUTTON, self.End, id=wx.ID_NO)
405
406 - def End(self, event):
407 self.EndModal(event.GetId())
408
411
412
414
415 win = LogWindow(logList)
416 win.CenterOnScreen()
417 win.ShowModal()
418 win.Destroy()
419
421 - def __init__(self, logList, size=wx.DefaultSize,
422 pos=wx.DefaultPosition, style=wx.DEFAULT_DIALOG_STYLE):