class kTitleLabel(QtGui.QLabel): resized = QtCore.pyqtSignal() def __init__(self, parent=None): QtGui.QToolButton.__init__(self, parent) self.resized.connect(self.setButtonGeometry) self.h = 40 self.button = QtGui.QToolButton() self.button.setAutoRaise(True) self.button.setIconSize(QtCore.QSize(28, 28)) self.button.setParent(self) def resizeEvent(self, event): self.resized.emit() return super(kTitleLabel, self).resizeEvent(event) def setButtonGeometry(self): self.button.setGeometry(self.width() - self.h, 0, self.h, self.h) def setIcon(self, path): self.button.setIcon(QtGui.QIcon(path)) def setScript(self, function): self.button.clicked.connect( lambda arg=None, args=function: self.runScript(args)) def runScript(self, script): exec(script) def setHeight(self, height): self.h = height self.setFixedHeight(height)
class EditorStatusWidget(QtWidgets.QWidget): customNameStateChange = QtCore.pyqtSignal(bool) customNameFieldChange = QtCore.pyqtSignal(str) def __init__(self, parent): QtWidgets.QWidget.__init__(self, parent) layout = QtWidgets.QHBoxLayout(self) layout.setContentsMargins(4, 4, 4, 4) layout.setSpacing(2) self.__iconLabel = QtWidgets.QLabel('', self) self.__iconLabel.setFixedSize(QtCore.QSize(16, 16)) self.__textLabel = QtWidgets.QLabel('', self) self.__inputEdit = QT4FormWidgets.InputWidgets.InputLineEdit(self) self.__inputEdit.hide() layout.addWidget(self.__iconLabel) layout.addWidget(self.__textLabel) layout.addWidget(self.__inputEdit, 2) layout.addStretch() self.__enableCustomName = QtWidgets.QCheckBox('use custom asset name', self) self.__enableCustomName.hide() self.setFixedHeight(self.__inputEdit.height()) layout.addWidget(self.__enableCustomName) self.__enableCustomName.clicked.connect(self.__enableClicked) if hasattr(self.__inputEdit, 'EMITS_CUSTOM_FOCUS_EVENTS' ) and self.__inputEdit.EMITS_CUSTOM_FOCUS_EVENTS: self.__inputEdit.lostFocus.connect(self.__customFieldChanged) else: self.__inputEdit.lostFocus.connect(self.__customFieldChanged) def update(self, text, icon, potentialCustomName=False, activeCustomName=False): self.__textLabel.setText(text) self.__inputEdit.setText(text) if activeCustomName: self.__textLabel.setText('') self.__inputEdit.setText(text) self.__textLabel.hide() self.__inputEdit.show() else: self.__textLabel.setText(text) self.__inputEdit.setText('') self.__textLabel.show() self.__inputEdit.hide() if icon: self.__iconLabel.setPixmap(icon.pixmap(16, 16)) else: self.__iconLabel.setPixmap( UI4.Util.ScenegraphIconManager.GetPixmap('none')) self.__enableCustomName.setChecked(activeCustomName) if potentialCustomName: self.__enableCustomName.show() else: self.__enableCustomName.hide() def __enableClicked(self): self.customNameStateChange.emit(self.__enableCustomName.isChecked()) def __customFieldChanged(self): self.customNameFieldChange.emit(str(self.__inputEdit.text()))