Changeset 1434

Show
Ignore:
Timestamp:
11/16/08 13:09:22 (15 years ago)
Author:
arnonym
Message:

Make the PanelManager? a QWidget again.

Instead we introduce a new FFADOWindow that is the mainwindow. And we have this window appear before we try to connect to dbus which should make the look and feel a bit more consistent for non-console users. And the retry-question is not asked via QMessageBox anymore but with an in-gui widget. Which also obsoletes some predefined loops for retry...

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/libffado-2.0/support/mixer-qt4/ffado-mixer.in

    r1415 r1434  
    3737import time 
    3838 
    39 from PyQt4.QtCore import SIGNAL, SLOT, QObject, QTimer 
    40 from PyQt4.QtGui import QApplication, QMessageBox, QIcon 
     39from PyQt4.QtCore import SIGNAL, SLOT, QObject, QTimer, Qt 
     40from PyQt4.QtGui import * #QApplication, QMessageBox, QIcon 
    4141 
    4242from ffado_dbus_util import * 
    4343 
    4444from ffado_panelmanager import PanelManager 
     45 
     46"""Just a small helper to ask the retry-question without a blocking messagebox""" 
     47class StartDialog(QWidget): 
     48    def __init__(self, parent): 
     49        QWidget.__init__(self, parent) 
     50        self.setObjectName("Restart Dialog") 
     51        self.label = QLabel("Somehow the connection to the dbus-service of FFADO couldn't be established.\nShall we take another try?",self) 
     52        self.button = QPushButton("Retry", self) 
     53        self.layout = QGridLayout(self) 
     54        self.layout.addWidget(self.label, 0, 0, Qt.AlignCenter) 
     55        self.layout.addWidget(self.button, 1, 0, Qt.AlignCenter) 
     56 
     57 
     58class FFADOWindow(QMainWindow): 
     59    def __init__(self, parent): 
     60        QMainWindow.__init__(self, parent) 
     61 
     62        self.manager = PanelManager(self) 
     63 
     64        filemenu = self.menuBar().addMenu("File") 
     65        quitaction = QAction("Quit", self) 
     66        quitaction.setShortcut(self.tr("Ctrl+q")) 
     67        self.connect(quitaction, SIGNAL("triggered()"), self, SLOT("close()")) 
     68        filemenu.addAction(quitaction) 
     69 
     70        editmenu = self.menuBar().addMenu("Edit") 
     71        self.updateaction = QAction("Update Mixer Panels", self) 
     72        self.updateaction.setEnabled(False) 
     73        self.connect(self.updateaction, SIGNAL("triggered()"), self.manager.updatePanels) 
     74        editmenu.addAction(self.updateaction) 
     75        self.resetaction = QAction("Trigger Bus Reset", self) 
     76        self.connect(self.resetaction, SIGNAL("triggered()"), self.manager.busreset) 
     77        editmenu.addAction(self.resetaction) 
     78        self.resetaction.setEnabled(False) 
     79 
     80        helpmenu = self.menuBar().addMenu( "Help" ) 
     81        aboutaction = QAction( "About FFADO", self ) 
     82        self.connect( aboutaction, SIGNAL( "triggered()" ), self.aboutFFADO ) 
     83        helpmenu.addAction( aboutaction ) 
     84        aboutqtaction = QAction( "About Qt", self ) 
     85        self.connect( aboutqtaction, SIGNAL( "triggered()" ), qApp, SLOT( "aboutQt()" ) ) 
     86        helpmenu.addAction( aboutqtaction ) 
     87 
     88        self.statusBar().showMessage( "Initializing...", 5000 ) 
     89 
     90        QTimer.singleShot( 1, self.connectToDBUS ) 
     91 
     92    def connectToDBUS(self): 
     93        try: 
     94            self.setupDeviceManager() 
     95        except dbus.DBusException, ex: 
     96            log.error("") 
     97            log.error("") 
     98            log.error("===========================================================") 
     99            log.error("ERROR: Could not communicate with the FFADO DBus service...") 
     100            log.error("===========================================================") 
     101            log.error("") 
     102            log.error("") 
     103            if not hasattr(self,"retry"): 
     104                self.retry = StartDialog(self) 
     105                self.setCentralWidget(self.retry) 
     106                self.connect(self.retry.button, SIGNAL("clicked()"), self.tryStartDBUSServer) 
     107            self.retry.setEnabled(True) 
     108 
     109    def tryStartDBUSServer(self): 
     110        try: 
     111            self.setupDeviceManager() 
     112        except dbus.DBusException, ex: 
     113            self.retry.setEnabled(False) 
     114            os.spawnlp( os.P_NOWAIT, "ffado-dbus-server" ) 
     115            QTimer.singleShot(2000, self.connectToDBUS) 
     116 
     117    def setupDeviceManager(self): 
     118        devmgr = DeviceManagerInterface(FFADO_DBUS_SERVER, FFADO_DBUS_BASEPATH) 
     119        nbDevices = devmgr.getNbDevices() 
     120        self.manager.setManager(devmgr) 
     121        self.setCentralWidget(self.manager) 
     122        self.updateaction.setEnabled(True) 
     123        self.resetaction.setEnabled(True) 
     124 
     125    def aboutFFADO(self): 
     126        QMessageBox.about( self, "About FFADO", """ 
     127<h1>ffado.org</h1> 
     128 
     129<p>FFADO is the new approach to have firewire audio on linux.</p> 
     130 
     131<p>&copy; 2006-2008 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> 
     132 
     133<p>FFADO developers are:<ul> 
     134<li>Pieter Palmers 
     135<li>Daniel Wagner 
     136<li>Jonathan Woithe 
     137<li>Arnold Krille 
     138</ul> 
     139""" ) 
     140 
    45141 
    46142if __name__ == "__main__": 
     
    78174    app.setWindowIcon( QIcon( SHAREDIR + "/icons/hi64-apps-ffado.png" ) ) 
    79175 
    80     msg = QMessageBox() 
    81176 
    82     repeat = 1 
    83     while repeat > 0: 
    84         try: 
    85             devmgr = DeviceManagerInterface(FFADO_DBUS_SERVER, FFADO_DBUS_BASEPATH) 
    86             nbDevices = devmgr.getNbDevices() 
    87             repeat -= 1 
    88         except dbus.DBusException, ex: 
    89             log.error("") 
    90             log.error("") 
    91             log.error("===========================================================") 
    92             log.error("ERROR: Could not communicate with the FFADO DBus service...") 
    93             log.error("===========================================================") 
    94             log.error("") 
    95             log.error("") 
    96             tmp = msg.question( msg, "FFADO-DBus not found", "<qt><b>The connection to FFADOs DBus service could not be established.</b><p>Probably you didn't start the ffado-dbus-server. Should I try this now?</qt>", QMessageBox.Yes, QMessageBox.No ) 
    97             if tmp == QMessageBox.No: 
    98                 sys.exit(-1) 
    99             else: 
    100                 os.spawnlp( os.P_NOWAIT, "ffado-dbus-server" ) 
    101                 nb_checks = 20 
    102                 while nb_checks > 0: 
    103                     nb_checks = nb_checks - 1 
    104                     try: 
    105                         devmgr = DeviceManagerInterface(FFADO_DBUS_SERVER, FFADO_DBUS_BASEPATH) 
    106                         nbDevices = devmgr.getNbDevices() 
    107                         nb_checks = 0 
    108                         repeat = 0 
    109                     except dbus.DBusException, ex: 
    110                         time.sleep( 1 ) 
     177    mainwindow = FFADOWindow(None) 
    111178 
    112     manager = PanelManager(None, devmgr) 
    113  
    114     # create a timer to poll the panels 
    115     polltimer = QTimer() 
    116     QObject.connect( polltimer, SIGNAL('timeout()'), manager.pollPanels ) 
    117     polltimer.start( POLL_SLEEP_TIME_MSEC ) 
    118  
    119     # create a timer to initialize the panel after the main form is shown 
    120     # since initialization can take a while 
    121     showtimer = QTimer() 
    122     QObject.connect( showtimer, SIGNAL('timeout()'), manager.updatePanels ) 
    123     showtimer.setSingleShot(True) 
    124     showtimer.start( POLL_SLEEP_TIME_MSEC ) 
    125179 
    126180    # rock & roll 
    127     manager.show() 
     181    mainwindow.show() 
    128182    QObject.connect(app,SIGNAL("lastWindowClosed()"),app,SLOT("quit()")) 
    129183    app.exec_() 
     184 
     185# 
     186# vim: ts=4 sw=4 et 
  • branches/libffado-2.0/support/mixer-qt4/ffado_panelmanager.py

    r1427 r1434  
    2525from ffadomixer_config import * #FFADO_VERSION, FFADO_DBUS_SERVER, FFADO_DBUS_BASEPATH 
    2626 
    27 from PyQt4.QtGui import QFrame, QWidget, QTabWidget, QVBoxLayout, QMainWindow, QIcon, QAction, qApp 
     27from PyQt4.QtGui import QFrame, QWidget, QTabWidget, QVBoxLayout, QMainWindow, QIcon, QAction, qApp, QStyleOptionTabWidgetFrame 
    2828from PyQt4.QtCore import QTimer 
    2929 
     
    7979        self.setupUi(self) 
    8080 
    81 class PanelManager(QMainWindow): 
    82     def __init__(self, parent, devmgr): 
     81class OwnTabWidget(QTabWidget): 
     82    def __init__(self,parent): 
     83        QTabWidget.__init__(self,parent) 
     84 
     85    def tabInserted(self,index): 
     86        self.checkTabBar() 
     87 
     88    def tabRemoved(self,index): 
     89        self.checkTabBar() 
     90 
     91    def checkTabBar(self): 
     92        if self.count()<2: 
     93            self.tabBar().hide() 
     94        else: 
     95            self.tabBar().show() 
     96 
     97class PanelManager(QWidget): 
     98    def __init__(self, parent, devmgr=None): 
    8399        QMainWindow.__init__(self, parent) 
     100        self.setObjectName("PanelManager") 
     101 
     102        # maps a device GUID to a QT panel 
     103        self.panels = {} 
     104 
     105        # a layout for ourselves 
     106        self.layout = QVBoxLayout(self) 
     107 
     108        # the tabs 
     109        self.tabs = OwnTabWidget(self) 
     110        self.tabs.hide() 
     111        self.layout.addWidget(self.tabs) 
     112 
     113        # a dialog that is shown during update 
     114        self.status = PanelManagerStatus(self) 
     115        self.layout.addWidget(self.status) 
     116        self.status.show() 
     117 
     118        self.devices = DeviceList( SYSTEM_CONFIG_FILE ) 
     119        self.devices.updateFromFile( USER_CONFIG_FILE ) 
     120 
     121        if devmgr is not None: 
     122            self.setManager(devmgr) 
     123 
     124    def setManager(self,devmgr): 
    84125        self.devmgr = devmgr 
    85126        self.devmgr.registerPreUpdateCallback(self.devlistPreUpdate) 
     
    87128        self.devmgr.registerUpdateCallback(self.devlistUpdate) 
    88129        self.devmgr.registerDestroyedCallback(self.devmgrDestroyed) 
    89  
    90         filemenu = self.menuBar().addMenu( "File" ) 
    91         quitaction = QAction( "Quit", self ) 
    92         quitaction.setShortcut( self.tr("Ctrl+q") ) 
    93         self.connect( quitaction, SIGNAL( "triggered()" ), self, SLOT( "close()" ) ) 
    94         filemenu.addAction( quitaction ) 
    95  
    96         editmenu = self.menuBar().addMenu( "Edit" ) 
    97         updateaction = QAction( "Update Mixer Panels", self ) 
    98         self.connect( updateaction, SIGNAL( "triggered()" ), self.updatePanels ) 
    99         editmenu.addAction( updateaction ) 
    100         resetaction = QAction( "Trigger Bus Reset", self ) 
    101         self.connect( resetaction, SIGNAL( "triggered()" ), self.busreset ) 
    102         editmenu.addAction( resetaction ) 
    103  
    104         helpmenu = self.menuBar().addMenu( "Help" ) 
    105         aboutaction = QAction( "About FFADO", self ) 
    106         self.connect( aboutaction, SIGNAL( "triggered()" ), self.aboutFFADO ) 
    107         helpmenu.addAction( aboutaction ) 
    108         aboutqtaction = QAction( "About Qt", self ) 
    109         self.connect( aboutqtaction, SIGNAL( "triggered()" ), qApp, SLOT( "aboutQt()" ) ) 
    110         helpmenu.addAction( aboutqtaction ) 
    111  
    112         self.statusBar().showMessage( "Initializing...", 5000 ) 
    113  
    114         # maps a device GUID to a QT panel 
    115         self.panels = {} 
    116  
    117         # a layout for ourselves 
    118         mw = QWidget( self ) 
    119         self.layout = QVBoxLayout( mw ) 
    120         self.setCentralWidget( mw ) 
    121  
    122         # the tabs 
    123         self.tabs = QTabWidget(mw) 
    124         self.tabs.hide() 
    125         self.layout.addWidget(self.tabs) 
    126  
    127         # a dialog that is shown during update 
    128         self.status = PanelManagerStatus(mw) 
    129         self.status.lblMessage.setText("Initializing...") 
    130         self.layout.addWidget(self.status) 
    131         self.status.show() 
     130        # create a timer to poll the panels 
     131        self.polltimer = QTimer() 
     132        self.connect( self.polltimer, SIGNAL('timeout()'), self.pollPanels ) 
     133        self.polltimer.start( POLL_SLEEP_TIME_MSEC ) 
     134 
     135        # create a timer to initialize the panel after the main form is shown 
     136        # since initialization can take a while 
     137        QTimer.singleShot( POLL_SLEEP_TIME_MSEC, self.updatePanels ) 
    132138 
    133139        # live check timer 
     
    135141        QObject.connect( self.alivetimer, SIGNAL('timeout()'), self.commCheck ) 
    136142        self.alivetimer.start( 2000 ) 
    137  
    138         self.devices = DeviceList( SYSTEM_CONFIG_FILE ) 
    139         self.devices.updateFromFile( USER_CONFIG_FILE ) 
    140143 
    141144    def count(self): 
     
    163166        self.status.lblMessage.setText("Bus reconfiguration in progress, please wait...") 
    164167        self.status.show() 
    165         self.statusBar().showMessage("bus reconfiguration in progress...", 5000) 
     168        #self.statusBar().showMessage("bus reconfiguration in progress...", 5000) 
    166169 
    167170    def devlistPostUpdate(self): 
     
    217220        log.debug("PanelManager::updatePanels()") 
    218221        nbDevices = self.devmgr.getNbDevices() 
    219         self.statusBar().showMessage("Reconfiguring the mixer panels...") 
     222        #self.statusBar().showMessage("Reconfiguring the mixer panels...") 
    220223 
    221224        # list of panels present 
     
    300303            # Generic elements for all mixers follow here: 
    301304            # 
    302             tmp = GlobalMixer( w ) 
    303             tmp.configrom = cfgrom 
    304             tmp.clockselect = clockselect 
    305             tmp.samplerateselect = samplerateselect 
    306             tmp.nickname = nickname 
    307             tmp.hw = hw 
    308             tmp.initValues() 
    309             l.addWidget( tmp, 1 ) 
     305            globalmixer = GlobalMixer( w ) 
     306            globalmixer.configrom = cfgrom 
     307            globalmixer.clockselect = clockselect 
     308            globalmixer.samplerateselect = samplerateselect 
     309            globalmixer.nickname = nickname 
     310            globalmixer.hw = hw 
     311            globalmixer.initValues() 
     312            l.addWidget( globalmixer, 1 ) 
    310313 
    311314            # 
     
    342345                title = mixerapp 
    343346 
     347            globalmixer.setName(title) 
    344348            self.tabs.addTab( w, title ) 
    345349            self.panels[guid] = w 
     
    352356            self.status.lblMessage.setText("No supported device found.") 
    353357            self.status.show() 
    354             self.statusBar().showMessage("No supported device found.", 5000) 
     358            #self.statusBar().showMessage("No supported device found.", 5000) 
    355359        else: 
    356360            self.tabs.show() 
    357361            self.tabs.setEnabled(True) 
    358362            self.status.hide() 
    359             self.statusBar().showMessage("Configured the mixer for %i devices." % self.tabs.count()) 
     363            #self.statusBar().showMessage("Configured the mixer for %i devices." % self.tabs.count()) 
    360364            if use_generic: 
    361365                # 
     
    369373        QMessageBox.information( self, "Not supported", "Triggering bus resets from the mixer (via dbus) isn't yet supported." ) 
    370374 
    371     def aboutFFADO(self): 
    372         QMessageBox.about( self, "About FFADO", """ 
    373 <h1>ffado.org</h1> 
    374  
    375 <p>FFADO is the new approach to have firewire audio on linux.</p> 
    376  
    377 <p>&copy; 2006-2008 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> 
    378  
    379 <p>FFADO developers are:<ul> 
    380 <li>Pieter Palmers 
    381 <li>Daniel Wagner 
    382 <li>Jonathan Woithe 
    383 <li>Arnold Krille 
    384 </ul> 
    385 """ ) 
     375# vim: et