2 # -*- coding: utf-8 -*-
6 from PyQt4
.QtCore
import Qt
, QRectF
7 from PyQt4
.QtGui
import QColor
, QGraphicsItem
, QGraphicsRectItem
, QGraphicsTextItem
, QGraphicsScene
, QPen
8 from PyQt4
.QtGui
import QFont
, QFontMetrics
12 class AudioTestBox(QGraphicsItem
):
13 def __init__(self
, p_min
, p_mout
, p_ain
, p_aout
, name
):
14 QGraphicsItem
.__init
__(self
)
21 self
.max_out_size
= 50
22 self
.box_font
= QFont("Deja Vu Sans", 8, QFont
.Normal
)
24 # Make the App Name fit the Box
25 app_name_size
= QFontMetrics(self
.box_font
).width(name
)
26 if (app_name_size
> self
.box_width
-10):
27 self
.box_width
= app_name_size
29 # Get Max Midi Name size
35 for i
in range(len(p_sel
)):
37 if (len(p_sel
) <= len(p_min
)):
38 size
+= QFontMetrics(self
.box_font
).width(p_min
[i
])
39 if (len(p_sel
) <= len(p_mout
)):
40 size
+= QFontMetrics(self
.box_font
).width(p_mout
[i
])
41 if (size
> self
.max_p_size
):
42 self
.max_p_size
= size
44 # Get Max Audio Name size
50 for i
in range(len(p_sel
)):
52 if (len(p_sel
) <= len(p_ain
)):
53 size
+= QFontMetrics(self
.box_font
).width(p_ain
[i
])
54 if (len(p_sel
) <= len(p_aout
)):
55 size
+= QFontMetrics(self
.box_font
).width(p_aout
[i
])
56 if (size
> self
.max_p_size
):
57 self
.max_p_size
= size
59 # Grow Box horizontally if needed
60 if (self
.max_p_size
> self
.box_width
-10):
61 self
.box_width
= self
.max_p_size
63 # Grow Box vertically to fit all inputs
65 for i
in range(len(p_min
)+len(p_ain
)):
68 if (new_box_height
> self
.box_height
):
69 self
.box_height
= new_box_height
71 # Grow Box vertically to fit all outputs
73 for i
in range(len(p_mout
)+len(p_aout
)):
76 if (new_box_height
> self
.box_height
):
77 self
.box_height
= new_box_height
80 self
.box
= QGraphicsRectItem(0, 0, self
.box_width
+10, self
.box_height
, self
)
81 self
.box
.setBrush(QColor(10, 11, 12))
82 self
.box
.setPen(QPen(Qt
.white
, 0))
85 self
.app_name
= QGraphicsTextItem(name
, self
.box
)
86 self
.app_name
.setFont(self
.box_font
)
88 # Get Max Midi Input Name size
89 for i
in range(len(p_min
)):
90 size
= QFontMetrics(self
.box_font
).width(p_min
[i
])
91 if (size
> self
.max_in_size
):
92 self
.max_in_size
= size
94 # Get Max Midi Output Name size
95 for i
in range(len(p_mout
)):
96 size
= QFontMetrics(self
.box_font
).width(p_mout
[i
])
97 if (size
> self
.max_out_size
):
98 self
.max_out_size
= size
100 # Get Max Audio Input Name size
101 for i
in range(len(p_ain
)):
102 size
= QFontMetrics(self
.box_font
).width(p_ain
[i
])
103 if (size
> self
.max_in_size
):
104 self
.max_in_size
= size
106 # Get Max Audio Output Name size
107 for i
in range(len(p_aout
)):
108 size
= QFontMetrics(self
.box_font
).width(p_aout
[i
])
109 if (size
> self
.max_out_size
):
110 self
.max_out_size
= size
114 for i
in range(len(p_ain
)):
115 self
.tmp_box
= QGraphicsRectItem(0, last_pos
, self
.max_in_size
+5, 15, self
.box
)
116 self
.tmp_box
.setBrush(Qt
.blue
)
117 self
.tmp_box
.setPen(QPen(Qt
.darkBlue
, 0))
118 self
.tmp_txt
= QGraphicsTextItem(p_ain
[i
], self
.box
)
119 self
.tmp_txt
.setFont(self
.box_font
)
120 self
.tmp_txt
.setPos(0, last_pos
-3)
123 for i
in range(len(p_min
)):
124 self
.tmp_box
= QGraphicsRectItem(0, last_pos
, self
.max_in_size
+5, 15, self
.box
)
125 self
.tmp_box
.setBrush(Qt
.red
)
126 self
.tmp_box
.setPen(QPen(Qt
.darkRed
, 0))
127 self
.tmp_txt
= QGraphicsTextItem(p_min
[i
], self
.box
)
128 self
.tmp_txt
.setFont(self
.box_font
)
129 self
.tmp_txt
.setPos(0, last_pos
-3)
134 for i
in range(len(p_aout
)):
135 self
.tmp_box
= QGraphicsRectItem(self
.box_width
-self
.max_out_size
+5, last_pos
, self
.max_out_size
+5, 15, self
.box
)
136 self
.tmp_box
.setBrush(Qt
.blue
)
137 self
.tmp_box
.setPen(QPen(Qt
.darkBlue
, 0))
138 self
.tmp_txt
= QGraphicsTextItem(p_aout
[i
], self
.box
)
139 self
.tmp_txt
.setFont(self
.box_font
)
140 self
.tmp_txt
.setPos(self
.box_width
-self
.max_out_size
+3, last_pos
-3)
143 for i
in range(len(p_mout
)):
144 self
.tmp_box
= QGraphicsRectItem(self
.box_width
-self
.max_out_size
+5, last_pos
, self
.max_out_size
+5, 15, self
.box
)
145 self
.tmp_box
.setBrush(Qt
.red
)
146 self
.tmp_box
.setPen(QPen(Qt
.darkRed
, 0))
147 self
.tmp_txt
= QGraphicsTextItem(p_mout
[i
], self
.box
)
148 self
.tmp_txt
.setFont(self
.box_font
)
149 self
.tmp_txt
.setPos(self
.box_width
-self
.max_out_size
+3, last_pos
-3)
153 self
.box
.setZValue(-1)
154 self
.box
.setFlag(QGraphicsItem
.ItemIsMovable
)
156 def boundingRect(self
):
157 return QRectF(0, 0, 0, 0)
159 def paint(self
, painter
, option
, widget
):