Beispiel #1
0
    def __init__(self, dimension, textureAtlas, geometryCache, shareGLWidget,
                 *args, **kwargs):
        super(CameraWorldViewFrame, self).__init__(*args, **kwargs)

        self.worldView = view = CameraWorldView(dimension, textureAtlas,
                                                geometryCache, shareGLWidget)

        auxControlWidget = QtGui.QWidget()

        StickyMouselookSetting.connectAndCall(view.setStickyMouselook)

        stickyCheckbox = QtGui.QCheckBox(self.tr("Sticky Mouselook"))
        stickyCheckbox.setChecked(StickyMouselookSetting.value())
        stickyCheckbox.toggled.connect(StickyMouselookSetting.setValue)

        auxControlWidget.setLayout(Column(stickyCheckbox))

        self.viewControls = ViewControls(view, auxControlWidget)

        ViewDistanceSetting.connectAndCall(view.setViewDistance)

        viewDistanceInput = QtGui.QSpinBox(minimum=2, maximum=64, singleStep=2)
        viewDistanceInput.setValue(self.worldView.viewDistance)
        viewDistanceInput.valueChanged.connect(ViewDistanceSetting.setValue)

        MaxViewDistanceSetting.connectAndCall(viewDistanceInput.setMaximum)

        PerspectiveSetting.connectAndCall(view.setPerspective)

        perspectiveInput = QtGui.QCheckBox(self.tr("Perspective"))
        perspectiveInput.setChecked(view.perspective)
        perspectiveInput.toggled.connect(PerspectiveSetting.setValue)

        showButton = QtGui.QPushButton(self.tr("Show..."))
        showButton.setMenu(view.layerToggleGroup.menu)

        workplaneCheckbox = QtGui.QCheckBox(self.tr("Work Plane"))
        workplaneSpinSlider = SpinSlider()
        workplaneSpinSlider.setValue(64)
        workplaneSpinSlider.setMinimum(dimension.bounds.miny)
        workplaneSpinSlider.setMaximum(dimension.bounds.maxy)

        workplaneCheckbox.toggled.connect(view.toggleWorkplane)

        workplaneSpinSlider.valueChanged.connect(view.setWorkplaneLevel)

        self.setLayout(
            Column(Row(None,
                       workplaneCheckbox,
                       workplaneSpinSlider,
                       showButton,
                       perspectiveInput,
                       QtGui.QLabel(self.tr("View Distance:")),
                       viewDistanceInput,
                       self.viewControls.getShowHideButton(),
                       margin=0),
                   view,
                   margin=0))
Beispiel #2
0
    def __init__(self, editorSession):
        super(LSystemPlugin, self).__init__(editorSession)
        self.optionsWidget = None

        self.iterationsSlider = SpinSlider()
        self.iterationsSlider.setMinimum(1)
        self.iterationsSlider.setMaximum(50)
        self.iterationsSlider.setValue(3)
        self.iterationsSlider.valueChanged.connect(self.updatePreview)
Beispiel #3
0
    def getOptionsWidget(self):
        if self.optionsWidget:
            return self.optionsWidget

        widget = QtGui.QWidget()
        self.trunkSlider = SpinSlider()
        self.trunkSlider.setValue(1)
        widget.setLayout(Column(self.trunkSlider, None))
        self.optionsWidget = widget
        return widget
Beispiel #4
0
    def widgetFromOptDict(self, optDict):
        self.optIdx += 1

        type = optDict.get('type')
        if type is None or not isinstance(type, basestring):
            raise ValueError("Option dict must have 'type' key")

        if type in ('int', 'float'):
            minimum = optDict.get('min', None)
            maximum = optDict.get('max', None)

            value = optDict.get('value', 0)
            increment = optDict.get('increment', None)

            name = optDict.get('name', None)
            if name is None:
                raise ValueError("Option dict must have 'name' key")

            text = optDict.get('text', "Option %d" % self.optIdx)
            if minimum is None or maximum is None:
                if type == 'float':
                    widget = QtGui.QDoubleSpinBox(value=value)
                else:
                    widget = QtGui.QSpinBox(value=value)
                if minimum is not None:
                    widget.setMinimum(minimum)
                else:
                    widget.setMinimum(-2000000000)
                if maximum is not None:
                    widget.setMaximum(maximum)
                else:
                    widget.setMaximum(2000000000)

                if increment is not None:
                    widget.setSingleStep(increment)
            else:
                widget = SpinSlider(double=(type == 'float'),
                                    minimum=minimum,
                                    maximum=maximum,
                                    value=value,
                                    increment=increment)

            self.widgets.append(widget)

            self.formLayout.addRow(text, widget)
            self.valueGetters[name] = widget.value

        elif type == 'bool':
            value = optDict.get('value', False)
            name = optDict.get('name', None)
            if name is None:
                raise ValueError("Option dict must have 'name' key")

            text = optDict.get('text', "Option %d" % self.optIdx)
            widget = QtGui.QCheckBox()
            widget.setChecked(value)
            self.widgets.append(widget)

            self.formLayout.addRow(text, widget)
            self.valueGetters[name] = widget.isChecked

        elif type == 'text':
            value = optDict.get('value', '')
            name = optDict.get('name', None)
            placeholder = optDict.get('placeholder', None)

            if name is None:
                raise ValueError("Option dict must have 'name' key")

            text = optDict.get('text', "Option %d" % self.optIdx)
            widget = QtGui.QLineEdit()
            self.widgets.append(widget)
            if placeholder:
                widget.setPlaceholderText(placeholder)
            if value:
                widget.setText(value)

            self.formLayout.addRow(text, widget)
            self.valueGetters[name] = widget.text

        elif type == 'choice':
            value = optDict.get('value', None)
            name = optDict.get('name', None)
            if name is None:
                raise ValueError("Option dict must have 'name' key")

            choices = optDict.get('choices', [])

            text = optDict.get('text', "Option %d" % self.optIdx)
            widget = QtGui.QComboBox()
            self.widgets.append(widget)

            for label, key in choices:
                widget.addItem(label, key)
                if key == value:
                    widget.setCurrentIndex(widget.count() - 1)

            def getChoiceKey():
                return widget.itemData(widget.currentIndex())

            self.formLayout.addRow(text, widget)
            self.valueGetters[name] = getChoiceKey

        elif type == 'blocktype':
            value = optDict.get('value', None)
            name = optDict.get('name', None)
            if name is None:
                raise ValueError("Option dict must have 'name' key")

            text = optDict.get('text', "Option %d" % self.optIdx)
            widget = BlockTypeButton()
            widget.editorSession = self.editorSession
            self.widgets.append(widget)

            if value is not None:
                if not isinstance(value, BlockType):
                    value = self.editorSession.worldEditor.blocktypes[value]
                widget.block = value

            self.formLayout.addRow(text, widget)
            self.valueGetters[name] = lambda: widget.block

        elif type == 'label':
            text = optDict.get('text', None)
            if not text:
                raise ValueError(
                    "Option dict for type 'label' must have 'text' key.")
            widget = QtGui.QLabel(text, wordWrap=True)
            self.widgets.append(widget)

            self.formLayout.addRow("", widget)

        elif type == 'nbt':
            widget = QtGui.QLabel("Not Implemented")
            self.widgets.append(widget)

            self.formLayout.addRow("NBT Option: ", widget)
        else:
            raise ValueError("Unknown type %s for option dict" % type)