root/trunk/libffado/support/mixer-qt4/ffado_logginghandler.py

Revision 1492, 2.2 kB (checked in by arnonym, 15 years ago)

Install the logginghandler. And don't print the logmessage to stdout (which effectively doubled the debug-output on the console).

  • Property svn:mergeinfo set to
Line 
1 #!/usr/bin/python
2 #
3 # Copyright (C) 2008 by Arnold Krille
4 #
5 # This file is part of FFADO
6 # FFADO = Free Firewire (pro-)audio drivers for linux
7 #
8 # FFADO is based upon FreeBoB.
9 #
10 # This program is free software: you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation, either version 3 of the License, or
13 # (at your option) any later version.
14 #
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
22 #
23
24 from PyQt4.QtGui import QTextEdit, QAbstractSlider, QColor
25 from PyQt4.QtCore import QObject, SIGNAL, SLOT
26
27 import logging
28 log = logging.getLogger('logginghandler')
29
30 class QStatusLogger( QObject, logging.Handler ):
31     def __init__( self, parent, statusbar, level=logging.NOTSET ):
32         QObject.__init__( self, parent )
33         logging.Handler.__init__( self, level )
34         self.setFormatter( logging.Formatter( "%(name)s: %(message)s" ) )
35         self.connect( self, SIGNAL("log(QString,int)"), statusbar, SLOT("showMessage(QString,int)") )
36
37     def emit( self, record ):
38         QObject.emit( self, SIGNAL("log(QString,int)"), "%s: %s" % (record.name, record.getMessage()), 5000 )
39
40 class QTextLogger( QTextEdit, logging.Handler ):
41     def __init__( self, parent, level=logging.NOTSET ):
42         QTextEdit.__init__( self, parent )
43         logging.Handler.__init__( self, level )
44
45         self.setReadOnly( True )
46         self.setAcceptRichText( True )
47
48     def emit( self, record ):
49         color = QColor( "#000000" )
50         if record.levelno > 20:
51             color = QColor( "#ffff00" )
52         if record.levelno > 30:
53             color = QColor( "#ff0000" )
54         if record.levelno <= 10:
55             color = QColor( "#808080" )
56         self.setTextColor( color )
57         tmp = "%s %s: %s" % (record.asctime, record.name, record.getMessage())
58         self.append( tmp )
59         self.verticalScrollBar().triggerAction( QAbstractSlider.SliderToMaximum )
60
61 #
62 # vim: et
63 #
Note: See TracBrowser for help on using the browser.