~ubuntu-branches/ubuntu/maverick/pype/maverick-proposed

« back to all changes in this revision

Viewing changes to plugins/logger.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2005-09-13 20:51:29 UTC
  • Revision ID: james.westby@ubuntu.com-20050913205129-ph18px3tkx7ay4pv
Tags: upstream-2.1.1
ImportĀ upstreamĀ versionĀ 2.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
import time
 
3
import sys
 
4
import wx
 
5
import cStringIO
 
6
 
 
7
class pseudo_logger:
 
8
    def __init__(self):
 
9
        self.buffer = cStringIO.StringIO()
 
10
        self.softspace = 0
 
11
        self.lg = 1
 
12
        self.lt = None
 
13
        sys.stdout = self
 
14
        sys.stderr = self
 
15
 
 
16
    def write(self, data):
 
17
        ## print >>sys.__stdout__, repr(data), self.softspace
 
18
        if self.lg and self.lt != time.asctime():
 
19
            self.lt = time.asctime()
 
20
            x = '[ %s ] '%self.lt
 
21
            self.buffer.write(x)
 
22
            sys.__stdout__.write(x)
 
23
        
 
24
        self.lg = data[-1:] == '\n'
 
25
        x = data.replace('\r', '').replace('\n', '\r\n')
 
26
        self.buffer.write(x)
 
27
        sys.__stdout__.write(x.encode('utf8'))
 
28
    
 
29
    def flush(self):
 
30
        sys.__stdout__.flush()
 
31
 
 
32
l = pseudo_logger()
 
33
 
 
34
class logger(wx.TextCtrl):
 
35
    def __init__(self, parent):
 
36
        wx.TextCtrl.__init__(self, parent, -1, style=wx.TE_READONLY|wx.TE_MULTILINE|wx.TE_RICH)
 
37
        self.softspace = 0
 
38
        self.lg = 1
 
39
        self.lt = None
 
40
        sys.stdout = self
 
41
        sys.stderr = self
 
42
        l.buffer.seek(0)
 
43
        self.AppendText(l.buffer.read())
 
44
        del globals()['l']
 
45
 
 
46
    def write(self, data):
 
47
        ## print >>sys.__stdout__, repr(data), self.softspace
 
48
        if self.lg and self.lt != time.asctime():
 
49
            self.lt = time.asctime()
 
50
            x = '[ %s ] '%self.lt
 
51
            self.AppendText(x)
 
52
            sys.__stdout__.write(x)
 
53
            
 
54
        self.lg = data[-1:] == '\n'
 
55
        x = data.replace('\r', '').replace('\n', '\r\n')
 
56
        self.AppendText(x)
 
57
        sys.__stdout__.write(data.encode('utf8'))