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

Revision 2653, 2.2 kB (checked in by jwoithe, 7 years ago)

This is a first pass at converting the signal handling of ffado-mixer to the
new style implemented by pyqtSignal[1]. It is based on patches provided by
Takashi Sakamoto in January 2015[2], Xavier Forestier in November 2016[3]
and additional minor fixes.

Note that this patchset breaks the matrix mixer due to problems with the
treatment of the valueChanged signal from the MixerNode? class. More work is
needed to determine what the problem is and how best to fix it in the
context of the new signal handling.

[1] http://www.riverbankcomputing.co.uk/news/pyqt-45
[2] https://sourceforge.net/p/ffado/mailman/ffado-devel/thread/1421471004-13162-1-git-send-email-o-takashi%40sakamocchi.jp/#msg33244745
[3] https://sourceforge.net/p/ffado/mailman/message/35457569/

  • 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, pyqtSignal, QString
25
26 import logging
27 log = logging.getLogger('logginghandler')
28
29 class QStatusLogger( QObject, logging.Handler ):
30     log = pyqtSignal(QString, int, name='log')
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.log.connect(statusbar.showMessage)
36
37     def emit( self, record ):
38         self.log.emit('%s: %s'.format(record.name, record.getMessage()), 5000)
39
40 class QTextLogger( logging.Handler ):
41     def __init__( self, parent, level=logging.NOTSET ):
42         logging.Handler.__init__( self, level )
43
44         self.textedit = QTextEdit( parent )
45
46         self.textedit.setReadOnly( True )
47         self.textedit.setAcceptRichText( True )
48
49     def emit( self, record ):
50         color = QColor( "#000000" )
51         if record.levelno > 20:
52             color = QColor( "#ffff00" )
53         if record.levelno > 30:
54             color = QColor( "#ff0000" )
55         if record.levelno <= 10:
56             color = QColor( "#808080" )
57         self.textedit.setTextColor( color )
58         tmp = "%s %s: %s" % (record.asctime, record.name, record.getMessage())
59         self.textedit.append( tmp )
60         self.textedit.verticalScrollBar().triggerAction( QAbstractSlider.SliderToMaximum )
61
62 #
63 # vim: et
64 #
Note: See TracBrowser for help on using the browser.