コード例 #1
0
    def test_EvalField_editor(self):
        c = self.EvalFieldTest()

        codeGen = Python2CodeGenerator('test')

        c.x.constantValue = 10.0
        c.y.constantValue = 20.0

        self.assertEqual(10.0, c.x.getValueForEditor())
        self.assertEqual(20.0, c.y.getValueForEditor())

        self.assertEqual(
            Py.Call(target=Py.Load(name='C'),
                    args=[
                        Py.FloatLiteral(value='10.0'),
                        Py.FloatLiteral(value='20.0')
                    ]), c.__py_evalmodel__(codeGen))

        x_expr = EmbeddedPython2Expr.fromText('a+b')
        y_expr = EmbeddedPython2Expr.fromText('c+d')
        c.x.expr = x_expr
        c.y.expr = y_expr

        self.assertEqual(10.0, c.x.getValueForEditor())
        self.assertEqual(20.0, c.y.getValueForEditor())

        self.assertEqual(
            Py.Call(target=Py.Load(name='C'),
                    args=[x_expr.model, y_expr.model]),
            c.__py_evalmodel__(codeGen))
コード例 #2
0
    def test_ChildField_editor(self):
        a1 = self.TypedFieldTest(x=10, y=20)
        a2 = self.TypedFieldTest(x=3, y=4)
        b = self.ChildFieldTest(p=a1, q=[a2])

        codeGen = Python2CodeGenerator('test')

        self.assertEqual(a1, b.p.getValueForEditor())
        self.assertEqual([a2], b.q.getValueForEditor())

        self.assertEqual(
            Py.Call(target=Py.Load(name='B'),
                    args=[
                        Py.Call(target=Py.Load(name='A'),
                                args=[
                                    Py.IntLiteral(format='decimal',
                                                  numType='int',
                                                  value='10'),
                                    Py.IntLiteral(format='decimal',
                                                  numType='int',
                                                  value='20')
                                ]),
                        Py.ListLiteral(values=[
                            Py.Call(target=Py.Load(name='A'),
                                    args=[
                                        Py.IntLiteral(format='decimal',
                                                      numType='int',
                                                      value='3'),
                                        Py.IntLiteral(format='decimal',
                                                      numType='int',
                                                      value='4')
                                    ])
                        ])
                    ]), b.__py_evalmodel__(codeGen))
コード例 #3
0
		def unitTesting(codeGen):
			# Create the class suite
			first = True
			testing = []
			for test in self._inlineTests:
				if not first:
					testing.append( Schema.BlankLine() )
					testing.append( Schema.BlankLine() )
				testing.append( test._createTestClass( codeGen ) )
				first = False

			testing.append( Schema.BlankLine() )
			testing.append( Schema.BlankLine() )

			for test in self._inlineTests:
				testAst = codeGen.embeddedValue( test )
				testing.append( Schema.ExprStmt( expr=Schema.Call( target=Schema.AttributeRef( target=testAst, name='_registerTestClass' ), args=[ Schema.Load( name=test._className ) ] ) ) )

			selfAST = codeGen.embeddedValue( self )
			moduleAST = codeGen.embeddedValue( codeGen.module )
			globalsAST = Schema.Call( target=Schema.Load( name='globals' ), args=[] )
			localsAST = Schema.Call( target=Schema.Load( name='locals' ), args=[] )
			testing.append( Schema.ExprStmt( expr=Schema.Call( target=Schema.AttributeRef( target=selfAST, name='runTests' ), args=[] ) ) )
			testing.append( Schema.ExprStmt( expr=Schema.Call( target=Schema.AttributeRef( target=selfAST, name='_registerScope' ), args=[ moduleAST, globalsAST, localsAST ] ) ) )

			return Schema.PythonSuite( suite=testing )
コード例 #4
0
	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
コード例 #5
0
	def __apply_py_evalmodel__(self, codeGen, py_p):
		left = self.left.__py_evalmodel__(codeGen)
		right = self.right.__py_evalmodel__(codeGen)
		top = self.top.__py_evalmodel__(codeGen)
		bottom = self.bottom.__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=[left, right, top, bottom])

		return py_p
コード例 #6
0
 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)
                    ])
コード例 #7
0
    def test_TypedField_editor(self):
        a = self.TypedFieldTest(x=10, y=20)

        codeGen = Python2CodeGenerator('test')

        self.assertEqual(10, a.x.getValueForEditor())
        self.assertEqual(20, a.y.getValueForEditor())

        self.assertEqual(
            Py.IntLiteral(format='decimal', numType='int', value='10'),
            a.x.__py_evalmodel__(codeGen))
        self.assertEqual(
            Py.IntLiteral(format='decimal', numType='int', value='20'),
            a.y.__py_evalmodel__(codeGen))

        self.assertEqual(
            Py.Call(target=Py.Load(name='A'),
                    args=[
                        Py.IntLiteral(format='decimal',
                                      numType='int',
                                      value='10'),
                        Py.IntLiteral(format='decimal',
                                      numType='int',
                                      value='20')
                    ]), a.__py_evalmodel__(codeGen))
コード例 #8
0
 def __component_py_evalmodel__(self, codeGen):
     child = self.child
     if child is not None:
         return child.__py_evalmodel__(codeGen)
     else:
         blank = codeGen.embeddedValue(Blank)
         return Py.Call(target=blank, args=[])
コード例 #9
0
 def __component_py_evalmodel__(self, codeGen):
     flowGrid = codeGen.embeddedValue(FlowGrid)
     targetNumColumns = self._targetNumColumns.getValue()
     args = []
     if targetNumColumns is not None:
         args.append(Py.IntLiteral(value=repr(targetNumColumns)))
     args.append(self._py_evalmodel_forChildren(codeGen))
     return Py.Call(target=flowGrid, args=args)
コード例 #10
0
    def test_ExprField_py_evalmodel(self):
        x_expr = EmbeddedPython2Expr.fromText('a+b')
        d = self.ExprFieldTest(x=x_expr)

        codeGen = Python2CodeGenerator('test')

        self.assertEqual(
            Py.Call(target=Py.Load(name='D'), args=[x_expr.model]),
            d.__py_evalmodel__(codeGen))
コード例 #11
0
	def _createMethodAST(self, codeGen):
		valueStmts, resultVarName = self._createValueStmtsAndResultVarName( codeGen )

		JythonExceptionAST = codeGen.embeddedValue( JythonException )
		sysAST = codeGen.embeddedValue( sys )
		getCurrentExceptionCallAST = Schema.Call( target=Schema.AttributeRef( target=JythonExceptionAST, name='getCurrentException' ), args=[] )
		getExcInfoTypeAST = Schema.Subscript( target=Schema.Call( target=Schema.AttributeRef( target=sysAST, name='exc_info' ), args=[] ),
						      index=Schema.IntLiteral( format='decimal', numType='int', value='0' ) )
		selfAST = codeGen.embeddedValue( self )
		testValueAST = Schema.AttributeRef( target=selfAST, name='_testValue' )
		kindExceptionAST = Schema.StringLiteral( format='ascii', quotation='single', value='exception' )
		kindValueAST = Schema.StringLiteral( format='ascii', quotation='single', value='value' )

		exceptStmts = [ Schema.ExprStmt( expr=Schema.Call( target=testValueAST, args=[ kindExceptionAST, getCurrentExceptionCallAST, getExcInfoTypeAST ] ) ) ]
		elseStmts = [ Schema.ExprStmt( expr=Schema.Call( target=testValueAST, args=[ kindValueAST, Schema.Load( name=resultVarName ) ] ) ) ]
		methodBody = [ Schema.TryStmt( suite=valueStmts, exceptBlocks=[ Schema.ExceptBlock( suite=exceptStmts ) ], elseSuite=elseStmts ) ]

		methodAST = Schema.DefStmt( name=self._methodName, decorators=[], params=[ Schema.SimpleParam( name='self' ) ], suite=methodBody )
		return methodAST
コード例 #12
0
 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)
                    ])
コード例 #13
0
 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
コード例 #14
0
    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
                       ])
コード例 #15
0
def blankCallModel(codeGen):
    blank = codeGen.embeddedValue(Blank)
    return Py.Call(target=blank, args=[])
コード例 #16
0
 def __component_py_evalmodel__(self, codeGen):
     textPresClass = codeGen.embeddedValue(Text)
     return Py.Call(target=textPresClass,
                    args=[self.text.__py_evalmodel__(codeGen)])
コード例 #17
0
 def __component_py_evalmodel__(self, codeGen):
     label = codeGen.embeddedValue(Label)
     return Py.Call(target=label,
                    args=[self.text.__py_evalmodel__(codeGen)])
コード例 #18
0
	def __component_py_evalmodel__(self, codeGen):
		onClick = self.onClick.__py_evalmodel__(codeGen)
		button = codeGen.embeddedValue(Button)
		child = self.child
		childArg = child.__py_evalmodel__(codeGen)   if child is not None   else blankCallModel(codeGen)
		return Py.Call(target=button, args=[childArg, onClick])
コード例 #19
0
 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])
コード例 #20
0
	def __py_evalmodel__(self, codeGen):
		py_richSpanClass = codeGen.embeddedValue(RichSpan)
		richSpan = Py.Call(target=py_richSpanClass, args=[self._contents_py_evalmodel_(codeGen)])

		py_styleSheet = codeGen.embeddedValue(self._styleSheet)
		return Py.Call(target=Py.AttributeRef(target=py_styleSheet, name='applyTo'), args=[richSpan])
コード例 #21
0
 def __component_py_evalmodel__(self, codeGen):
     paragraph = codeGen.embeddedValue(Paragraph)
     return Py.Call(target=paragraph,
                    args=[self._py_evalmodel_forChildren(codeGen)])
コード例 #22
0
 def __component_py_evalmodel__(self, codeGen):
     column = codeGen.embeddedValue(Column)
     return Py.Call(target=column,
                    args=[self._py_evalmodel_forChildren(codeGen)])
コード例 #23
0
 def __component_py_evalmodel__(self, codeGen):
     liveFun = codeGen.embeddedValue(LiveFunction)
     lmb = Py.LambdaExpr(params=[], expr=self.expr.expr.model)
     live = Py.Call(target=liveFun, args=[lmb])
     return live
コード例 #24
0
 def __component_py_evalmodel__(self, codeGen):
     staticText = codeGen.embeddedValue(StaticText)
     return Py.Call(target=staticText,
                    args=[self.text.__py_evalmodel__(codeGen)])
コード例 #25
0
	def __py_evalmodel__(self, codeGen):
		combinatorClass = self._styleMap[self._style.value]
		py_combinatorClass = codeGen.embeddedValue(combinatorClass)
		return Py.Call(target=py_combinatorClass, args=[self._contents_py_evalmodel_(codeGen)])
コード例 #26
0
 def __component_py_evalmodel__(self, codeGen):
     py_bin = codeGen.embeddedValue(Bin)
     return Py.Call(target=py_bin,
                    args=[self.child.node.__py_evalmodel__(codeGen)])
コード例 #27
0
	def __py_evalmodel__(self, codeGen):
		py_body = codeGen.embeddedValue(Body)
		coerceObj = lambda x: x.__py_evalmodel__(codeGen)
		return Py.Call(target=py_body, args=[Py.coerceToModel(self._contents.value[:], coerceObj=coerceObj)])
コード例 #28
0
 def __component_py_evalmodel__(self, codeGen):
     rGrid = codeGen.embeddedValue(RGrid)
     return Py.Call(target=rGrid,
                    args=[self._py_evalmodel_forChildren(codeGen)])
コード例 #29
0
	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) ] )
コード例 #30
0
 def __component_py_evalmodel__(self, codeGen):
     gridRow = codeGen.embeddedValue(GridRow)
     return Py.Call(target=gridRow,
                    args=[self._py_evalmodel_forChildren(codeGen)])