root/trunk/libffado/support/mixer-qt4/ffado/logginghandler.py

Revision 1934, 2.3 kB (checked in by adi, 13 years ago)

Shebang-line cleanup. Closes: #292

Patch provided by Orcan Ogetbil (Fedora).

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