class SpinBoxImageView(QHBoxLayout): valueChanged = pyqtSignal(int) def __init__(self, parentView, backgroundColor, foregroundColor, value, height, fontSize): QHBoxLayout.__init__(self) self.backgroundColor = backgroundColor self.foregroundColor = foregroundColor self.labelLayout = QVBoxLayout() self.upLabel = LabelButtons('spin-up', parentView, backgroundColor, foregroundColor, height/2, height/2) self.labelLayout.addWidget(self.upLabel) self.upLabel.clicked.connect(self.on_upLabel) self.downLabel = LabelButtons('spin-down', parentView, backgroundColor, foregroundColor, height/2, height/2) self.labelLayout.addWidget(self.downLabel) self.downLabel.clicked.connect(self.on_downLabel) self.addLayout(self.labelLayout) self.spinBox = QSpinBox() self.spinBox.valueChanged.connect(self.spinBoxValueChanged) self.addWidget(self.spinBox) self.spinBox.setToolTip("Spinbox") self.spinBox.setButtonSymbols(QAbstractSpinBox.NoButtons) self.spinBox.setAlignment(Qt.AlignRight) self.spinBox.setMaximum(value) self.spinBox.setMaximumHeight(height) self.spinBox.setSuffix("/" + str(value)) font = self.spinBox.font() font.setPixelSize(fontSize) self.spinBox.setFont(font) self.do_draw() def do_draw(self): r, g, b, a = self.foregroundColor.getRgb() rgb = "rgb({0},{1},{2})".format(r, g, b) sheet = TEMPLATE.format(rgb, self.backgroundColor.name()) self.spinBox.setStyleSheet(sheet) def spinBoxValueChanged(self, value): self.valueChanged.emit(value) def setValue(self, value): self.spinBox.setValue(value) def setNewValue(self, value): self.spinBox.setMaximum(value) self.spinBox.setSuffix("/" + str(value)) def on_upLabel(self): self.spinBox.setValue(self.spinBox.value() + 1) def on_downLabel(self): self.spinBox.setValue(self.spinBox.value() - 1)
def addSpinBox(self, attribute_name, title, tool_tip=None, min_value=1, max_value=10, single_step=1): sb = QSpinBox() self[attribute_name] = sb sb.setMaximumHeight(25) sb_layout = QHBoxLayout() sb_layout.addWidget(sb) sb_layout.addStretch() self.addRow(title, sb_layout) if tool_tip is not None: sb.setToolTip(tool_tip) sb.setMinimum(min_value) sb.setMaximum(max_value) sb.setSingleStep(single_step) def getter(self): return self[attribute_name].value() def setter(self, value): self[attribute_name].setValue(value) self.updateProperty(attribute_name, getter, setter) return sb
class SpinBoxImageView(QHBoxLayout): valueChanged = pyqtSignal(int) def __init__(self, backgroundColor, foregroundColor, value, height, fontSize): QHBoxLayout.__init__(self) self.backgroundColor = backgroundColor self.foregroundColor = foregroundColor self.labelLayout = QVBoxLayout() self.upLabel = LabelButtons(backgroundColor, foregroundColor, height/2, height/2) self.labelLayout.addWidget(self.upLabel) self.upLabel.setSpinBoxUpIcon() self.upLabel.clicked.connect(self.on_upLabel) self.downLabel = LabelButtons(backgroundColor, foregroundColor, height/2, height/2) self.labelLayout.addWidget(self.downLabel) self.downLabel.setSpinBoxDownIcon() self.downLabel.clicked.connect(self.on_downLabel) self.addLayout(self.labelLayout) self.spinBox = QSpinBox() self.spinBox.valueChanged.connect(self.spinBoxValueChanged) self.addWidget(self.spinBox) self.spinBox.setToolTip("Spinbox") self.spinBox.setButtonSymbols(QAbstractSpinBox.NoButtons) self.spinBox.setAlignment(Qt.AlignRight) self.spinBox.setMaximum(value) self.spinBox.setMaximumHeight(height) self.spinBox.setSuffix("/" + str(value)) font = self.spinBox.font() font.setPixelSize(fontSize) self.spinBox.setFont(font) rgb = foregroundColor.getRgb() rgba_string = "rgba("+str(rgb[0])+","+str(rgb[1])+","+str(rgb[2])+","+str(0.6*100)+"%)" self.spinBox.setStyleSheet("QSpinBox { color: " + rgba_string + "; font: bold; background-color: " + str(backgroundColor.name()) + "; border:0;}") def changeOpacity(self, opacity): rgb = self.foregroundColor.getRgb() rgba_string = "rgba("+str(rgb[0])+","+str(rgb[1])+","+str(rgb[2])+","+str(opacity*100)+"%)" self.spinBox.setStyleSheet("QSpinBox { color: " + rgba_string + "; font: bold; background-color: " + str(self.backgroundColor.name()) + "; border:0;}") self.upLabel.changeOpacity(opacity) self.downLabel.changeOpacity(opacity) def spinBoxValueChanged(self, value): self.valueChanged.emit(value) def setValue(self, value): self.spinBox.setValue(value) def setNewValue(self, value): self.spinBox.setMaximum(value) self.spinBox.setSuffix("/" + str(value)) def on_upLabel(self): self.spinBox.setValue(self.spinBox.value() + 1) def on_downLabel(self): self.spinBox.setValue(self.spinBox.value() - 1)
def _get_pos_widget(name, backgroundColor, foregroundColor): label = QLabel() label.setAttribute(Qt.WA_TransparentForMouseEvents, True) pixmap = QPixmap(25*10, 25*10) pixmap.fill(backgroundColor) painter = QPainter() painter.begin(pixmap) pen = QPen(foregroundColor) painter.setPen(pen) painter.setRenderHint(QPainter.Antialiasing) font = QFont() font.setBold(True) font.setPixelSize(25*10-30) path = QPainterPath() path.addText(QPointF(50, 25*10-50), font, name) brush = QBrush(foregroundColor) painter.setBrush(brush) painter.drawPath(path) painter.setFont(font) painter.end() pixmap = pixmap.scaled(QSize(20,20), Qt.KeepAspectRatio, Qt.SmoothTransformation) label.setPixmap(pixmap) spinbox = QSpinBox() spinbox.setAttribute(Qt.WA_TransparentForMouseEvents, True) spinbox.setEnabled(False) spinbox.setAlignment(Qt.AlignCenter) spinbox.setToolTip("{0} Spin Box".format(name)) spinbox.setButtonSymbols(QAbstractSpinBox.NoButtons) spinbox.setMaximumHeight(20) spinbox.setMaximum(9999) font = spinbox.font() font.setPixelSize(14) spinbox.setFont(font) sheet = TEMPLATE.format(foregroundColor.name(), backgroundColor.name()) spinbox.setStyleSheet(sheet) return label, spinbox
class QuadStatusBar(QHBoxLayout): def __init__(self, parent=None ): QHBoxLayout.__init__(self, parent) self.setContentsMargins(0,4,0,0) self.setSpacing(0) def createQuadViewStatusBar(self, xbackgroundColor, xforegroundColor, ybackgroundColor, yforegroundColor, zbackgroundColor, zforegroundColor, graybackgroundColor, grayforegroundColor): self.xLabel = QLabel() self.xLabel.setAttribute(Qt.WA_TransparentForMouseEvents, True) self.addWidget(self.xLabel) pixmap = QPixmap(25*10, 25*10) pixmap.fill(xbackgroundColor) painter = QPainter() painter.begin(pixmap) pen = QPen(xforegroundColor) painter.setPen(pen) painter.setRenderHint(QPainter.Antialiasing) font = QFont() font.setBold(True) font.setPixelSize(25*10-30) path = QPainterPath() path.addText(QPointF(50, 25*10-50), font, "X") brush = QBrush(xforegroundColor) painter.setBrush(brush) painter.drawPath(path) painter.setFont(font) painter.end() pixmap = pixmap.scaled(QSize(20,20),Qt.KeepAspectRatio, Qt.SmoothTransformation) self.xLabel.setPixmap(pixmap) self.xSpinBox = QSpinBox() self.xSpinBox.setAttribute(Qt.WA_TransparentForMouseEvents, True) self.xSpinBox.setEnabled(False) self.xSpinBox.setAlignment(Qt.AlignCenter) self.xSpinBox.setToolTip("xSpinBox") self.xSpinBox.setButtonSymbols(QAbstractSpinBox.NoButtons) self.xSpinBox.setMaximumHeight(20) self.xSpinBox.setMaximum(9999) font = self.xSpinBox.font() font.setPixelSize(14) self.xSpinBox.setFont(font) self.xSpinBox.setStyleSheet("QSpinBox { color: " + str(xforegroundColor.name()) + "; font: bold; background-color: " + str(xbackgroundColor.name()) + "; border:0;}") self.addWidget(self.xSpinBox) self.yLabel = QLabel() self.yLabel.setAttribute(Qt.WA_TransparentForMouseEvents, True) self.addWidget(self.yLabel) pixmap = QPixmap(25*10, 25*10) pixmap.fill(ybackgroundColor) painter = QPainter() painter.begin(pixmap) pen = QPen(yforegroundColor) painter.setPen(pen) painter.setRenderHint(QPainter.Antialiasing) font = QFont() font.setBold(True) font.setPixelSize(25*10-30) path = QPainterPath() path.addText(QPointF(50, 25*10-50), font, "Y") brush = QBrush(yforegroundColor) painter.setBrush(brush) painter.drawPath(path) painter.setFont(font) painter.end() pixmap = pixmap.scaled(QSize(20,20),Qt.KeepAspectRatio, Qt.SmoothTransformation) self.yLabel.setPixmap(pixmap) self.ySpinBox = QSpinBox() self.ySpinBox.setAttribute(Qt.WA_TransparentForMouseEvents, True) self.ySpinBox.setEnabled(False) self.ySpinBox.setAlignment(Qt.AlignCenter) self.ySpinBox.setToolTip("ySpinBox") self.ySpinBox.setButtonSymbols(QAbstractSpinBox.NoButtons) self.ySpinBox.setMaximumHeight(20) self.ySpinBox.setMaximum(9999) font = self.ySpinBox.font() font.setPixelSize(14) self.ySpinBox.setFont(font) self.ySpinBox.setStyleSheet("QSpinBox { color: " + str(yforegroundColor.name()) + "; font: bold; background-color: " + str(ybackgroundColor.name()) + "; border:0;}") self.addWidget(self.ySpinBox) self.zLabel = QLabel() self.zLabel.setAttribute(Qt.WA_TransparentForMouseEvents, True) self.addWidget(self.zLabel) pixmap = QPixmap(25*10, 25*10) pixmap.fill(zbackgroundColor) painter = QPainter() painter.begin(pixmap) pen = QPen(zforegroundColor) painter.setPen(pen) painter.setRenderHint(QPainter.Antialiasing) font = QFont() font.setBold(True) font.setPixelSize(25*10-30) path = QPainterPath() path.addText(QPointF(50, 25*10-50), font, "Z") brush = QBrush(zforegroundColor) painter.setBrush(brush) painter.drawPath(path) painter.setFont(font) painter.end() pixmap = pixmap.scaled(QSize(20,20),Qt.KeepAspectRatio, Qt.SmoothTransformation) self.zLabel.setPixmap(pixmap) self.zSpinBox = QSpinBox() self.zSpinBox.setAttribute(Qt.WA_TransparentForMouseEvents, True) self.zSpinBox.setEnabled(False) self.zSpinBox.setAlignment(Qt.AlignCenter) self.zSpinBox.setToolTip("zSpinBox") self.zSpinBox.setButtonSymbols(QAbstractSpinBox.NoButtons) self.zSpinBox.setMaximumHeight(20) self.zSpinBox.setMaximum(9999) font = self.zSpinBox.font() font.setPixelSize(14) self.zSpinBox.setFont(font) self.zSpinBox.setStyleSheet("QSpinBox { color: " + str(zforegroundColor.name()) + "; font: bold; background-color: " + str(zbackgroundColor.name()) + "; border:0;}") self.addWidget(self.zSpinBox) self.addSpacing(4) self.grayScaleLabel = QLabel() self.grayScaleLabel.setAttribute(Qt.WA_TransparentForMouseEvents, True) self.addWidget(self.grayScaleLabel) pixmap = QPixmap(610, 250) pixmap.fill(graybackgroundColor) painter = QPainter() painter.begin(pixmap) pen = QPen(grayforegroundColor) painter.setPen(pen) painter.setRenderHint(QPainter.Antialiasing) font = QFont() font.setBold(True) font.setPixelSize(25*10-30) path = QPainterPath() path.addText(QPointF(50, 25*10-50), font, "Gray") brush = QBrush(grayforegroundColor) painter.setBrush(brush) painter.drawPath(path) painter.setFont(font) painter.end() pixmap = pixmap.scaled(QSize(61,20),Qt.KeepAspectRatio, Qt.SmoothTransformation) """ self.grayScaleLabel.setPixmap(pixmap) self.grayScaleSpinBox = QSpinBox() self.grayScaleSpinBox.setAttribute(Qt.WA_TransparentForMouseEvents, True) self.grayScaleSpinBox.setEnabled(False) self.grayScaleSpinBox.setAlignment(Qt.AlignCenter) self.grayScaleSpinBox.setToolTip("grayscaleSpinBox") self.grayScaleSpinBox.setButtonSymbols(QAbstractSpinBox.NoButtons) self.grayScaleSpinBox.setMaximum(255) self.grayScaleSpinBox.setMaximumHeight(20) self.grayScaleSpinBox.setMaximum(255) font = self.grayScaleSpinBox.font() font.setPixelSize(14) self.grayScaleSpinBox.setFont(font) self.grayScaleSpinBox.setStyleSheet("QSpinBox { color: " + str(grayforegroundColor.name()) + "; font: bold; background-color: " + str(graybackgroundColor.name()) + "; border:0;}") self.addWidget(self.grayScaleSpinBox) """ self.addStretch() self.positionCheckBox = QCheckBox() self.positionCheckBox.setChecked(True) self.positionCheckBox.setCheckable(True) self.positionCheckBox.setText("Position") self.addWidget(self.positionCheckBox) self.addSpacing(20) self.channelLabel = QLabel("Channel:") self.addWidget(self.channelLabel) self.channelSpinBox = QSpinBox() self.addWidget(self.channelSpinBox) self.addSpacing(20) self.timeLabel = QLabel("Time:") self.addWidget(self.timeLabel) self.timeSpinBox = QSpinBox() self.addWidget(self.timeSpinBox) """ def setGrayScale(self, gray): self.grayScaleSpinBox.setValue(gray) """ def setMouseCoords(self, x, y, z): self.xSpinBox.setValue(x) self.ySpinBox.setValue(y) self.zSpinBox.setValue(z)