from PyQt5.QtCore import (QTranslator, QVariant, QDate, QTime, QDateTime, Qt, QLocale, QPoint, QPointF, QSize, QSizeF, QRect, QRectF) from PyQt5.QtGui import QKeySequence from pyqtcore import QList from qtvariantproperty import QtVariantEditorFactory, QtVariantPropertyManager from qttreepropertybrowser import QtTreePropertyBrowser if __name__ == '__main__': app = QApplication(sys.argv) trans = QTranslator() variantManager = QtVariantPropertyManager() i = 0 topItem = variantManager.addProperty( QtVariantPropertyManager.groupTypeId(), str(i) + " Group Property") i += 1 item = variantManager.addProperty(QVariant.Bool, str(i) + " Bool Property") i += 1 item.setValue(True) topItem.addSubProperty(item) item = variantManager.addProperty(QVariant.Int, str(i) + " Int Property") i += 1 item.setValue(20) item.setAttribute("minimum", 0) item.setAttribute("maximum", 100) item.setAttribute("singleStep", 10) topItem.addSubProperty(item)
def addClassProperties(self, metaObject): if (not metaObject): return self.addClassProperties(metaObject.superClass()) classProperty = self.m_classToProperty.value(metaObject) if (not classProperty): className = metaObject.className() classProperty = self.m_manager.addProperty( QtVariantPropertyManager.groupTypeId(), className) self.m_classToProperty[metaObject] = classProperty self.m_propertyToClass[classProperty] = metaObject for idx in range(metaObject.propertyOffset(), metaObject.propertyCount(), 1): metaProperty = metaObject.property(idx) type = metaProperty.userType() subProperty = 0 if (not metaProperty.isReadable()): subProperty = self.m_readOnlyManager.addProperty( QVariant.String, metaProperty.name()) subProperty.setValue("< Non Readable >") elif (metaProperty.isEnumType()): if (metaProperty.isFlagType()): subProperty = self.m_manager.addProperty( QtVariantPropertyManager.flagTypeId(), metaProperty.name()) metaEnum = metaProperty.enumerator() valueMap = QMap() flagNames = QList() for i in range(metaEnum.keyCount()): value = metaEnum.value(i) if (not valueMap.contains(value) and self.isPowerOf2(value)): valueMap[value] = True flagNames.append(metaEnum.key(i)) subProperty.setAttribute("flagNames", flagNames) subProperty.setValue( self.flagToInt(metaEnum, metaProperty.read(self.m_object))) else: subProperty = self.m_manager.addProperty( QtVariantPropertyManager.enumTypeId(), metaProperty.name()) metaEnum = metaProperty.enumerator() valueMap = QMap( ) # dont show multiple enum values which have the same values enumNames = QList() for i in range(metaEnum.keyCount()): value = metaEnum.value(i) if (not valueMap.contains(value)): valueMap[value] = True enumNames.append(metaEnum.key(i)) subProperty.setAttribute("enumNames", enumNames) subProperty.setValue( self.enumToInt(metaEnum, metaProperty.read(self.m_object))) elif (self.m_manager.isPropertyTypeSupported(type)): if (not metaProperty.isWritable()): subProperty = self.m_readOnlyManager.addProperty( type, metaProperty.name() + " (Non Writable)") if (not metaProperty.isDesignable()): subProperty = self.m_readOnlyManager.addProperty( type, metaProperty.name() + " (Non Designable)") else: subProperty = self.m_manager.addProperty( type, metaProperty.name()) subProperty.setValue(metaProperty.read(self.m_object)) else: subProperty = self.m_readOnlyManager.addProperty( QVariant.String, metaProperty.name()) subProperty.setValue("< Unknown Type >") subProperty.setEnabled(False) classProperty.addSubProperty(subProperty) self.m_propertyToIndex[subProperty] = idx self.m_classToIndexToProperty[metaObject][idx] = subProperty else: self.updateClassProperties(metaObject, False) self.m_topLevelProperties.append(classProperty) self.m_browser.addProperty(classProperty)
def __init__(self): super(MainWindow, self).__init__() self.setGeometry(0, 0, 1280, 780) # Create actions and menus self.createMenu() self.createToolBar() # Create status bar self.statusBar().showMessage("Ready") # Vulkan widget self.vulkanWindow = VulkanWindow(self) self.vulkanWindowWidget = QtWidgets.QWidget.createWindowContainer( self.vulkanWindow) self.vulkanWindow.initialize() # Stop rendering while moving the window self.moveEventTimer = QtCore.QTimer(self) self.moveEventTimer.timeout.connect(self.moveEventDone) # Dock layout dock = QtWidgets.QDockWidget() dock.setAllowedAreas(QtCore.Qt.LeftDockWidgetArea | QtCore.Qt.RightDockWidgetArea) self.addDockWidget(QtCore.Qt.LeftDockWidgetArea, dock) # Property editor self.variantManager = QtVariantPropertyManager(self) self.variantManager.valueChangedSignal.connect(self.valueChanged) topItem = self.variantManager.addProperty( QtVariantPropertyManager.groupTypeId(), "Group Property") item = self.variantManager.addProperty(QtCore.QVariant.Bool, "Pause?") item.setValue(False) topItem.addSubProperty(item) self.variantFactory = QtVariantEditorFactory() self.propertyEditor = QtTreePropertyBrowser(dock) self.propertyEditor.setFactoryForManager(self.variantManager, self.variantFactory) self.propertyEditor.addProperty(topItem) self.propertyEditor.setPropertiesWithoutValueMarked(True) self.propertyEditor.setRootIsDecorated(False) dock.setWidget(self.propertyEditor) # Vulkan viewport dock = QtWidgets.QDockWidget() dock.setWidget(self.vulkanWindowWidget) # Box layout #layout = QtWidgets.QVBoxLayout() #layout.addWidget(self.button) #layout.addWidget(self.vulkanWindowWidget) #layout.addWidget(dock) #mainWidget = QtWidgets.QWidget() #mainWidget.setLayout(layout) #self.setCentralWidget(mainWidget) self.setCentralWidget(self.vulkanWindowWidget)
def addClassProperties(self, metaObject): if (not metaObject): return self.addClassProperties(metaObject.superClass()) classProperty = self.m_classToProperty.value(metaObject) if (not classProperty): className = metaObject.className() classProperty = self.m_manager.addProperty(QtVariantPropertyManager.groupTypeId(), className) self.m_classToProperty[metaObject] = classProperty self.m_propertyToClass[classProperty] = metaObject for idx in range(metaObject.propertyOffset(), metaObject.propertyCount(), 1): metaProperty = metaObject.property(idx) type = metaProperty.userType() subProperty = 0 if (not metaProperty.isReadable()): subProperty = self.m_readOnlyManager.addProperty(QVariant.String, metaProperty.name()) subProperty.setValue("< Non Readable >") elif (metaProperty.isEnumType()): if (metaProperty.isFlagType()): subProperty = self.m_manager.addProperty(QtVariantPropertyManager.flagTypeId(), metaProperty.name()) metaEnum = metaProperty.enumerator() valueMap = QMap() flagNames = QList() for i in range(metaEnum.keyCount()): value = metaEnum.value(i) if (not valueMap.contains(value) and self.isPowerOf2(value)): valueMap[value] = True flagNames.append(metaEnum.key(i)) subProperty.setAttribute("flagNames", flagNames) subProperty.setValue(self.flagToInt(metaEnum, metaProperty.read(self.m_object))) else: subProperty = self.m_manager.addProperty(QtVariantPropertyManager.enumTypeId(), metaProperty.name()) metaEnum = metaProperty.enumerator() valueMap = QMap() # dont show multiple enum values which have the same values enumNames = QList() for i in range(metaEnum.keyCount()): value = metaEnum.value(i) if (not valueMap.contains(value)): valueMap[value] = True enumNames.append(metaEnum.key(i)) subProperty.setAttribute("enumNames", enumNames) subProperty.setValue(self.enumToInt(metaEnum, metaProperty.read(self.m_object))) elif (self.m_manager.isPropertyTypeSupported(type)): if (not metaProperty.isWritable()): subProperty = self.m_readOnlyManager.addProperty(type, metaProperty.name() + " (Non Writable)") if (not metaProperty.isDesignable()): subProperty = self.m_readOnlyManager.addProperty(type, metaProperty.name() + " (Non Designable)") else: subProperty = self.m_manager.addProperty(type, metaProperty.name()) subProperty.setValue(metaProperty.read(self.m_object)) else: subProperty = self.m_readOnlyManager.addProperty(QVariant.String, metaProperty.name()) subProperty.setValue("< Unknown Type >") subProperty.setEnabled(False) classProperty.addSubProperty(subProperty) self.m_propertyToIndex[subProperty] = idx self.m_classToIndexToProperty[metaObject][idx] = subProperty else: self.updateClassProperties(metaObject, False) self.m_topLevelProperties.append(classProperty) self.m_browser.addProperty(classProperty)
QSizeF, QRect, QRectF ) from PyQt5.QtGui import QKeySequence from pyqtcore import QList from qtvariantproperty import QtVariantEditorFactory, QtVariantPropertyManager from qttreepropertybrowser import QtTreePropertyBrowser if __name__ == '__main__': app = QApplication(sys.argv) trans = QTranslator() variantManager = QtVariantPropertyManager() i = 0 topItem = variantManager.addProperty(QtVariantPropertyManager.groupTypeId(), str(i) + " Group Property") i += 1 item = variantManager.addProperty(QVariant.Bool, str(i) + " Bool Property") i += 1 item.setValue(True) topItem.addSubProperty(item) item = variantManager.addProperty(QVariant.Int, str(i) + " Int Property") i += 1 item.setValue(20) item.setAttribute("minimum", 0) item.setAttribute("maximum", 100) item.setAttribute("singleStep", 10) topItem.addSubProperty(item)