From 99970719729eb04d326ed0ac35d8c5712b24cb27 Mon Sep 17 00:00:00 2001 From: falkTX Date: Fri, 6 Aug 2010 15:56:46 +0100 Subject: [PATCH] Start working on 2d canvas patchbay --- src/qpatchbay.py | 77 +++++++++++++++++++++++++++++++++------------------ src/tb_connections.py | 4 +-- 2 files changed, 52 insertions(+), 29 deletions(-) diff --git a/src/qpatchbay.py b/src/qpatchbay.py index 53fa89d..c95ef9f 100755 --- a/src/qpatchbay.py +++ b/src/qpatchbay.py @@ -3,39 +3,62 @@ # Imports -from PyQt4.QtCore import Qt -from PyQt4.QtGui import QGraphicsItem, QGraphicsRectItem, QGraphicsScene, QPen +from PyQt4.QtCore import Qt, QRectF +from PyQt4.QtGui import QGraphicsItem, QGraphicsRectItem, QGraphicsTextItem, QGraphicsScene, QPen +from PyQt4.QtGui import QFont, QFontMetrics # Testing Box -class AudioTestBox(QGraphicsRectItem): - def __init__(self, *args): - QGraphicsRectItem.__init__(self, *args) +class AudioTestBox(QGraphicsItem): + def __init__(self, p_min, p_mout, p_ain, p_aout, name): + QGraphicsItem.__init__(self) - self.setRect(0, 0, 150, 100) - self.setFlag(QGraphicsItem.ItemIsMovable) + box_width = 50 + box_height = 50 + box_font = QFont("Deja Vu Sans", 8, QFont.Normal) + + app_name_size = QFontMetrics(box_font).width(name) + if (app_name_size > box_width-10): + box_width = app_name_size + + self.box = QGraphicsRectItem(0, 0, box_width+10, box_height, self) + self.box.setBrush(Qt.blue) + + self.app_name = QGraphicsTextItem(name, self.box) + self.app_name.setFont(box_font) + + self.small_boxes = [] + for i in range(p_aout): + count_helper = 0 + self.tmp_box = QGraphicsRectItem(0, 20+((i+1)*15)+(i*5), 60, 15, self.box) + self.tmp_box.setBrush(Qt.yellow) + self.small_boxes.append(self.tmp_box) + + self.box.setZValue(-1) + self.box.setFlag(QGraphicsItem.ItemIsMovable) def paint(self, painter, option, widget): - painter.setPen(QPen(Qt.white, 0)) - painter.drawText(10, 20, "Example App") - - painter.setPen(QPen(Qt.blue, 0)) - painter.setBrush(Qt.red) - painter.drawRect(0, 45, 60, 20) - painter.setPen(QPen(Qt.black, 0)) - painter.drawText(10, 60, "midi_in") - - painter.setPen(QPen(Qt.blue, 0)) - painter.setBrush(Qt.blue) - painter.drawRect(90, 45, 60, 20) - painter.setPen(QPen(Qt.black, 0)) - painter.drawText(100, 60, "out_1") - - painter.setPen(QPen(Qt.blue, 0)) - painter.setBrush(Qt.blue) - painter.drawRect(90, 70, 60, 20) - painter.setPen(QPen(Qt.black, 0)) - painter.drawText(100, 85, "out_2") + pass + #painter.setPen(QPen(Qt.white, 0)) + #painter.drawText(10, 20, "Example App") + + #painter.setPen(QPen(Qt.blue, 0)) + #painter.setBrush(Qt.red) + #painter.drawRect(0, 45, 60, 20) + #painter.setPen(QPen(Qt.black, 0)) + #painter.drawText(10, 60, "midi_in") + + #painter.setPen(QPen(Qt.blue, 0)) + #painter.setBrush(Qt.blue) + #painter.drawRect(90, 45, 60, 20) + #painter.setPen(QPen(Qt.black, 0)) + #painter.drawText(100, 60, "out_1") + + #painter.setPen(QPen(Qt.blue, 0)) + #painter.setBrush(Qt.blue) + #painter.drawRect(90, 70, 60, 20) + #painter.setPen(QPen(Qt.black, 0)) + #painter.drawText(100, 85, "out_2") #from PyQt4.QtGui import QRadialGradient, QPen, QBrush, QColor #gradient = QRadialGradient(-3, -3, 10) diff --git a/src/tb_connections.py b/src/tb_connections.py index 7a49c27..e7136df 100755 --- a/src/tb_connections.py +++ b/src/tb_connections.py @@ -42,10 +42,10 @@ class ConnectionsW(QWidget, ui_tb_connections.Ui_ConnectionsW): self.b_disconnect_all.setEnabled(False) self.patchbay = QGraphicsScene(self) - self.patchbay.setBackgroundBrush(Qt.black) + self.patchbay.setBackgroundBrush(Qt.green) self.graph.setScene(self.patchbay) - self.patchbay.addItem(qpatchbay.AudioTestBox()) + self.patchbay.addItem(qpatchbay.AudioTestBox(0, 0, 0, 5, "Test App 1")) self.enabledAudio = [0, 0] self.enabledMIDI = [0, 0] -- 2.11.4.GIT