Changeset 1647

Show
Ignore:
Timestamp:
08/31/09 14:35:35 (15 years ago)
Author:
arnonym
Message:

Replace the big matrix of buttons by only one button per destination and choose the source per menu. The menu is filled when first shown to reduce startup load.

This is even real working. I have successfully switched the routing here :-)

Files:

Legend:

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

    r1644 r1647  
    2222import dbus 
    2323 
     24class InGroupMenu(QtGui.QMenu): 
     25    def __init__(self, interface, outname, inname, insize, parent, exclusiveGroup = None): 
     26        QtGui.QMenu.__init__(self, inname, parent) 
     27        self.interface = interface 
     28        self.outname = str(outname) 
     29        self.inname = str(inname) 
     30        self.insize = insize 
     31        self.connect(self, QtCore.SIGNAL("aboutToShow()"), self.showMenu) 
    2432 
    25 class CrossbarState(QtGui.QAbstractButton): 
    26     def __init__(self, title, parent=None)
    27         QtGui.QAbstractButton.__init__(self, parent) 
    28         self.setText(title) 
    29         self.setToolTip(title
     33        self.lock = False 
     34        if exclusiveGroup
     35            self.exclusiveGroup = exclusiveGroup 
     36        else: 
     37            self.exclusiveGroup = QtGui.QActionGroup(self
    3038 
    31         self.setMinimumSize(QtCore.QSize(10, 10)) 
     39    def showMenu(self): 
     40        #print "About to show the menu" 
     41        if len(self.actions()) < self.insize: 
     42            # Do a lazy init of the sub-items. 
     43            for i in range(self.insize): 
     44                action = QtGui.QAction("%s:%02i" % (self.inname,i), self) 
     45                action.setCheckable(True) 
     46                self.connect(action, QtCore.SIGNAL("toggled(bool)"), self.connectionSwitched) 
     47                self.exclusiveGroup.addAction(action) 
     48                self.addAction(action) 
     49                idx = self.interface.getDestinationIndex(self.outname) 
     50                sourceidx = self.interface.getSourceForDestination(idx) 
     51                #print self.interface.getConnectionState(sourceidx, idx) 
     52                source = self.interface.getSourceName(sourceidx) 
     53                self.lock = True 
     54                for action in self.actions(): 
     55                    action.setChecked(action.text() == source) 
     56                self.lock = False 
    3257 
    33     def paintEvent(self, event): 
    34         p = QtGui.QPainter(self) 
    35         color = QtGui.QColor(0, 255, 0
    36         if self.isChecked(): 
    37             color = QtGui.QColor(255, 0, 0
    38         p.fillRect(self.rect(), color
     58    def connectionSwitched(self, checked): 
     59        if self.lock: return 
     60        print "connectionSwitched( %s ) sender: %s" % (str(checked),str(self.sender())
     61        inname = str(self.sender().text()) 
     62        print " source=%s destination=%s  possible? %s" % (inname, self.outname, self.interface.canConnectNamed(inname, self.outname)
     63        print " connectionState is now %s" % self.interface.setConnectionStateNamed(inname, self.outname, checked
    3964 
    4065 
     
    6287        for ch in self.sources: 
    6388            tmp = ch.split(":")[0] 
    64             if not tmp in self.ingroups: 
    65                 self.ingroups[tmp] = 0 
    66                 self.innames.append(tmp) 
    67             self.ingroups[tmp] = self.ingroups[tmp] + 1 
     89            if True: #tmp[0] == "M" or tmp[0] == "I": 
     90                if not tmp in self.ingroups: 
     91                    self.ingroups[tmp] = 0 
     92                    self.innames.append(tmp) 
     93                self.ingroups[tmp] = self.ingroups[tmp] + 1 
    6894        print self.ingroups 
    6995        self.outnames = [] 
     
    7197        for ch in self.destinations: 
    7298            tmp = ch.split(":")[0] 
    73             if not tmp in self.outgroups: 
    74                 self.outgroups[tmp] = 0 
    75                 self.outnames.append(tmp) 
    76             self.outgroups[tmp] = self.outgroups[tmp] + 1 
     99            if True: #tmp == "MixerIn": 
     100                if not tmp in self.outgroups: 
     101                    self.outgroups[tmp] = 0 
     102                    self.outnames.append(tmp) 
     103                self.outgroups[tmp] = self.outgroups[tmp] + 1 
    77104        print self.outgroups 
    78105 
     
    80107        self.setLayout(self.layout) 
    81108 
    82         tmp = 1 
    83         for group in self.innames: 
    84             lbl = QtGui.QLabel(group, self) 
    85             self.layout.addWidget(lbl, 0, tmp + self.innames.index(group), 1, self.ingroups[group]) 
    86             tmp += self.ingroups[group] 
    87         tmp = 1 
    88         for group in self.outnames: 
    89             lbl = QtGui.QLabel(group, self) 
    90             self.layout.addWidget(lbl, tmp + self.outnames.index(group), 0, self.outgroups[group], 1) 
    91             tmp += self.outgroups[group] 
    92         #for i in range(len(self.sources)): 
    93         #    lbl = QtGui.QLabel(self.sources[i], self) 
    94         #    self.layout.addWidget(lbl, 0, i+1) 
    95         #for i in range(len(self.destinations)): 
    96         #    lbl = QtGui.QLabel(self.destinations[i], self) 
    97         #    self.layout.addWidget(lbl, i+1, 0) 
     109        for group in self.outgroups.keys(): 
     110            for i in range(self.outgroups[group]): 
     111                outname = "%s:%02i" % (group,i) 
     112                #print "Creating buttons for %s" % outname 
     113                btn = QtGui.QPushButton("%s" % outname, self) 
     114                outidx = self.destinations.index(outname) 
     115                self.layout.addWidget(btn, i, self.outnames.index(group)) 
     116                menu = QtGui.QMenu(self) 
     117                btn.setMenu(menu) 
     118                exclusiveGroup = QtGui.QActionGroup(btn) 
     119                for x in self.ingroups: 
     120                    submenu = InGroupMenu(self.interface, outname, x, self.ingroups[x], self, exclusiveGroup) 
     121                    menu.addMenu(submenu) 
    98122 
    99         for i in range(0, min(600, len(self.sources))): 
    100             print "Checking connections for source %s" % self.sources[i] 
    101             for j in range(0, min(600, len(self.destinations))): 
    102                 if self.interface.canConnect(i, j) and self.sources[i].split(":")[0] != self.destinations[j].split(":")[0]: 
    103                     #checkbox = QtGui.QPushButton("%s->%s" % (self.sources[i], self.destinations[j]), self) 
    104                     checkbox = CrossbarState("%s->%s" % (self.sources[i], self.destinations[j]), self) 
    105                     checkbox.setCheckable(True) 
    106                     checkbox.setChecked(self.interface.getConnectionState(i, j)) 
    107                     #self.layout.addWidget(checkbox, j, i) 
    108                     self.layout.addWidget(checkbox, j+1, i+1) 
    109123# 
    110124# vim: sw=4 ts=4 et