Changeset 2726

Show
Ignore:
Timestamp:
01/05/18 01:56:40 (4 months ago)
Author:
jwoithe
Message:

Further Python3/PyQt5 compatibility fixes, enhance "About" dialog box.

This patch was prepared by Orcan Ogetbil on Fedora and tested on that
distribution with PyQt?4-4.12.1 and PyQt?5-5.9.1. It is primarily concerned
with additional compatibility between Python2/3 and PyQt?4/5. It has also
been tested under python 2 with pyqt 4.11.4. Further testing under
different python/pyqt environments would be welcomed.

An enhancement to the "About" dialog is also included which adds version
strings and updates the copyright year range.

The patch was submitted to the ffado-devel mailing list.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libffado/support/mixer-qt4/ffado/ffadowindow.py

    r2701 r2726  
    2323# 
    2424 
     25import ctypes 
     26import datetime 
    2527import os 
    2628 
     
    9395 
    9496            if (ffado_python3 and (self.style().objectName().lower() == theme.lower()) or 
    95                     not(ffado_python3) and (self.style().objectName().toLower() == theme.toLower())): 
     97                    not(ffado_python3) and (self.style().objectName().toLower() == theme.toLower() if ffado_pyqt_version == 4 else 
     98                                            self.style().objectName().lower() == theme.lower())): 
    9699                self.menuTheme[theme].setDisabled(True) 
    97100                self.menuTheme[theme].setChecked(True) 
     
    175178<h1>ffado.org</h1> 
    176179 
     180<p>{ffado_version}</p> 
     181 
    177182<p>FFADO is the new approach to have firewire audio on linux.</p> 
    178183 
    179 <p>&copy; 2006-2014 by the FFADO developers<br />ffado is licensed under the GPLv3, for the full license text see <a href="http://www.gnu.org/licenses/">www.gnu.org/licenses</a> or the LICENSE.* files shipped with ffado.</p> 
     184        <p>&copy; 2006-2018 by the FFADO developers<br />ffado is licensed under the GPLv3, for the full license text see <a href="http://www.gnu.org/licenses/">www.gnu.org/licenses</a> or the LICENSE.* files shipped with ffado.</p> 
    180185 
    181186<p>FFADO developers are:<ul> 
     
    192197<li>Jano Svitok 
    193198</ul> 
    194 """ ) 
    195  
     199        """.format(ffado_version=get_ffado_version(), thisyear=datetime.datetime.now().year)) 
     200 
     201def get_ffado_version(): 
     202    try: 
     203        # call the C function ffado_get_version() to figure out the version 
     204        lib = ctypes.cdll.LoadLibrary('libffado.so') 
     205        func = ctypes.CFUNCTYPE(ctypes.c_char_p) 
     206        ffado_get_version = func(('ffado_get_version', lib)) 
     207        return ffado_get_version() 
     208    except: 
     209        return "libffado" 
    196210 
    197211def get_lock(process_name): 
     
    253267 
    254268    log = logging.getLogger('main') 
     269    log.debug("Using %s with Qt: %s PyQt: %s" % (get_ffado_version(), QtCore.QT_VERSION_STR, QtCore.PYQT_VERSION_STR)) 
    255270 
    256271    app = QApplication(args) 
  • trunk/libffado/support/mixer-qt4/ffado/logginghandler.py

    r2694 r2726  
    2929 
    3030class QStatusLogger( QObject, logging.Handler ): 
    31     log = pyqtSignal(QString, int, name='log') 
     31    log = pyqtSignal(QString if ffado_pyqt_version == 4 else str, int, name='log') 
    3232    def __init__( self, parent, statusbar, level=logging.NOTSET ): 
    3333        QObject.__init__( self, parent ) 
  • trunk/libffado/support/mixer-qt4/ffado/panelmanager.py

    r2702 r2726  
    379379        # Extract the action data and store as a dbus.String type so  
    380380        # it is usable as a key into self.panels[]. 
    381         panel_key = dbus.String(action.data().toString()
     381        panel_key = dbus.String(action.data().toString() if ffado_pyqt_version == 4 else action.data()
    382382        self.tabs.setCurrentIndex(self.tabs.indexOf(self.panels[panel_key])) 
    383383 
     
    516516        # file saving 
    517517        savefilename = QFileDialog.getSaveFileName(self, 'Save File', os.getenv('HOME')) 
     518        if isinstance(savefilename, tuple): # newer PyQt5 
     519            savefilename = savefilename[0] 
    518520        try: 
    519521          f = open(savefilename, 'w') 
     
    527529    def readSettings(self): 
    528530        readfilename = QFileDialog.getOpenFileName(self, 'Open File', os.getenv('HOME')) 
     531        if isinstance(readfilename, tuple): # newer PyQt5 
     532            readfilename = readfilename[0] 
    529533        try: 
    530534          f = open(readfilename, 'r') 
  • trunk/libffado/support/mixer-qt4/ffado/widgets/crossbarrouter.py

    r2694 r2726  
    169169        self.timer.timeout.connect(self.updateLevels) 
    170170 
    171         self.vubtn.setChecked(self.settings.value("crossbarrouter/runvu", False).toBool()) 
     171        if ffado_pyqt_version == 4: 
     172            self.vubtn.setChecked(self.settings.value("crossbarrouter/runvu", False).toBool()) 
     173        else: 
     174            self.vubtn.setChecked(self.settings.value("crossbarrouter/runvu", False) == u'true') 
    172175 
    173176    def __del__(self): 
  • trunk/libffado/support/mixer-qt4/ffado/widgets/matrixmixer.py

    r2699 r2726  
    201201    def mousePressEvent(self, ev): 
    202202        if ev.buttons() & Qt.LeftButton: 
    203             self.pos = ev.posF() 
     203            self.pos = ev.posF() if ffado_pyqt_version == 4 else ev.localPos() 
    204204            self.tmpvalue = self.value() 
    205205            ev.accept() 
     
    208208    def mouseMoveEvent(self, ev): 
    209209        if hasattr(self, "tmpvalue") and self.pos is not QtCore.QPointF(0, 0): 
    210             newpos = ev.posF() 
     210            newpos = ev.posF() if ffado_pyqt_version == 4 else ev.localPos() 
    211211            change = newpos.y() - self.pos.y() 
    212212            #log.debug("MixerNode.mouseReleaseEvent() change %s" % (str(change))) 
     
    216216    def mouseReleaseEvent(self, ev): 
    217217        if hasattr(self, "tmpvalue") and self.pos is not QtCore.QPointF(0, 0): 
    218             newpos = ev.posF() 
     218            newpos = ev.posF() if ffado_pyqt_version == 4 else ev.localPos() 
    219219            change = newpos.y() - self.pos.y() 
    220220            #log.debug("MixerNode.mouseReleaseEvent() change %s" % (str(change))) 
     
    258258            symb_inf = u"\u221E" 
    259259            text = "-" + symb_inf + " dB" 
    260         if ffado_python3
     260        if ffado_python3 or ffado_pyqt_version == 5
    261261            # Python3 uses native python UTF strings rather than QString. 
    262262            # This therefore appears to be the correct way to display this 
     
    264264            p.drawText(rect, Qt.AlignCenter, text) 
    265265        else: 
    266             p.drawText(rect, Qt.AlignCenter, QtCore.QString.fromUtf8(text)) 
     266            p.drawText(rect, Qt.AlignCenter, QString.fromUtf8(text)) 
    267267        if (self.inv_action!=None and self.inv_action.isChecked()): 
    268             if ffado_python3
     268            if ffado_python3 or ffado_pyqt_version == 5
    269269                # Refer to the comment about about Python UTF8 strings. 
    270270                p.drawText(rect, Qt.AlignLeft|Qt.AlignTop, " ϕ") 
    271271            else: 
    272                 p.drawText(rect, Qt.AlignLeft|Qt.AlignTop, QtCore.QString.fromUtf8(" ϕ")) 
     272                p.drawText(rect, Qt.AlignLeft|Qt.AlignTop, QString.fromUtf8(" ϕ")) 
    273273 
    274274    def internalValueChanged(self, value):