1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# messagedialog.py
import wx
import waxyobject
import core
class MessageDialog(wx.MessageDialog, waxyobject.WaxyObject):
"""Displays a message dialog. Title, text, buttons (OK/Cancel/Yes/No),
and icon are configurable.
"""
_icons = {
'asterisk': wx.ICON_ASTERISK,
'error': wx.ICON_ERROR,
'exclamation': wx.ICON_EXCLAMATION,
'hand': wx.ICON_HAND,
'information': wx.ICON_INFORMATION,
'mask': wx.ICON_MASK,
'question': wx.ICON_QUESTION,
'stop': wx.ICON_STOP,
'warning': wx.ICON_WARNING,
}
def __init__(self, parent, title="Message", text="A message", ok=0,
cancel=0, yes_no=0, icon=""):
style = 0
if ok: style |= wx.OK
if cancel: style |= wx.CANCEL
if yes_no: style |= wx.YES_NO
# set icon... some of these values show the same icon, at least on
# Windows.
icon = self._icons.get(icon.lower(), None)
if icon:
style |= icon
# use a sensible default
if not (ok or cancel or yes_no):
style |= wx.OK
wx.MessageDialog.__init__(self, parent, text, title, style)
def ShowModal(self):
r = wx.MessageDialog.ShowModal(self)
return {
wx.ID_OK: 'ok',
wx.ID_CANCEL: 'cancel',
wx.ID_YES: 'yes',
wx.ID_NO: 'no',
}.get(r, "?")
def ShowMessage(title, text, icon=""):
""" Displays a message with an OK button. A bit like Delphi's ShowMessage
procedure. """
parent = core.GetActiveWindow()
dlg = MessageDialog(parent, title, text, ok=1, icon=icon)
try:
dlg.ShowModal()
finally:
dlg.Destroy()
def Error(msg,parent=None):
dlg = MessageDialog(parent, "Error",
msg,icon='error')
dlg.ShowModal()
dlg.Destroy()
|