Пример #1
0
    def __init__(self, parent=None):
        super(ObjectController, self).__init__(parent)
        self.d_ptr = ObjectControllerPrivate()
        self.d_ptr.q_ptr = self
        self.d_ptr.m_object = 0

        ##
        #    scroll = QScrollArea(self)
        #    scroll.setWidgetResizable(True)
        #
        #    self.d_ptr.m_browser = QtGroupBoxPropertyBrowser(self)
        #    layout = QVBoxLayout(self)
        #    layout.setMargin(0)
        #    layout.addWidget(scroll)
        #    scroll.setWidget(self.d_ptr.m_browser)
        ##
        browser = QtTreePropertyBrowser(self)
        browser.setRootIsDecorated(False)
        self.d_ptr.m_browser = browser
        layout = QVBoxLayout(self)
        layout.setContentsMargins(0, 0, 0, 0)
        layout.addWidget(self.d_ptr.m_browser)

        self.d_ptr.m_readOnlyManager = QtVariantPropertyManager(self)
        self.d_ptr.m_manager = QtVariantPropertyManager(self)
        factory = QtVariantEditorFactory(self)
        self.d_ptr.m_browser.setFactoryForManager(self.d_ptr.m_manager,
                                                  factory)

        self.d_ptr.m_manager.valueChangedSignal.connect(
            self.d_ptr.slotValueChanged)
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.propertyToId = QMap()
        self.idToProperty = QMap()
        self.idToExpanded = QMap()

        editMenu = self.menuBar().addMenu(self.tr("Edit"))
        newObjectMenu = editMenu.addMenu(self.tr("New Object"))

        newRectangleAction = QAction(self.tr("Rectangle"), self)
        newRectangleAction.triggered.connect(self.newRectangle)
        newObjectMenu.addAction(newRectangleAction)

        newLineAction = QAction(self.tr("Line"), self)
        newLineAction.triggered.connect(self.newLine)
        newObjectMenu.addAction(newLineAction)

        newEllipseAction = QAction(self.tr("Ellipse"), self)
        newEllipseAction.triggered.connect(self.newEllipse)
        newObjectMenu.addAction(newEllipseAction)

        newTextAction = QAction(self.tr("Text"), self)
        newTextAction.triggered.connect(self.newText)
        newObjectMenu.addAction(newTextAction)

        self.deleteAction = QAction(self.tr("Delete Object"), self)
        self.deleteAction.triggered.connect(self.deleteObject)
        editMenu.addAction(self.deleteAction)

        clearAction = QAction(self.tr("Clear All"), self)
        clearAction.triggered.connect(self.clearAll)
        editMenu.addAction(clearAction)

        fillAction = QAction(self.tr("Fill View"), self)
        fillAction.triggered.connect(self.fillView)
        editMenu.addAction(fillAction)

        self.variantManager = QtVariantPropertyManager(self)

        self.variantManager.valueChangedSignal.connect(self.valueChanged)
        variantFactory = QtVariantEditorFactory(self)

        self.canvas = QtCanvas(800, 600)
        self.canvasView = CanvasView(self.canvas, self)
        self.setCentralWidget(self.canvasView)

        dock = QDockWidget(self)
        self.addDockWidget(Qt.RightDockWidgetArea, dock)

        self.propertyEditor = QtTreePropertyBrowser(dock)
        self.propertyEditor.setFactoryForManager(self.variantManager, variantFactory)
        dock.setWidget(self.propertyEditor)

        self.currentItem = QtCanvasItem(None)

        self.canvasView.itemClickedSignal.connect(self.itemClicked)
        self.canvasView.itemMovedSignal.connect(self.itemMoved)

        self.fillView()
        self.itemClicked(QtCanvasItem(None))
Пример #3
0
    def addMapProperties(self):

        groupProperty = self.mGroupManager.addProperty(self.tr("Map"))

        orientationProperty = self.createProperty(
            PropertyId.OrientationProperty,
            QtVariantPropertyManager.enumTypeId(), self.tr("Orientation"),
            groupProperty)
        orientationProperty.setAttribute("enumNames", self.mOrientationNames)
        self.createProperty(PropertyId.WidthProperty, QVariant.Int,
                            self.tr("Width"), groupProperty).setEnabled(False)
        self.createProperty(PropertyId.HeightProperty, QVariant.Int,
                            self.tr("Height"), groupProperty).setEnabled(False)
        self.createProperty(PropertyId.TileWidthProperty, QVariant.Int,
                            self.tr("Tile Width"), groupProperty)
        self.createProperty(PropertyId.TileHeightProperty, QVariant.Int,
                            self.tr("Tile Height"), groupProperty)
        self.createProperty(PropertyId.HexSideLengthProperty, QVariant.Int,
                            self.tr("Tile Side Length (Hex)"), groupProperty)
        staggerAxisProperty = self.createProperty(
            PropertyId.StaggerAxisProperty,
            QtVariantPropertyManager.enumTypeId(), self.tr("Stagger Axis"),
            groupProperty)
        staggerAxisProperty.setAttribute("enumNames", self.mStaggerAxisNames)
        staggerIndexProperty = self.createProperty(
            PropertyId.StaggerIndexProperty,
            QtVariantPropertyManager.enumTypeId(), self.tr("Stagger Index"),
            groupProperty)
        staggerIndexProperty.setAttribute("enumNames", self.mStaggerIndexNames)
        layerFormatProperty = self.createProperty(
            PropertyId.LayerFormatProperty,
            QtVariantPropertyManager.enumTypeId(),
            self.tr("Tile Layer Format"), groupProperty)
        layerFormatProperty.setAttribute("enumNames", self.mLayerFormatNames)
        renderOrderProperty = self.createProperty(
            PropertyId.RenderOrderProperty,
            QtVariantPropertyManager.enumTypeId(),
            self.tr("Tile Render Order"), groupProperty)
        renderOrderProperty.setAttribute("enumNames", self.mRenderOrderNames)
        self.createProperty(PropertyId.ColorProperty, QVariant.Color,
                            self.tr("Background Color"), groupProperty)
        self.addProperty(groupProperty)
Пример #4
0
    def addObjectGroupProperties(self):
        groupProperty = self.mGroupManager.addProperty(self.tr("Object Layer"))
        self.addLayerProperties(groupProperty)
        
        self.createProperty(PropertyId.OffsetXProperty, QVariant.Double, self.tr("Horizontal Offset"), groupProperty)
        self.createProperty(PropertyId.OffsetYProperty, QVariant.Double, self.tr("Vertical Offset"), groupProperty)

        self.createProperty(PropertyId.ColorProperty, QVariant.Color, self.tr("Color"), groupProperty)
        drawOrderProperty = self.createProperty(PropertyId.DrawOrderProperty,
                               QtVariantPropertyManager.enumTypeId(),
                               self.tr("Drawing Order"),
                               groupProperty)
        drawOrderProperty.setAttribute("enumNames", self.mDrawOrderNames)
        self.addProperty(groupProperty)
Пример #5
0
 def addMapProperties(self):
     
     groupProperty = self.mGroupManager.addProperty(self.tr("Map"))
     
     orientationProperty = self.createProperty(PropertyId.OrientationProperty,
                            QtVariantPropertyManager.enumTypeId(),
                            self.tr("Orientation"),
                            groupProperty)
     orientationProperty.setAttribute("enumNames", self.mOrientationNames)
     self.createProperty(PropertyId.WidthProperty, QVariant.Int, self.tr("Width"), groupProperty).setEnabled(False)
     self.createProperty(PropertyId.HeightProperty, QVariant.Int, self.tr("Height"), groupProperty).setEnabled(False)
     self.createProperty(PropertyId.TileWidthProperty, QVariant.Int, self.tr("Tile Width"), groupProperty)
     self.createProperty(PropertyId.TileHeightProperty, QVariant.Int, self.tr("Tile Height"), groupProperty)
     self.createProperty(PropertyId.HexSideLengthProperty, QVariant.Int, self.tr("Tile Side Length (Hex)"), groupProperty)
     staggerAxisProperty = self.createProperty(PropertyId.StaggerAxisProperty,
                            QtVariantPropertyManager.enumTypeId(),
                            self.tr("Stagger Axis"),
                            groupProperty)
     staggerAxisProperty.setAttribute("enumNames", self.mStaggerAxisNames)
     staggerIndexProperty = self.createProperty(PropertyId.StaggerIndexProperty,
                            QtVariantPropertyManager.enumTypeId(),
                            self.tr("Stagger Index"),
                            groupProperty)
     staggerIndexProperty.setAttribute("enumNames", self.mStaggerIndexNames)
     layerFormatProperty = self.createProperty(PropertyId.LayerFormatProperty,
                            QtVariantPropertyManager.enumTypeId(),
                            self.tr("Tile Layer Format"),
                            groupProperty)
     layerFormatProperty.setAttribute("enumNames", self.mLayerFormatNames)
     renderOrderProperty = self.createProperty(PropertyId.RenderOrderProperty,
                            QtVariantPropertyManager.enumTypeId(),
                            self.tr("Tile Render Order"),
                            groupProperty)
     renderOrderProperty.setAttribute("enumNames", self.mRenderOrderNames)
     self.createProperty(PropertyId.ColorProperty, QVariant.Color, self.tr("Background Color"), groupProperty)
     self.addProperty(groupProperty)
Пример #6
0
    def addObjectGroupProperties(self):
        groupProperty = self.mGroupManager.addProperty(self.tr("Object Layer"))
        self.addLayerProperties(groupProperty)

        self.createProperty(PropertyId.OffsetXProperty, QVariant.Double,
                            self.tr("Horizontal Offset"), groupProperty)
        self.createProperty(PropertyId.OffsetYProperty, QVariant.Double,
                            self.tr("Vertical Offset"), groupProperty)

        self.createProperty(PropertyId.ColorProperty, QVariant.Color,
                            self.tr("Color"), groupProperty)
        drawOrderProperty = self.createProperty(
            PropertyId.DrawOrderProperty,
            QtVariantPropertyManager.enumTypeId(), self.tr("Drawing Order"),
            groupProperty)
        drawOrderProperty.setAttribute("enumNames", self.mDrawOrderNames)
        self.addProperty(groupProperty)
Пример #7
0
sys.path.append('libqt5')

from PyQt5.QtWidgets import QApplication, QLineEdit
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)
Пример #8
0
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.propertyToId = QMap()
        self.idToProperty = QMap()
        self.idToExpanded = QMap()

        editMenu = self.menuBar().addMenu(self.tr("Edit"))
        newObjectMenu = editMenu.addMenu(self.tr("New Object"))

        newRectangleAction = QAction(self.tr("Rectangle"), self)
        newRectangleAction.triggered.connect(self.newRectangle)
        newObjectMenu.addAction(newRectangleAction)

        newLineAction = QAction(self.tr("Line"), self)
        newLineAction.triggered.connect(self.newLine)
        newObjectMenu.addAction(newLineAction)

        newEllipseAction = QAction(self.tr("Ellipse"), self)
        newEllipseAction.triggered.connect(self.newEllipse)
        newObjectMenu.addAction(newEllipseAction)

        newTextAction = QAction(self.tr("Text"), self)
        newTextAction.triggered.connect(self.newText)
        newObjectMenu.addAction(newTextAction)

        self.deleteAction = QAction(self.tr("Delete Object"), self)
        self.deleteAction.triggered.connect(self.deleteObject)
        editMenu.addAction(self.deleteAction)

        clearAction = QAction(self.tr("Clear All"), self)
        clearAction.triggered.connect(self.clearAll)
        editMenu.addAction(clearAction)

        fillAction = QAction(self.tr("Fill View"), self)
        fillAction.triggered.connect(self.fillView)
        editMenu.addAction(fillAction)

        self.variantManager = QtVariantPropertyManager(self)

        self.variantManager.valueChangedSignal.connect(self.valueChanged)
        variantFactory = QtVariantEditorFactory(self)

        self.canvas = QtCanvas(800, 600)
        self.canvasView = CanvasView(self.canvas, self)
        self.setCentralWidget(self.canvasView)

        dock = QDockWidget(self)
        self.addDockWidget(Qt.RightDockWidgetArea, dock)

        self.propertyEditor = QtTreePropertyBrowser(dock)
        self.propertyEditor.setFactoryForManager(self.variantManager,
                                                 variantFactory)
        dock.setWidget(self.propertyEditor)

        self.currentItem = QtCanvasItem(None)

        self.canvasView.itemClickedSignal.connect(self.itemClicked)
        self.canvasView.itemMovedSignal.connect(self.itemMoved)

        self.fillView()
        self.itemClicked(QtCanvasItem(None))
Пример #9
0
class MainWindow(QMainWindow):
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.propertyToId = QMap()
        self.idToProperty = QMap()
        self.idToExpanded = QMap()

        editMenu = self.menuBar().addMenu(self.tr("Edit"))
        newObjectMenu = editMenu.addMenu(self.tr("New Object"))

        newRectangleAction = QAction(self.tr("Rectangle"), self)
        newRectangleAction.triggered.connect(self.newRectangle)
        newObjectMenu.addAction(newRectangleAction)

        newLineAction = QAction(self.tr("Line"), self)
        newLineAction.triggered.connect(self.newLine)
        newObjectMenu.addAction(newLineAction)

        newEllipseAction = QAction(self.tr("Ellipse"), self)
        newEllipseAction.triggered.connect(self.newEllipse)
        newObjectMenu.addAction(newEllipseAction)

        newTextAction = QAction(self.tr("Text"), self)
        newTextAction.triggered.connect(self.newText)
        newObjectMenu.addAction(newTextAction)

        self.deleteAction = QAction(self.tr("Delete Object"), self)
        self.deleteAction.triggered.connect(self.deleteObject)
        editMenu.addAction(self.deleteAction)

        clearAction = QAction(self.tr("Clear All"), self)
        clearAction.triggered.connect(self.clearAll)
        editMenu.addAction(clearAction)

        fillAction = QAction(self.tr("Fill View"), self)
        fillAction.triggered.connect(self.fillView)
        editMenu.addAction(fillAction)

        self.variantManager = QtVariantPropertyManager(self)

        self.variantManager.valueChangedSignal.connect(self.valueChanged)
        variantFactory = QtVariantEditorFactory(self)

        self.canvas = QtCanvas(800, 600)
        self.canvasView = CanvasView(self.canvas, self)
        self.setCentralWidget(self.canvasView)

        dock = QDockWidget(self)
        self.addDockWidget(Qt.RightDockWidgetArea, dock)

        self.propertyEditor = QtTreePropertyBrowser(dock)
        self.propertyEditor.setFactoryForManager(self.variantManager,
                                                 variantFactory)
        dock.setWidget(self.propertyEditor)

        self.currentItem = QtCanvasItem(None)

        self.canvasView.itemClickedSignal.connect(self.itemClicked)
        self.canvasView.itemMovedSignal.connect(self.itemMoved)

        self.fillView()
        self.itemClicked(QtCanvasItem(None))

    def newRectangle(self):
        item = self.addRectangle()
        self.canvas.update()
        self.itemClicked(item)

    def newEllipse(self):
        item = self.addEllipse()
        self.canvas.update()
        self.itemClicked(item)

    def newLine(self):
        item = self.addLine()
        self.canvas.update()
        self.itemClicked(item)

    def newText(self):
        item = self.addText()
        self.canvas.update()
        self.itemClicked(item)

    def deleteObject(self):
        if (not self.currentItem or self.currentItem.isNone()):
            return

        self.canvas.removeItem(self.currentItem)
        self.currentItem = QtCanvasItem(None)
        self.itemClicked(self.currentItem)
        self.canvas.update()

    def clearAll(self):
        for item in self.canvas.allItems():
            self.canvas.removeItem(item)
        self.itemClicked(QtCanvasItem(None))
        self.canvas.update()

    def fillView(self):
        for i in range(10):
            self.addRectangle()
            self.addEllipse()
            self.addLine()
            self.addText()
        self.canvas.update()

    def addRectangle(self):
        item = QtCanvasRectangle(rand() % self.canvas.width(),
                                 rand() % self.canvas.height(), 50, 50,
                                 self.canvas)
        item.setBrush(
            QBrush(QColor(rand() % 32 * 8,
                          rand() % 32 * 8,
                          rand() % 32 * 8)))
        item.setPen(
            QPen(QColor(rand() % 32 * 8,
                        rand() % 32 * 8,
                        rand() % 32 * 8), 4))
        item.setZ(rand() % 256)
        item.show()
        return item

    def addEllipse(self):
        item = QtCanvasEllipse(50, 50, self.canvas)
        item.setBrush(
            QBrush(QColor(rand() % 32 * 8,
                          rand() % 32 * 8,
                          rand() % 32 * 8)))
        item.move(rand() % self.canvas.width(), rand() % self.canvas.height())
        item.setZ(rand() % 256)
        item.show()
        return item

    def addLine(self):
        item = QtCanvasLine(self.canvas)
        item.setPoints(
            0, 0,
            rand() % self.canvas.width() - self.canvas.width() / 2,
            rand() % self.canvas.height() - self.canvas.height() / 2)
        item.move(rand() % self.canvas.width(), rand() % self.canvas.height())
        item.setPen(
            QPen(QColor(rand() % 32 * 8,
                        rand() % 32 * 8,
                        rand() % 32 * 8), 6))
        item.setZ(rand() % 256)
        item.show()
        return item

    def addText(self):
        item = QtCanvasText(self.canvas)
        item.setText(self.tr("Text"))
        item.setColor(QColor(rand() % 32 * 8,
                             rand() % 32 * 8,
                             rand() % 32 * 8))
        item.move(rand() % self.canvas.width(), rand() % self.canvas.height())
        item.setZ(rand() % 256)
        item.show()
        return item

    def itemMoved(self, item):
        if (item != self.currentItem or self.currentItem.isNone()):
            return

        self.variantManager.setValue(self.idToProperty["xpos"], item.x())
        self.variantManager.setValue(self.idToProperty["ypos"], item.y())
        self.variantManager.setValue(self.idToProperty["zpos"], item.z())

    def updateExpandState(self):
        l = self.propertyEditor.topLevelItems()
        for item in l:
            prop = item.property()
            self.idToExpanded[
                self.propertyToId[prop]] = self.propertyEditor.isExpanded(item)

    def itemClicked(self, item):
        self.updateExpandState()
        for p in self.propertyToId.keys():
            p.destroy()
        self.propertyToId.clear()
        self.idToProperty.clear()

        self.currentItem = item
        if (not self.currentItem or self.currentItem.isNone()):
            self.deleteAction.setEnabled(False)
            return

        self.deleteAction.setEnabled(True)

        property = self.variantManager.addProperty(QVariant.Double,
                                                   self.tr("Position X"))
        property.setAttribute("minimum", 0)
        property.setAttribute("maximum", self.canvas.width())
        property.setValue(item.x())
        self.addProperty(property, "xpos")

        property = self.variantManager.addProperty(QVariant.Double,
                                                   self.tr("Position Y"))
        property.setAttribute("minimum", 0)
        property.setAttribute("maximum", self.canvas.height())
        property.setValue(item.y())
        self.addProperty(property, "ypos")

        property = self.variantManager.addProperty(QVariant.Double,
                                                   self.tr("Position Z"))
        property.setAttribute("minimum", 0)
        property.setAttribute("maximum", 256)
        property.setValue(item.z())
        self.addProperty(property, "zpos")

        if (item.rtti() == RttiValues.Rtti_Rectangle):
            i = item

            property = self.variantManager.addProperty(QVariant.Color,
                                                       self.tr("Brush Color"))
            property.setValue(i.brush().color())
            self.addProperty(property, "brush")

            property = self.variantManager.addProperty(QVariant.Color,
                                                       self.tr("Pen Color"))
            property.setValue(i.pen().color())
            self.addProperty(property, "pen")

            property = self.variantManager.addProperty(QVariant.Size,
                                                       self.tr("Size"))
            property.setValue(i.size())
            self.addProperty(property, "size")
        elif (item.rtti() == RttiValues.Rtti_Line):
            i = item

            property = self.variantManager.addProperty(QVariant.Color,
                                                       self.tr("Pen Color"))
            property.setValue(i.pen().color())
            self.addProperty(property, "pen")

            property = self.variantManager.addProperty(QVariant.Point,
                                                       self.tr("Vector"))
            property.setValue(i.endPoint())
            self.addProperty(property, "endpoint")
        elif (item.rtti() == RttiValues.Rtti_Ellipse):
            i = item

            property = self.variantManager.addProperty(QVariant.Color,
                                                       self.tr("Brush Color"))
            property.setValue(i.brush().color())
            self.addProperty(property, "brush")

            property = self.variantManager.addProperty(QVariant.Size,
                                                       self.tr("Size"))
            property.setValue(QSize(i.width(), i.height()))
            self.addProperty(property, "size")
        elif (item.rtti() == RttiValues.Rtti_Text):
            i = item

            property = self.variantManager.addProperty(QVariant.Color,
                                                       self.tr("Color"))
            property.setValue(i.color())
            self.addProperty(property, "color")

            property = self.variantManager.addProperty(QVariant.String,
                                                       self.tr("Text"))
            property.setValue(i.text())
            self.addProperty(property, "text")

            property = self.variantManager.addProperty(QVariant.Font,
                                                       self.tr("Font"))
            property.setValue(i.font())
            self.addProperty(property, "font")

    def addProperty(self, property, id):
        self.propertyToId[property] = id
        self.idToProperty[id] = property
        item = self.propertyEditor.addProperty(property)
        if (self.idToExpanded.contains(id)):
            self.propertyEditor.setExpanded(item, self.idToExpanded[id])

    def valueChanged(self, property, value):
        if (not self.propertyToId.contains(property)):
            return

        if (not self.currentItem or self.currentItem.isNone()):
            return

        id = self.propertyToId[property]
        if (id == "xpos"):
            self.currentItem.setX(value)
        elif (id == "ypos"):
            self.currentItem.setY(value)
        elif (id == "zpos"):
            self.currentItem.setZ(value)
        elif (id == "text"):
            if (self.currentItem.rtti() == RttiValues.Rtti_Text):
                i = self.currentItem
                i.setText(value)
        elif (id == "color"):
            if (self.currentItem.rtti() == RttiValues.Rtti_Text):
                i = self.currentItem
                i.setColor(value)
        elif (id == "brush"):
            if (self.currentItem.rtti() == RttiValues.Rtti_Rectangle
                    or self.currentItem.rtti() == RttiValues.Rtti_Ellipse):
                i = self.currentItem
                b = QBrush(i.brush())
                b.setColor(value)
                i.setBrush(b)
        elif (id == "pen"):
            if (self.currentItem.rtti() == RttiValues.Rtti_Rectangle
                    or self.currentItem.rtti() == RttiValues.Rtti_Line):
                i = self.currentItem
                p = QPen(i.pen())
                p.setColor(value)
                i.setPen(p)
        elif (id == "font"):
            if (self.currentItem.rtti() == RttiValues.Rtti_Text):
                i = self.currentItem
                i.setFont(value)
        elif (id == "endpoint"):
            if (self.currentItem.rtti() == RttiValues.Rtti_Line):
                i = self.currentItem
                p = value
                i.setPoints(i.startPoint().x(),
                            i.startPoint().y(), p.x(), p.y())
        elif (id == "size"):
            if (self.currentItem.rtti() == RttiValues.Rtti_Rectangle):
                i = self.currentItem
                s = value
                i.setSize(s.width(), s.height())
            elif (self.currentItem.rtti() == RttiValues.Rtti_Ellipse):
                i = self.currentItem
                s = value
                i.setSize(s.width(), s.height())
        self.canvas.update()
Пример #10
0
    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 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)
Пример #12
0
    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)
Пример #13
0
class MainWindow(QtWidgets.QMainWindow):
    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)

        #self.showMaximized()

    def __del__(self):
        del self.variantManager
        del self.variantFactory
        del self.variantEditor
        self.destroy()

    def valueChanged(self, property, value):
        tp = type(value)
        if tp == bool:
            self.vulkanWindow.vk_renderer.is_paused = value

    def closeEvent(self, event):
        self.vulkanWindow.cleanup()
        del self.vulkanWindow

    def moveEvent(self, event):
        self.moveEventTimer.start(500)
        self.vulkanWindow.timer.stop()

    def moveEventDone(self):
        self.vulkanWindow.timer.start()

    def createMenu(self):
        fileMenu = self.menuBar().addMenu("&File")
        fileMenu.addAction("Exit", self.exit)

    def createToolBar(self):
        exitAction = QtWidgets.QAction(QtGui.QIcon(":/images/open.png"),
                                       "&Open...", self)
        exitAction.setStatusTip("Open an existing file")
        exitAction.triggered.connect(self.exit)
        self.fileToolBar = self.addToolBar("File")
        self.fileToolBar.addAction(exitAction)

    def exit(self):
        print("exit")
    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)
class MainWindow(QMainWindow):
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.propertyToId = QMap()
        self.idToProperty = QMap()
        self.idToExpanded = QMap()

        editMenu = self.menuBar().addMenu(self.tr("Edit"))
        newObjectMenu = editMenu.addMenu(self.tr("New Object"))

        newRectangleAction = QAction(self.tr("Rectangle"), self)
        newRectangleAction.triggered.connect(self.newRectangle)
        newObjectMenu.addAction(newRectangleAction)

        newLineAction = QAction(self.tr("Line"), self)
        newLineAction.triggered.connect(self.newLine)
        newObjectMenu.addAction(newLineAction)

        newEllipseAction = QAction(self.tr("Ellipse"), self)
        newEllipseAction.triggered.connect(self.newEllipse)
        newObjectMenu.addAction(newEllipseAction)

        newTextAction = QAction(self.tr("Text"), self)
        newTextAction.triggered.connect(self.newText)
        newObjectMenu.addAction(newTextAction)

        self.deleteAction = QAction(self.tr("Delete Object"), self)
        self.deleteAction.triggered.connect(self.deleteObject)
        editMenu.addAction(self.deleteAction)

        clearAction = QAction(self.tr("Clear All"), self)
        clearAction.triggered.connect(self.clearAll)
        editMenu.addAction(clearAction)

        fillAction = QAction(self.tr("Fill View"), self)
        fillAction.triggered.connect(self.fillView)
        editMenu.addAction(fillAction)

        self.variantManager = QtVariantPropertyManager(self)

        self.variantManager.valueChangedSignal.connect(self.valueChanged)
        variantFactory = QtVariantEditorFactory(self)

        self.canvas = QtCanvas(800, 600)
        self.canvasView = CanvasView(self.canvas, self)
        self.setCentralWidget(self.canvasView)

        dock = QDockWidget(self)
        self.addDockWidget(Qt.RightDockWidgetArea, dock)

        self.propertyEditor = QtTreePropertyBrowser(dock)
        self.propertyEditor.setFactoryForManager(self.variantManager, variantFactory)
        dock.setWidget(self.propertyEditor)

        self.currentItem = QtCanvasItem(None)

        self.canvasView.itemClickedSignal.connect(self.itemClicked)
        self.canvasView.itemMovedSignal.connect(self.itemMoved)

        self.fillView()
        self.itemClicked(QtCanvasItem(None))

    def newRectangle(self):
        item = self.addRectangle()
        self.canvas.update()
        self.itemClicked(item)

    def newEllipse(self):
        item = self.addEllipse()
        self.canvas.update()
        self.itemClicked(item)

    def newLine(self):
        item = self.addLine()
        self.canvas.update()
        self.itemClicked(item)

    def newText(self):
        item = self.addText()
        self.canvas.update()
        self.itemClicked(item)

    def deleteObject(self):
        if (not self.currentItem or self.currentItem.isNone()):
            return

        self.canvas.removeItem(self.currentItem)
        self.currentItem = QtCanvasItem(None)
        self.itemClicked(self.currentItem)
        self.canvas.update()

    def clearAll(self):
        for item in self.canvas.allItems():
            self.canvas.removeItem(item)
        self.itemClicked(QtCanvasItem(None))
        self.canvas.update()

    def fillView(self):
        for i in range(10):
            self.addRectangle()
            self.addEllipse()
            self.addLine()
            self.addText()
        self.canvas.update()

    def addRectangle(self):
        item = QtCanvasRectangle(rand() % self.canvas.width(), rand() % self.canvas.height(), 50, 50, self.canvas)
        item.setBrush(QBrush(QColor(rand() % 32 * 8, rand() % 32 * 8, rand() % 32 * 8)))
        item.setPen(QPen(QColor(rand() % 32*8, rand() % 32*8, rand() % 32*8), 4))
        item.setZ(rand() % 256)
        item.show()
        return item

    def addEllipse(self):
        item = QtCanvasEllipse(50, 50, self.canvas)
        item.setBrush(QBrush(QColor(rand() % 32 * 8, rand() % 32 * 8, rand() % 32 * 8)))
        item.move(rand() % self.canvas.width(), rand() % self.canvas.height())
        item.setZ(rand() % 256)
        item.show()
        return item

    def addLine(self):
        item = QtCanvasLine(self.canvas)
        item.setPoints(0, 0, rand() % self.canvas.width() - self.canvas.width() / 2, rand() % self.canvas.height() - self.canvas.height() / 2)
        item.move(rand() % self.canvas.width(), rand() % self.canvas.height())
        item.setPen(QPen(QColor(rand() % 32*8, rand() % 32*8, rand() % 32*8), 6))
        item.setZ(rand() % 256)
        item.show()
        return item

    def addText(self):
        item = QtCanvasText(self.canvas)
        item.setText(self.tr("Text"))
        item.setColor(QColor(rand() % 32*8, rand() % 32*8, rand() % 32*8))
        item.move(rand() % self.canvas.width(), rand() % self.canvas.height())
        item.setZ(rand() % 256)
        item.show()
        return item

    def itemMoved(self, item):
        if (item != self.currentItem or self.currentItem.isNone()):
            return

        self.variantManager.setValue(self.idToProperty["xpos"], item.x())
        self.variantManager.setValue(self.idToProperty["ypos"], item.y())
        self.variantManager.setValue(self.idToProperty["zpos"], item.z())

    def updateExpandState(self):
        l = self.propertyEditor.topLevelItems()
        for item in l:
            prop = item.property()
            self.idToExpanded[self.propertyToId[prop]] = self.propertyEditor.isExpanded(item)

    def itemClicked(self, item):
        self.updateExpandState()
        for p in self.propertyToId.keys():
            p.destroy()
        self.propertyToId.clear()
        self.idToProperty.clear()

        self.currentItem = item
        if (not self.currentItem or self.currentItem.isNone()):
            self.deleteAction.setEnabled(False)
            return

        self.deleteAction.setEnabled(True)

        property = self.variantManager.addProperty(QVariant.Double, self.tr("Position X"))
        property.setAttribute("minimum", 0)
        property.setAttribute("maximum", self.canvas.width())
        property.setValue(item.x())
        self.addProperty(property, "xpos")

        property = self.variantManager.addProperty(QVariant.Double, self.tr("Position Y"))
        property.setAttribute("minimum", 0)
        property.setAttribute("maximum", self.canvas.height())
        property.setValue(item.y())
        self.addProperty(property, "ypos")

        property = self.variantManager.addProperty(QVariant.Double, self.tr("Position Z"))
        property.setAttribute("minimum", 0)
        property.setAttribute("maximum", 256)
        property.setValue(item.z())
        self.addProperty(property, "zpos")

        if (item.rtti() == RttiValues.Rtti_Rectangle):
            i = item

            property = self.variantManager.addProperty(QVariant.Color, self.tr("Brush Color"))
            property.setValue(i.brush().color())
            self.addProperty(property, "brush")

            property = self.variantManager.addProperty(QVariant.Color, self.tr("Pen Color"))
            property.setValue(i.pen().color())
            self.addProperty(property, "pen")

            property = self.variantManager.addProperty(QVariant.Size, self.tr("Size"))
            property.setValue(i.size())
            self.addProperty(property, "size")
        elif (item.rtti() == RttiValues.Rtti_Line):
            i = item

            property = self.variantManager.addProperty(QVariant.Color, self.tr("Pen Color"))
            property.setValue(i.pen().color())
            self.addProperty(property, "pen")

            property = self.variantManager.addProperty(QVariant.Point, self.tr("Vector"))
            property.setValue(i.endPoint())
            self.addProperty(property, "endpoint")
        elif (item.rtti() == RttiValues.Rtti_Ellipse):
            i = item

            property = self.variantManager.addProperty(QVariant.Color, self.tr("Brush Color"))
            property.setValue(i.brush().color())
            self.addProperty(property, "brush")

            property = self.variantManager.addProperty(QVariant.Size, self.tr("Size"))
            property.setValue(QSize(i.width(), i.height()))
            self.addProperty(property, "size")
        elif (item.rtti() == RttiValues.Rtti_Text):
            i = item

            property = self.variantManager.addProperty(QVariant.Color, self.tr("Color"))
            property.setValue(i.color())
            self.addProperty(property, "color")

            property = self.variantManager.addProperty(QVariant.String, self.tr("Text"))
            property.setValue(i.text())
            self.addProperty(property, "text")

            property = self.variantManager.addProperty(QVariant.Font, self.tr("Font"))
            property.setValue(i.font())
            self.addProperty(property, "font")

    def addProperty(self, property, id):
        self.propertyToId[property] = id
        self.idToProperty[id] = property
        item = self.propertyEditor.addProperty(property)
        if (self.idToExpanded.contains(id)):
            self.propertyEditor.setExpanded(item, self.idToExpanded[id])

    def valueChanged(self, property, value):
        if (not self.propertyToId.contains(property)):
            return

        if (not self.currentItem or self.currentItem.isNone()):
            return

        id = self.propertyToId[property]
        if (id == "xpos"):
            self.currentItem.setX(value)
        elif (id == "ypos"):
            self.currentItem.setY(value)
        elif (id == "zpos"):
            self.currentItem.setZ(value)
        elif (id == "text"):
            if (self.currentItem.rtti() == RttiValues.Rtti_Text):
                i = self.currentItem
                i.setText(value)
        elif (id == "color"):
            if (self.currentItem.rtti() == RttiValues.Rtti_Text):
                i = self.currentItem
                i.setColor(value)
        elif (id == "brush"):
            if (self.currentItem.rtti() == RttiValues.Rtti_Rectangle or self.currentItem.rtti() == RttiValues.Rtti_Ellipse):
                i = self.currentItem
                b = QBrush(i.brush())
                b.setColor(value)
                i.setBrush(b)
        elif (id == "pen"):
            if (self.currentItem.rtti() == RttiValues.Rtti_Rectangle or self.currentItem.rtti() == RttiValues.Rtti_Line):
                i = self.currentItem
                p = QPen(i.pen())
                p.setColor(value)
                i.setPen(p)
        elif (id == "font"):
            if (self.currentItem.rtti() == RttiValues.Rtti_Text):
                i = self.currentItem
                i.setFont(value)
        elif (id == "endpoint"):
            if (self.currentItem.rtti() == RttiValues.Rtti_Line):
                i = self.currentItem
                p = value
                i.setPoints(i.startPoint().x(), i.startPoint().y(), p.x(), p.y())
        elif (id == "size"):
            if (self.currentItem.rtti() == RttiValues.Rtti_Rectangle):
                i = self.currentItem
                s = value
                i.setSize(s.width(), s.height())
            elif (self.currentItem.rtti() == RttiValues.Rtti_Ellipse):
                i = self.currentItem
                s = value
                i.setSize(s.width(), s.height())
        self.canvas.update()