-
Notifications
You must be signed in to change notification settings - Fork 19
/
wx_log_handler.py
41 lines (34 loc) · 1018 Bytes
/
wx_log_handler.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
import logging
import wx
import wx.lib.newevent
# create event type
wxLogEvent, EVT_WX_LOG_EVENT = wx.lib.newevent.NewEvent()
class WxLogHandler(logging.Handler):
"""
A handler class which sends log strings to a wx object
https://stackoverflow.com/a/2820928
"""
def __init__(self, wx_dest: wx.Window):
"""
Initialize the handler
@param wx_dest: the destination object to post the event to
"""
logging.Handler.__init__(self)
self.__wxDest = wx_dest
self.level = logging.DEBUG
def flush(self):
"""
does nothing for this handler
"""
def emit(self, record):
"""
Emit a record.
"""
try:
msg = self.format(record)
evt = wxLogEvent(message=msg, levelno=record.levelno)
wx.PostEvent(self.__wxDest, evt)
except (KeyboardInterrupt, SystemExit) as err:
raise err
except Exception:
self.handleError(record)