Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

[82ddff]: plugins / logger.py Maximize Restore History

Download this file

logger.py    86 lines (71 with data), 2.2 kB

 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import time
import sys
import os
import re
import wx
import cStringIO
import Queue
lerexp = re.compile('(\r\n)|(\r)|(\n)')
def fixle(st):
return lerexp.sub(os.linesep, st)
class pseudo_logger:
def __init__(self):
self.buffer = cStringIO.StringIO()
self.softspace = 0
self.lg = 1
self.lt = None
sys.stdout = sys.stderr = self
def write(self, data):
## print >>sys.__stdout__, repr(data), self.softspace
if self.lg and self.lt != time.asctime():
self.lt = time.asctime()
x = '[ %s ] '%self.lt
self.buffer.write(x)
sys.__stdout__.write(x)
self.lg = data[-1:] == '\n'
x = fixle(data)
self.buffer.write(x)
sys.__stdout__.write(x.encode('utf8'))
def flush(self):
sys.__stdout__.flush()
l = pseudo_logger()
class logger(wx.TextCtrl):
def __init__(self, parent):
global l
wx.TextCtrl.__init__(self, parent, -1, style=wx.TE_READONLY|wx.TE_MULTILINE|wx.TE_RICH)
self.softspace = 0
self.lg = 1
self.lt = None
sys.stdout = sys.stderr = self
l.buffer.seek(0)
wx.TextCtrl.AppendText(self, l.buffer.read())
self.data = Queue.Queue()
l = self
def write(self, data):
## print >>sys.__stdout__, repr(data), self.softspace
if self.lg and self.lt != time.asctime():
self.lt = time.asctime()
x = '[ %s ] '%self.lt
self.data.put(x)
try:
sys.__stdout__.write(x)
except:
pass
self.lg = data[-1:] == '\n'
x = fixle(data)
self.data.put(x)
try:
sys.__stdout__.write(data.encode('utf8'))
except:
pass
wx.CallAfter(self.handle_writes)
def flush(self):
try:
sys.__stdout__.flush()
except:
pass
def handle_writes(self):
while self.data.qsize():
wx.TextCtrl.AppendText(self, self.data.get())
def AppendText(self, txt):
self.write(txt)