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

Revision 2694, 3.7 kB (checked in by jwoithe, 7 years ago)

ffado-mixer: Centralise imports of PyQt? modules and make compatible with PyQt?5.

In Xavier Forestier's patch set submitted to ffado-devel in November 2016,
changes were required to every PyQt? import statement if PyQt?5 were to to be
used instead. Since the current intent is to retain compatiblity to both
PyQt?4 and PyQt?5 a slightly different approach was needed.

All PyQt? module imports are now handled by the newly added import_pyqt
module. This transparently loads PyQt?4 or PyQt?5 modules depending on what
is found on the system at runtime. Presently PyQt?4 is tried first with a
fallback to PyQt?5 if PyQt?4 is not found, but this could change in future.
The result is that the ffado-mixer code should now be very close to being
compatible with PyQt?5 without additional patches. Having said that, some
build system changes are still needed to make PyQt?5 an option, along with
some other minor fixes.

This is perhaps not the neatest way of achieving the desired result, but it
seems to work. It avoids the need to patch every ffado-mixer source file
depending on the PyQt? version in use, and allows ffado-mixer to adapt to the
PyQt? version found at runtime.

The import_pyqt module also sets two global version variables:
ffado_pyqt_version (the version of PyQt? in use) and ffado_python3 (true if
python3 is in use). These may be of use when addressing remaining
PtQt?4/PyQt5 and Python 2/3 issues.

This patch has been tested with PyQt?4 under Python 2.7.

Line 
1 #
2 # Copyright (C) 2009-2010 by Arnold Krille
3 #
4 # This file is part of FFADO
5 # FFADO = Free Firewire (pro-)audio drivers for linux
6 #
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 2 of the License, or
10 # (at your option) version 3 of the License.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20
21 # from PyQt4 import QtGui, QtCore, Qt
22 # from PyQt4.QtGui import QWidget, QScrollArea
23 from ffado.import_pyqt import *
24
25 import dbus
26
27 import ffado.config
28 from ffado.widgets.matrixmixer import MatrixMixer
29 from ffado.widgets.crossbarrouter import *
30 from ffado.mixer.generic_dice_eap import *
31
32 from ffado.config import *
33
34 class BooleanControl:
35     def __init__(self, hw, path):
36         if ffado.config.bypassdbus:
37             self.value = False
38             return
39         self.iface = dbus.Interface(
40                 hw.bus.get_object(hw.servername, path),
41                 dbus_interface="org.ffado.Control.Element.Boolean")
42         self.value = self.iface.selected()
43
44     def selected(self):
45         return self.value
46
47     def select(self, n):
48         if self.iface.select(n):
49             self.value = n
50             return True
51         return False
52
53 class DiscreteControl:
54     def __init__(self, hw, path):
55         if ffado.config.bypassdbus:
56             self.value = 0
57             return
58         self.iface = dbus.Interface(
59                 hw.bus.get_object(hw.servername, path),
60                 dbus_interface="org.ffado.Control.Element.Discrete")
61         self.value = self.iface.getValue()
62
63     def getvalue(self):
64         return self.value
65
66     def setvalue(self, v):
67         if v != self.value:
68             self.iface.setValue(v)
69             self.value = v
70
71 class Profire2626(Generic_Dice_EAP):
72     def __init__(self, parent=None):
73         Generic_Dice_EAP.__init__(self, parent)
74
75     def buildMixer(self):
76         #print( self.hw )
77         #print( self.hw.getText("/Generic/Nickname") )
78         Generic_Dice_EAP.buildMixer(self)
79
80         widget = QWidget()
81         uicLoad("ffado/mixer/profire2626_settings.ui", widget)
82
83         # Add Settings to ffado-mixer panels
84         scrollarea = QScrollArea(self.tabs)
85         scrollarea.setWidgetResizable(False)
86         scrollarea.setWidget(widget)
87         self.tabs.addTab(scrollarea, "Settings")
88
89         # Master volume knob
90         from collections import namedtuple
91         LineInfo = namedtuple('LineInfo', ['widget','Interface'])
92
93         # Volume Unactivating
94         self.LineUnActivates = []
95         p = LineInfo(widget.line1line2, BooleanControl(self.hw, self.hw.basepath+"/EAP/Settings/VolumeKnob/Line1Line2"))
96         self.LineUnActivates.append(p)
97         p = LineInfo(widget.line3line4, BooleanControl(self.hw, self.hw.basepath+"/EAP/Settings/VolumeKnob/Line3Line4"))
98         self.LineUnActivates.append(p)
99         p = LineInfo(widget.line5line6, BooleanControl(self.hw, self.hw.basepath+"/EAP/Settings/VolumeKnob/Line5Line6"))
100         self.LineUnActivates.append(p)
101         p = LineInfo(widget.line7line8, BooleanControl(self.hw, self.hw.basepath+"/EAP/Settings/VolumeKnob/Line7Line8"))
102         self.LineUnActivates.append(p)
103
104         for l in self.LineUnActivates:
105             l.widget.setChecked(l.Interface.selected())
106             l.widget.toggled.connect(l.Interface.select)
107
108     def getDisplayTitle(self):
109         return "M-Audio Profire 2626 Mixer"
110
111 #
112 # vim: et ts=4 sw=4
Note: See TracBrowser for help on using the browser.