Changeset 1739

Show
Ignore:
Timestamp:
12/01/09 13:16:07 (11 years ago)
Author:
arnonym
Message:

Reducing the number of lines while maintaining the functionality is good. Improving the gui is even better :-)

Files:

Legend:

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

    r1707 r1739  
    6969        self.interface = interface 
    7070        self.outname = outname 
     71        self.lastin = "" 
    7172 
    7273        self.setLineWidth(1) 
     
    8081 
    8182        self.vu = VuMeter(self.interface, self.interface.getDestinationIndex(outname), parent=self) 
    82         self.layout.addWidget(self.vu, 0, 1, 2, 1) 
    83  
    84         self.btn = QtGui.QPushButton("Sel.", self) 
    85         self.layout.addWidget(self.btn, 1, 0) 
    86  
    87         self.exclusiveGroup = QtGui.QActionGroup(self) 
     83        self.layout.addWidget(self.vu, 0, 1) 
    8884 
    8985        sources = self.interface.getSourceNames() 
    90         self.ingroups = {} 
    91         for ch in sources: 
    92             tmp = str(ch).split(":")[0] 
    93             if tmp not in self.ingroups: 
    94                 self.ingroups[tmp] = 0 
    95             self.ingroups[tmp] += 1 
    96         #log.debug("Detected ingroups: %s" % str(self.ingroups)) 
    9786 
    98         self.menu = QtGui.QMenu(self) 
    99         self.btn.setMenu(self.menu) 
     87        self.combo = QtGui.QComboBox(self) 
     88        self.layout.addWidget(self.combo, 1, 0, 1, 2) 
     89        self.combo.addItem("Disconnected") 
     90        self.combo.addItems(sources) 
     91        idx = self.interface.getDestinationIndex(self.outname) 
     92        sourceidx = self.interface.getSourceForDestination(idx) 
     93        if sourceidx > -1: 
     94            source = self.interface.getSourceName(sourceidx) 
     95            self.combo.setCurrentIndex(sources.index(source)+1) 
     96        self.connect(self.combo, QtCore.SIGNAL("activated(QString)"), self.comboCurrentChanged) 
    10097 
    101         action = QtGui.QAction("Disconnect", self) 
    102         action.setCheckable(True) 
    103         self.connect(action, QtCore.SIGNAL("toggled(bool)"), self.disconnectRoute) 
    104         self.exclusiveGroup.addAction(action) 
    105         self.menu.addAction(action) 
    106  
    107         for group in self.ingroups: 
    108             submenu = InGroupMenu(self.interface, self.outname, group, self.ingroups[group], self, self.exclusiveGroup) 
    109             self.menu.addMenu(submenu) 
    11098 
    11199    def peakValue(self, value): 
    112100        self.vu.updateLevel(value) 
    113101 
    114     def disconnectRoute(self, checked): 
    115         log.debug("disconnectRoute( %s )" % str(checked)) 
    116         dest = self.interface.getDestinationIndex(self.outname) 
    117         src = self.interface.getSourceName( self.interface.getSourceForDestination( dest ) ) 
    118         #log.debug(" source=%s destination=%s  possible? %s" % (src, self.outname, self.interface.canConnectNamed(src, self.outname))) 
    119         if self.interface.setConnectionStateNamed(src, self.outname, False): 
    120             log.warning(" Failed to change the connection table!") 
    121         self.peakValue(0) 
     102    def comboCurrentChanged(self, inname): 
     103        #log.debug("comboCurrentChanged( %s )" % inname) 
     104        if inname == self.lastin: 
     105            return 
     106        if self.lastin != "": 
     107            self.interface.setConnectionStateNamed(self.lastin, self.outname, False) 
    122108 
    123 class InGroupMenu(QtGui.QMenu): 
    124     def __init__(self, interface, outname, inname, insize, parent, exclusiveGroup = None): 
    125         QtGui.QMenu.__init__(self, inname, parent) 
    126         self.interface = interface 
    127         self.outname = str(outname) 
    128         self.inname = str(inname) 
    129         self.insize = insize 
    130         self.connect(self, QtCore.SIGNAL("aboutToShow()"), self.showMenu) 
    131  
    132         self.lock = False 
    133         if exclusiveGroup: 
    134             self.exclusiveGroup = exclusiveGroup 
     109        if inname != "Disconnected": 
     110            if self.interface.setConnectionStateNamed(str(inname), self.outname, True): 
     111                self.lastin = str(inname) 
     112            else: 
     113                log.warning(" Failed to connect %s to %s" % (inname, self.outname)) 
    135114        else: 
    136             self.exclusiveGroup = QtGui.QActionGroup(self) 
    137  
    138     def showMenu(self): 
    139         #print "About to show the menu" 
    140         if len(self.actions()) < self.insize+1: 
    141             # Do a lazy init of the sub-items. 
    142             for i in range(self.insize): 
    143                 action = QtGui.QAction("%s:%02i" % (self.inname,i), self) 
    144                 action.setCheckable(True) 
    145                 self.connect(action, QtCore.SIGNAL("toggled(bool)"), self.connectionSwitched) 
    146                 self.exclusiveGroup.addAction(action) 
    147                 self.addAction(action) 
    148                 idx = self.interface.getDestinationIndex(self.outname) 
    149                 sourceidx = self.interface.getSourceForDestination(idx) 
    150                 source = self.interface.getSourceName(sourceidx) 
    151                 self.lock = True 
    152                 for action in self.actions(): 
    153                     action.setChecked(action.text() == source) 
    154                 self.lock = False 
    155  
    156     def connectionSwitched(self, checked): 
    157         if self.lock: return 
    158         #log.debug("connectionSwitched( %s ) sender: %s" % (str(checked),str(self.sender()))) 
    159         inname = str(self.sender().text()) 
    160         #log.debug(" source=%s destination=%s  possible? %s" % (inname, self.outname, self.interface.canConnectNamed(inname, self.outname))) 
    161         if not self.interface.setConnectionStateNamed(inname, self.outname, checked): 
    162             log.warning(" Failed to change the routing.") 
     115            self.lastin = "" 
    163116 
    164117