| 24 | class 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) |
---|
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 |
---|
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) |
---|
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) |
---|
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) |
---|