Exemplo n.º 1
0
class GUISpacer(GUILeafComponent):
    componentName = 'Spacer'

    width = TypedEvalField(float, 10.0)
    height = TypedEvalField(float, 10.0)

    def _presentLeafContents(self, fragment, inheritedState):
        return Spacer(self.width.getValueForEditor(),
                      self.height.getValueForEditor())

    def _editUIFormSections(self):
        width = Form.SmallSection(
            'Width', None,
            self.width.editUI(
                lambda live: RealSpinEntry(live, 0.0, 1048576.0, 1.0, 10.0)))
        height = Form.SmallSection(
            'Height', None,
            self.height.editUI(
                lambda live: RealSpinEntry(live, 0.0, 1048576.0, 1.0, 10.0)))
        superSections = super(GUISpacer, self)._editUIFormSections()
        return [width, height] + superSections

    def __component_py_evalmodel__(self, codeGen):
        spacer = codeGen.embeddedValue(Spacer)
        return Py.Call(target=spacer,
                       args=[
                           self.width.__py_evalmodel__(codeGen),
                           self.height.__py_evalmodel__(codeGen)
                       ])
class UniformPadding (AbstractPadding):
	x = TypedEvalField(float, 0.0)
	y = TypedEvalField(float, 0.0)

	def editUI(self, setPaddingFn):
		box = _boxStyle(Bin(Label('Padded element'))).alignHExpand().alignVExpand()

		left = self.x.editUI(lambda live: RealSpinEntry(live, 0.0, 1048576.0, 1.0, 10.0))
		right = _liveLabel(self.x.constantValueLive)
		top = self.y.editUI(lambda live: RealSpinEntry(live, 0.0, 1048576.0, 1.0, 10.0))
		bottom = _liveLabel(self.y.constantValueLive)

		return _tableStyle(Table([[None, top, None], [left, box, right], [None, bottom, None]]))


	def apply(self, p):
		x = self.x.getValueForEditor()
		y = self.y.getValueForEditor()
		return Pres.coerce(p).pad(x, y)


	def __apply_py_evalmodel__(self, codeGen, py_p):
		x = self.x.__py_evalmodel__(codeGen)
		y = self.y.__py_evalmodel__(codeGen)

		py_pres = codeGen.embeddedValue(Pres)
		py_pres_coerce = Py.AttributeRef(target=py_pres, name='coerce')
		py_p = Py.Call(target=py_pres_coerce, args=[py_p])
		py_p = Py.Call(target=Py.AttributeRef(target=py_p, name='pad'), args=[x, y])

		return py_p
Exemplo n.º 3
0
class GUISpaceBin(GUIUnaryBranchComponent):
    componentName = 'Space bin'

    width = TypedEvalField(float, 100.0)
    height = TypedEvalField(float, 100.0)
    sizeConstraintX = TypedEvalField(LSSpaceBin.SizeConstraint,
                                     LSSpaceBin.SizeConstraint.LARGER)
    sizeConstraintY = TypedEvalField(LSSpaceBin.SizeConstraint,
                                     LSSpaceBin.SizeConstraint.LARGER)

    def _presentBranchContents(self, child, fragment, inheritedState):
        return SpaceBin(self.width.getValueForEditor(),
                        self.height.getValueForEditor(),
                        self.sizeConstraintX.getValueForEditor(),
                        self.sizeConstraintY.getValueForEditor(), child)

    def _presentEditableBranchContents(self, child, fragment, inheritedState):
        return SpaceBin(self.width.getValueForEditor(),
                        self.height.getValueForEditor(),
                        self.sizeConstraintX.getValueForEditor(),
                        self.sizeConstraintY.getValueForEditor(), child)

    def _editUIFormSections(self):
        width = Form.SmallSection(
            'Width', None,
            self.width.editUI(
                lambda live: RealSpinEntry(live, 0.0, 1048576.0, 1.0, 10.0)))
        height = Form.SmallSection(
            'Height', None,
            self.height.editUI(
                lambda live: RealSpinEntry(live, 0.0, 1048576.0, 1.0, 10.0)))
        sizeConstraintX = Form.SmallSection(
            'Constraint-X', None,
            self.sizeConstraintX.editUI(_sizeConstraintEditor))
        sizeConstraintY = Form.SmallSection(
            'Constraint-Y', None,
            self.sizeConstraintY.editUI(_sizeConstraintEditor))
        superSections = super(GUISpaceBin, self)._editUIFormSections()
        return [width, height, sizeConstraintX, sizeConstraintY
                ] + superSections

    def __component_py_evalmodel__(self, codeGen):
        py_spaceBin = codeGen.embeddedValue(SpaceBin)
        width = self.width.__py_evalmodel__(codeGen)
        height = self.height.__py_evalmodel__(codeGen)
        sizeConstraintX = self.sizeConstraintX.__py_evalmodel__(codeGen)
        sizeConstraintY = self.sizeConstraintY.__py_evalmodel__(codeGen)
        return Py.Call(target=py_spaceBin,
                       args=[
                           width, height, sizeConstraintX, sizeConstraintY,
                           self.child.node.__py_evalmodel__(codeGen)
                       ])
Exemplo n.º 4
0
class GUIArrow(GUILeafComponent):
    componentName = 'Arrow'

    size = TypedEvalField(float, 12.0)
    direction = TypedEvalField(Arrow.Direction, Arrow.Direction.RIGHT)

    def _presentLeafContents(self, fragment, inheritedState):
        return Arrow(self.direction.getValueForEditor(),
                     self.size.getValueForEditor())

    _offStyle = StyleSheet.style(
        Primitive.shapePainter(FillPainter(Color(0.4, 0.4, 0.4))))
    _onStyle = StyleSheet.style(
        Primitive.shapePainter(FillPainter(Color(0.2, 0.2, 0.2))))

    @staticmethod
    def _arrowDirectionEditor(live):
        offOptions = [
            GUIArrow._offStyle(Arrow(dir, 14.0).alignVCentre())
            for dir in Arrow.Direction.values()
        ]
        onOptions = [
            GUIArrow._onStyle(Arrow(dir, 14.0).alignVCentre())
            for dir in Arrow.Direction.values()
        ]

        return enumSwitchButtonEditor(live, Arrow.Direction, offOptions,
                                      onOptions)

    def _editUIFormSections(self):
        direction = Form.SmallSection(
            'Direction', None,
            self.direction.editUI(self._arrowDirectionEditor))
        size = Form.SmallSection(
            'Size', None,
            self.size.editUI(
                lambda live: RealSpinEntry(live, 0.0, 1048576.0, 1.0, 10.0)))
        superSections = super(GUIArrow, self)._editUIFormSections()
        return [direction, size] + superSections

    def __component_py_evalmodel__(self, codeGen):
        arrow = codeGen.embeddedValue(Arrow)
        direction = self.direction.__py_evalmodel__(codeGen)
        size = self.size.__py_evalmodel__(codeGen)
        return Py.Call(target=arrow, args=[direction, size])
Exemplo n.º 5
0
class _GUIUIText (GUILeafComponent):
	componentName = None
	__pres_type__ = None

	text = TypedEvalField(str, 'Text')

	def _presentLeafContents(self, fragment, inheritedState):
		assert self.__pres_type__ is not None, 'abstract'
		return self.__pres_type__(self.text.getValueForEditor())

	def _editUIFormSections(self):
		text = Form.SmallSection('Text', None, self.text.editUI(lambda live: TextEntry.textEntryCommitOnChange(live)))
		superSections = super(_GUIUIText, self)._editUIFormSections()
		return [text] + superSections

	def __component_py_evalmodel__(self, codeGen):
		assert self.__pres_type__ is not None, 'abstract'
		py_pres_type = codeGen.embeddedValue(self.__pres_type__)
		return Py.Call( target=py_pres_type, args=[ self.text.__py_evalmodel__(codeGen) ] )
Exemplo n.º 6
0
class GUIText(GUILeafComponent):
    componentName = 'Text'

    text = TypedEvalField(str, 'Label')

    def _presentLeafContents(self, fragment, inheritedState):
        return Text(self.text.getValueForEditor())

    def _editUIFormSections(self):
        text = Form.SmallSection(
            'Text', None,
            self.text.editUI(
                lambda live: TextEntry.textEntryCommitOnChange(live)))
        superSections = super(GUIText, self)._editUIFormSections()
        return [text] + superSections

    def __component_py_evalmodel__(self, codeGen):
        textPresClass = codeGen.embeddedValue(Text)
        return Py.Call(target=textPresClass,
                       args=[self.text.__py_evalmodel__(codeGen)])
class GUIComponent(GUINode):
    isRootGUIEditorComponent = False
    componentName = '<abstract-Component>'

    hAlignment = TypedEvalField([HAlignment, type(None)], None)
    vAlignment = TypedEvalField([VAlignment, type(None)], None)
    padding = TypedField([AbstractPadding, type(None)], None)

    def __init__(self, **values):
        super(GUIComponent, self).__init__(**values)

    @property
    def guiEditor(self):
        return self._parent.guiEditor if self._parent is not None else None

    def _presentContents(self, fragment, inheritedState):
        raise NotImplementedError, 'abstract'

    def _lookFor(self, x):
        return False

    def _editUI(self):
        return self._editUIForm()

    def _editUIForm(self):
        sections = self._editUIFormSections()
        if len(sections) > 0:
            return Form(None, sections)
        else:
            return Blank()

    def _editUIFormSections(self):
        hAlign = Form.SmallSection('H alignment', None,
                                   self.hAlignment.editUI(_hAlignmentEditor))
        vAlign = Form.SmallSection('V alignment', None,
                                   self.vAlignment.editUI(_vAlignmentEditor))

        @LiveFunction
        def paddingUI():
            padding = self.padding.value

            if padding is None:

                def onPadUniform(button, event):
                    self.padding.value = UniformPadding()

                def onPadNonUniform(button, event):
                    self.padding.value = NonUniformPadding()

                return ControlsRow([
                    Button.buttonWithLabel('Uniform', onPadUniform),
                    Button.buttonWithLabel('Non-uniform', onPadNonUniform)
                ]).alignHPack()
            else:

                def onRemove(button, event):
                    self.padding.value = None

                def setPadding(padding):
                    self.padding.value = padding

                removeButton = Button.buttonWithLabel('Remove padding',
                                                      onRemove).alignHPack()

                return Column([
                    removeButton.alignHPack(),
                    Spacer(0.0, 5.0),
                    padding.editUI(setPadding)
                ])

        padding = Form.SmallSection('Padding', None, paddingUI)

        return [hAlign, vAlign, padding]

    def __present__(self, fragment, inheritedState):
        hAlign = self.hAlignment.getValueForEditor()
        vAlign = self.vAlignment.getValueForEditor()
        p = self._presentContents(fragment, inheritedState)
        p = componentBorder.surround(p)
        padding = self.padding.value
        if padding is not None:
            p = padding.apply(p)
        if hAlign is not None:
            p = p.alignH(hAlign)
        if vAlign is not None:
            p = p.alignV(vAlign)
        p = p.withContextMenuInteractor(componentContextMenu)
        p = p.withElementInteractor(GUITargetInteractor())
        p = p.withElementInteractor(GUIScrollInteractor())
        p = p.withProperty(GUICProp.instance, self)
        return p

    def __py_evalmodel__(self, codeGen):
        hasHAlign = not self.hAlignment.isConstant(
        ) or self.hAlignment.constantValue is not None
        hasVAlign = not self.vAlignment.isConstant(
        ) or self.vAlignment.constantValue is not None
        hAlign = self.hAlignment.__py_evalmodel__(codeGen)
        vAlign = self.vAlignment.__py_evalmodel__(codeGen)
        py_p = self.__component_py_evalmodel__(codeGen)
        padding = self.padding.value
        if padding is not None:
            py_p = padding.__apply_py_evalmodel__(codeGen, py_p)
        if hasHAlign or hasVAlign:
            py_pres = codeGen.embeddedValue(Pres)
            py_pres_coerce = Py.AttributeRef(target=py_pres, name='coerce')
            py_p = Py.Call(target=py_pres_coerce, args=[py_p])
            if hasHAlign:
                py_p = Py.Call(target=Py.AttributeRef(target=py_p,
                                                      name='alignH'),
                               args=[hAlign])
            if hasVAlign:
                py_p = Py.Call(target=Py.AttributeRef(target=py_p,
                                                      name='alignV'),
                               args=[vAlign])
        return py_p

    def __component_py_evalmodel__(self, codeGen):
        raise NotImplementedError, 'abstract'
class SolidGUIBorder(AbstractGUIBorder):
    thickness = TypedEvalField(float, 1.0)
    inset = TypedEvalField(float, 1.0)
    roundingX = TypedEvalField(float, 0.0)
    roundingY = TypedEvalField(float, 0.0)
    borderPaint = TypedEvalField(Color, Color.BLACK)
    backgroundPaint = TypedEvalField((Color, type(None)), None)
    highlightBorderPaint = TypedEvalField((Color, type(None)), None)
    highlightBackgroundPaint = TypedEvalField((Color, type(None)), None)

    def formSections(self):
        return [
            Form.SmallSection(
                'Thickness', None,
                self.thickness.editUI(lambda live: RealSpinEntry(
                    live, 0.0, 10240.0, 0.1, 10.0))),
            Form.SmallSection(
                'Inset', None,
                self.inset.editUI(lambda live: RealSpinEntry(
                    live, 0.0, 10240.0, 0.1, 10.0))),
            Form.SmallSection(
                'Round-X', None,
                self.roundingX.editUI(lambda live: RealSpinEntry(
                    live, 0.0, 10240.0, 0.1, 10.0))),
            Form.SmallSection(
                'Round-Y', None,
                self.roundingY.editUI(lambda live: RealSpinEntry(
                    live, 0.0, 10240.0, 0.1, 10.0))),
            Form.SmallSection(
                'Border colour', None,
                self.borderPaint.editUI(
                    lambda live: ColourPicker(live).alignHPack())),
            Form.SmallSection(
                'Background colour', None,
                self.backgroundPaint.editUI(lambda live: optionalTypedEditor(
                    live, Color.WHITE, lambda live: ColourPicker(live).
                    alignHPack()))),
            Form.SmallSection(
                'Hover border colour', None,
                self.highlightBorderPaint.editUI(
                    lambda live: optionalTypedEditor(
                        live, Color.BLACK, lambda live: ColourPicker(live).
                        alignHPack()))),
            Form.SmallSection(
                'Hover background colour', None,
                self.highlightBackgroundPaint.editUI(
                    lambda live: optionalTypedEditor(
                        live, Color.WHITE, lambda live: ColourPicker(live).
                        alignHPack()))),
        ]

    def makeBorder(self):
        thickness = self.thickness.getValueForEditor()
        inset = self.inset.getValueForEditor()
        roundingX = self.roundingX.getValueForEditor()
        roundingY = self.roundingY.getValueForEditor()
        borderPaint = self.borderPaint.getValueForEditor()
        backgroundPaint = self.backgroundPaint.getValueForEditor()
        highlightBorderPaint = self.highlightBorderPaint.getValueForEditor()
        highlightBackgroundPaint = self.highlightBackgroundPaint.getValueForEditor(
        )
        return SolidBorder(thickness, inset, roundingX, roundingY, borderPaint,
                           backgroundPaint).highlight(
                               highlightBorderPaint, highlightBackgroundPaint)

    def __makeBorder_py_evalmodel__(self, codeGen):
        thickness = self.thickness.__py_evalmodel__(codeGen)
        inset = self.inset.__py_evalmodel__(codeGen)
        roundingX = self.roundingX.__py_evalmodel__(codeGen)
        roundingY = self.roundingY.__py_evalmodel__(codeGen)
        borderPaint = self.borderPaint.__py_evalmodel__(codeGen)
        backgroundPaint = self.backgroundPaint.__py_evalmodel__(codeGen)
        highlightBorderPaint = self.highlightBorderPaint.__py_evalmodel__(
            codeGen)
        highlightBackgroundPaint = self.highlightBackgroundPaint.__py_evalmodel__(
            codeGen)

        py_SolidBorder = codeGen.embeddedValue(SolidBorder)
        return Py.Call(target=py_SolidBorder,
                       args=[
                           thickness, inset, roundingX, roundingY, borderPaint,
                           backgroundPaint, highlightBorderPaint,
                           highlightBackgroundPaint
                       ])