/
logger.py
59 lines (51 loc) · 1.54 KB
/
logger.py
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
import wx
VERSION = 0.1 # global version number
ERROR = 1
WARNING = 2
INFO = 3
QUESTION = 4
console = False # set True to force logging to console
outFile = None # If not None, logger will write to this file
fName = "log.txt"
def write( msg ):
try:
if outFile is None or console:
print msg
if outFile is not None:
outFile.write( str(msg) + "\n" )
except Exception as e:
print e
pass
def log(name, options, mode=0):
if mode == ERROR:
write( "(E)" + name + ": " + str(options) )
elif mode == WARNING:
write( "(W)" + name + ": " + str(options) )
elif mode == INFO:
write( "(I)" + name + ": " + str(options) )
else:
write( "(?)" + name + ": " + str(options) )
def message(message, mode=0):
if mode == ERROR:
wx.MessageBox(message, "Error", wx.OK | wx.ICON_ERROR)
elif mode == WARNING:
wx.MessageBox(message, "Warning", wx.OK | wx.ICON_EXCLAMATION)
elif mode == INFO:
wx.MessageBox(message, "Message", wx.OK | wx.ICON_INFORMATION)
else:
wx.MessageBox(message, "Message", wx.OK | wx.ICON_QUESTION)
def ask(message, mode=4):
if mode == ERROR:
ret = wx.MessageBox(message, "Error", wx.YES_NO | wx.ICON_ERROR)
elif mode == WARNING:
ret = wx.MessageBox(message, "Warning", wx.YES_NO | wx.ICON_EXCLAMATION)
elif mode == INFO:
ret = wx.MessageBox(message, "Message", wx.YES_NO | wx.ICON_INFORMATION)
elif mode == QUESTION:
ret = wx.MessageBox(message, "Message", wx.YES_NO | wx.ICON_QUESTION)
else:
ret = wx.MessageBox(message, "Message", wx.YES_NO | wx.ICON_QUESTION)
if ret == wx.YES:
return True
else:
return False