def _indentSelection(self, selection):
        startMarker = selection.getStartMarker()
        endMarker = selection.getEndMarker()

        # Get the statements that contain the start and end markers
        startContext = getStatementContextFromElement(startMarker.getElement())
        endContext = getStatementContextFromElement(endMarker.getElement())
        # Get the statement elements
        startStmtElement = startContext.getFragmentContentElement()
        endStmtElement = endContext.getFragmentContentElement()

        # Get paths to start and end nodes, from the common root statement
        path0, path1 = getStatementContextPathsFromCommonRoot(
            startContext, endContext)
        root = path0[0]

        # Get the content element, not the fragment itself, otherwise editing operations that involve the module (top level) will trigger events that will NOT be caught
        rootElement = root.getFragmentContentElement()

        event = IndentPythonSelectionTreeEvent(self, rootElement)
        visitor = event.getRichStringVisitor()
        visitor.ignoreElementFixedValuesOnPath(
            startContext.getFragmentContentElement(), rootElement)
        visitor.ignoreElementFixedValuesOnPath(
            endContext.getFragmentContentElement(), rootElement)
        visitor.setElementPrefix(startStmtElement, Schema.Indent())
        visitor.setElementSuffix(endStmtElement, Schema.Dedent())

        bSuccess = root.getFragmentContentElement().postTreeEvent(event)
        if not bSuccess:
            print 'PythonSyntaxRecognizingController._indentSelection(): INDENT SELECTION FAILED'
예제 #2
0
 def test_ListTarget(self):
     self._buildTest(
         Py.ListTarget(
             targets=[Py.SingleTarget(name='t'),
                      Py.SingleTarget(name='v')]),
         ListTarget([SingleTarget('t'),
                     SingleTarget('v')]))
 def __py_execmodel__(self, codeGen):
     assigns = []
     for definition in self._definitions_:
         target = definition.target.model['target']
         value = definition.value.model['expr']
         assign = Py.AssignStmt(targets=[target], value=value)
         assigns.append(assign)
     return Py.PythonSuite(suite=assigns)
예제 #4
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)
 def _indentLine(self, element, fragment, node):
     event = PythonIndentTreeEvent()
     visitor = event.getRichStringVisitor()
     visitor.setElementPrefix(element, Schema.Indent())
     visitor.setElementSuffix(element, Schema.Dedent())
     bSuccess = element.postTreeEventToParent(event)
     if not bSuccess:
         print 'PythonSyntaxRecognizingController._indentLine(): INDENT LINE FAILED'
def _commitUnparsedStatment(model, value):
    withoutNewline = value[:-1]
    unparsed = Schema.UnparsedStmt(value=Schema.UNPARSED(
        value=withoutNewline.getItemValues()))
    # In some cases, we will be replacing @model with an UNPARSED node that contains a reference to @model.
    # Since pyReplaceNode calls model.become(), this causes severe problems, due to circular references.
    # The call to deepcopy eliminates this possibility.
    pyReplaceNode(model, deepcopy(unparsed))
예제 #7
0
 def test_IntLit(self):
     self._buildTest(
         Py.IntLiteral(value='123', numType='int', format='decimal'),
         IntLit(123))
     self._buildTest(
         Py.IntLiteral(value='123', numType='long', format='decimal'),
         IntLit(123L))
     self._buildTest(Py.IntLiteral(value='40', numType='int', format='hex'),
                     IntLit(64, format='hex'))
    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))
	def _statementsForExecutionAndEvaluationIntoValue(stmts, varName):
		for i in xrange( len( stmts ) - 1, -1, -1 ):
			stmt = stmts[i]
			if stmt.isInstanceOf( Schema.ExprStmt ):
				return stmts[:i] + [ Schema.AssignStmt( targets=[ Schema.SingleTarget( name=varName ) ], value=stmt['expr'] ) ] + stmts[i+1:]
			elif stmt.isInstanceOf( Schema.BlankLine )  or  stmt.isInstanceOf( Schema.CommentStmt ):
				pass
			else:
				break
		return deepcopy( stmts ) + [ Schema.AssignStmt( targets=[ Schema.SingleTarget( name=varName ) ], value=Schema.Load( name='None' ) ) ]
예제 #10
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
예제 #11
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
예제 #12
0
 def test_StrLit(self):
     self._buildTest(
         Py.StringLiteral(value='abc\\n',
                          format='ascii',
                          quotation='single'), StrLit('abc\n'))
     self._buildTest(
         Py.StringLiteral(value='abc\'\\n',
                          format='ascii',
                          quotation='single'), StrLit('abc\'\n'))
     self._buildTest(
         Py.StringLiteral(value='abc\\n',
                          format='unicode',
                          quotation='double'),
         StrLit('abc\n', format='unicode', quotation='double'))
 def _dedentLine(self, element, fragment, node):
     suite = node.getParent()
     suiteParent = suite.getParent()
     if not isTopLevel(suiteParent):
         # This statement is not within a top-level node
         event = PythonDedentTreeEvent()
         visitor = event.getRichStringVisitor()
         visitor.setElementPrefix(element, Schema.Dedent())
         visitor.setElementSuffix(element, Schema.Indent())
         bSuccess = element.postTreeEventToParent(event)
         if not bSuccess:
             print 'PythonSyntaxRecognizingController._dedentLine(): DEDENT LINE FAILED'
     else:
         print 'PythonSyntaxRecognizingController._dedentLine(): Attempted to dedent line in top-level module'
예제 #14
0
	def __py_execmodel__(self, codeGen):
		self._clear()

		prevTestingBlock = [ None ]


		# Use a guard to push self onto the TestingBlock stack
		def beginGuard(codeGen):
			prevTestingBlock[0] = AbstractInlineTest.__current_testing_block__
			AbstractInlineTest.__current_testing_block__ = self

		def endGuard(codeGen):
			AbstractInlineTest.__current_testing_block__ = prevTestingBlock[0]

		mainContent = codeGen.guard( beginGuard, Schema.PythonSuite( suite=self._suite.model['suite'] ), endGuard )


		# Defer the generation of the unit test class
		@codeGen.deferred
		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 )


		return Schema.PythonSuite( suite=[ mainContent, unitTesting ] )
예제 #15
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)
                    ])
 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=[])
	def _createTestClassBodyStmts(self, codeGen, testedBlock):
		stmts = []
		first = True
		for test in self._tests:
			if not first:
				stmts.append( Schema.BlankLine() )
			test._regsiterTestTable( self )
			stmts.append( test._createMethodAST( codeGen ) )
			first = False
		return stmts
예제 #18
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)
                    ])
예제 #19
0
	def __init__(self, model=None):
		if isinstance( model, DMNode )  and  model.isInstanceOf( Schema.PythonModule ):
			pass
		elif model is None:
			model = _py25NewModule()
		elif isinstance( model, list )  or  isinstance( model, java.util.List ):
			model = Schema.PythonModule( suite=model )
		else:
			raise TypeError, 'Cannot construct EmbeddedPython2Module from %s' % model

		super(EmbeddedPython2Module, self).__init__( model )
예제 #20
0
	def __init__(self, model=None):
		if model is None:
			model = _py25NewExpr()
		elif isinstance( model, DMNode ):
			if model.isInstanceOf( Schema.PythonExpression ):
				pass
			else:
				model = Schema.PythonExpression( expr=model )
		else:
			raise TypeError, 'Cannot construct EmbeddedPython2Expr from %s' % model

		super(EmbeddedPython2Expr, self).__init__( model )
예제 #21
0
	def __init__(self, model=None):
		if model is None:
			model = _py25NewTarget()
		elif isinstance( model, DMNode ):
			if model.isInstanceOf( Schema.PythonTarget ):
				pass
			else:
				model = Schema.PythonTarget( target=model )
		else:
			raise TypeError, 'Cannot construct EmbeddedPython2Target from %s' % model

		super(EmbeddedPython2Target, self).__init__( model )
    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))
    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))
예제 #24
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
                       ])
 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
예제 #26
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) ] )
	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])
	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)])
	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])
	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)])