Beispiel #1
0
    def __init__(self, *args, **kwargs):
        addShapes = kwargs.pop('addShapes', None)
        super(ShapeWidget, self).__init__(*args, **kwargs)
        buttons = self.buttons = []
        self.groupBox = QtGui.QGroupBox("Shape:")

        flowLayout = flowlayout.FlowLayout()
        actionGroup = QtGui.QActionGroup(self)
        actionGroup.setExclusive(True)
        iconBase = resourcePath("mcedit2/assets/mcedit2/icons")
        actions = {}
        shapes = list(getShapes())
        if addShapes:
            shapes.extend(addShapes)

        for shape in shapes:
            if shape.icon is not None:
                filename = os.path.join(iconBase, shape.icon)
                assert os.path.exists(filename), "%r does not exist" % filename
                icon = QtGui.QIcon(filename)
                if icon is None:
                    log.warn("Failed to read shape icon file %s" % filename)
            else:
                icon = None

            def _handler(shape):
                def handler():
                    self.currentShape = shape
                    BrushShapeSetting.setValue(shape.ID)
                    self.shapeChanged.emit(shape)
                return handler
            if icon is None:
                action = QtGui.QAction(shape.ID, self, triggered=_handler(shape))
            else:
                action = QtGui.QAction(icon, shape.ID, self, triggered=_handler(shape))
            button = QtGui.QToolButton()
            action.setCheckable(True)
            button.setDefaultAction(action)
            button.setIconSize(QtCore.QSize(32, 32))
            buttons.append(button)
            flowLayout.addWidget(button)
            actionGroup.addAction(action)
            actions[shape.ID] = action
            shape.optionsChanged.connect(self.shapeOptionsChanged.emit)

        self.optionsHolder = QtGui.QStackedWidget()
        layout = Column(flowLayout, (self.optionsHolder, 1))
        self.groupBox.setLayout(layout)
        self.setLayout(Column(self.groupBox, margin=0))

        currentID = BrushShapeSetting.value(shapes[0].ID)
        shapesByID = {shape.ID: shape for shape in shapes}
        if currentID not in actions:
            currentID = shapes[0].ID
        actions[currentID].setChecked(True)

        self.currentShape = shapesByID.get(currentID, shapes[0])

        self.shapeChanged.connect(self.shapeDidChange)
        self.shapeDidChange(self.currentShape)
Beispiel #2
0
    def __init__(self, *args, **kwargs):
        super(ShapeWidget, self).__init__(*args, **kwargs)
        buttons = self.buttons = []
        layout = flowlayout.FlowLayout()
        actionGroup = QtGui.QActionGroup(self)
        actionGroup.setExclusive(True)
        iconBase = resourcePath("mcedit2/assets/mcedit2/icons")
        actions = {}
        for shape in Shapes.allShapes:
            filename = os.path.join(iconBase, shape.icon)
            assert os.path.exists(filename), "%r does not exist" % filename
            icon = QtGui.QIcon(filename)
            if icon is None:
                raise ValueError("Failed to read shape icon file %s" % filename)
            def _handler(shape):
                def handler():
                    self.currentShape = shape
                    BrushShapeSetting.setValue(shape.ID)
                    self.shapeChanged.emit()
                return handler
            action = QtGui.QAction(icon, shape.ID, self, triggered=_handler(shape))
            button = QtGui.QToolButton()
            action.setCheckable(True)
            button.setDefaultAction(action)
            button.setIconSize(QtCore.QSize(32, 32))
            buttons.append(button)
            layout.addWidget(button)
            actionGroup.addAction(action)
            actions[shape.ID] = action

        self.setLayout(layout)
        currentID = BrushShapeSetting.value(Shapes.allShapes[0].ID)
        shapesByID = {shape.ID:shape for shape in Shapes.allShapes}
        actions[currentID].setChecked(True)

        self.currentShape = shapesByID.get(currentID, Shapes.allShapes[0])
Beispiel #3
0
    def __init__(self, *args, **kwargs):
        addShapes = kwargs.pop('addShapes', None)
        super(ShapeWidget, self).__init__(*args, **kwargs)
        buttons = self.buttons = []
        flowLayout = flowlayout.FlowLayout()
        actionGroup = QtGui.QActionGroup(self)
        actionGroup.setExclusive(True)
        iconBase = resourcePath("mcedit2/assets/mcedit2/icons")
        actions = {}
        shapes = list(getShapes())
        if addShapes:
            shapes.extend(addShapes)
        for shape in shapes:
            if shape.icon is not None:
                filename = os.path.join(iconBase, shape.icon)
                assert os.path.exists(filename), "%r does not exist" % filename
                icon = QtGui.QIcon(filename)
                if icon is None:
                    log.warn("Failed to read shape icon file %s" % filename)
            else:
                icon = None

            def _handler(shape):
                def handler():
                    self.currentShape = shape
                    BrushShapeSetting.setValue(shape.ID)
                    self.shapeChanged.emit(shape)

                return handler

            if icon is None:
                action = QtGui.QAction(shape.ID,
                                       self,
                                       triggered=_handler(shape))
            else:
                action = QtGui.QAction(icon,
                                       shape.ID,
                                       self,
                                       triggered=_handler(shape))
            button = QtGui.QToolButton()
            action.setCheckable(True)
            button.setDefaultAction(action)
            button.setIconSize(QtCore.QSize(32, 32))
            buttons.append(button)
            flowLayout.addWidget(button)
            actionGroup.addAction(action)
            actions[shape.ID] = action
            shape.optionsChanged.connect(self.shapeOptionsChanged.emit)

        self.optionsHolder = QtGui.QStackedWidget()
        layout = Column(flowLayout, (self.optionsHolder, 1))
        self.setLayout(layout)

        currentID = BrushShapeSetting.value(shapes[0].ID)
        shapesByID = {shape.ID: shape for shape in shapes}
        if currentID not in actions:
            currentID = shapes[0].ID
        actions[currentID].setChecked(True)

        self.currentShape = shapesByID.get(currentID, shapes[0])

        self.shapeChanged.connect(self.shapeDidChange)
        self.shapeDidChange(self.currentShape)