Python System.Collections.Generic.List() Examples

The following are 23 code examples of System.Collections.Generic.List(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module System.Collections.Generic , or try the search function .
Example #1
Source File: test_list.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
def test_generic_list(self):
        """https://github.com/IronLanguages/ironpython2/issues/109"""
        from System.Collections.Generic import List
        lst = List[str]()
        lst.Add('Hello')
        lst.Add('World')
        vals = []
        for v in lst[1:]:
            vals.append(v)
        self.assertEqual(vals, ['World']) 
Example #2
Source File: test_ipyc.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def CompileAsDll(fileName, assemblyName):
    sources = List[str]()
    sources.Add(fileName)
    pc = PythonCompiler(sources, assemblyName)
    pc.TargetKind = System.Reflection.Emit.PEFileKinds.Dll
    pc.Compile() 
Example #3
Source File: test_helpers.py    From mikeio with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_safe_length_returns_length_for_net_list():

    a = List[Int32]()
    a.Add(1)
    a.Add(2)
    a.Add(6)

    n = safe_length(a)

    assert n==3 
Example #4
Source File: __splines.py    From compas with MIT License 5 votes vote down vote up
def DrawForeground(self, e):

        lines = List[Line](self.lines_count)
        for i, j in self.lines:
            sp = self.points[i]
            ep = self.points[j]
            lines.Add(Line(Point3d(*sp), Point3d(*ep)))
        e.Display.DrawLines(lines, self.color, self.thickness)
        for i, (u, v) in enumerate(self.splines):
            sp = self.points[u]
            ep = self.points[v]
            th = self.spline_thickness[i]
            e.Display.DrawLine(Line(Point3d(*sp), Point3d(*ep)), self.spline_color, th)


# ==============================================================================
# Main
# ============================================================================== 
Example #5
Source File: mesh.py    From compas with MIT License 5 votes vote down vote up
def DrawForeground(self, e):
        draw_line = e.Display.DrawLine
        draw_lines = e.Display.DrawLines

        if self.color:
            if self.thickness:
                for i, start, end in self.lines:
                    draw_line(start, end, self.color[i], self.thickness[i])
            else:
                for i, start, end in self.lines:
                    draw_line(start, end, self.color[i], self._default_thickness)

        elif self.thickness:
            if self.color:
                for i, start, end in self.lines:
                    draw_line(start, end, self.color[i], self.thickness[i])
            else:
                for i, start, end in self.lines:
                    draw_line(start, end, self._default_color, self.thickness[i])

        else:
            lines = List[Line](self.mesh.number_of_edges())
            for i, start, end in self.lines:
                lines.Add(Line(start, end))
            draw_lines(lines, self._default_color, self._default_thickness)


# ==============================================================================
# Main
# ============================================================================== 
Example #6
Source File: lines.py    From compas with MIT License 5 votes vote down vote up
def DrawForeground(self, e):
        try:
            if self.color:
                draw = e.Display.DrawLine
                if self.thickness:
                    for i, (start, end) in enumerate(self.lines):
                        draw(Point3d(*start), Point3d(*end), self.color[i], self.thickness[i])
                else:
                    for i, (start, end) in enumerate(self.lines):
                        draw(Point3d(*start), Point3d(*end), self.color[i], self._default_thickness)

            elif self.thickness:
                draw = e.Display.DrawLine
                if self.color:
                    for i, (start, end) in enumerate(self.lines):
                        draw(Point3d(*start), Point3d(*end), self.color[i], self.thickness[i])
                else:
                    for i, (start, end) in enumerate(self.lines):
                        draw(Point3d(*start), Point3d(*end), self._default_color, self.thickness[i])

            else:
                lines = List[Line](len(self.lines))
                for start, end in self.lines:
                    lines.Add(Line(Point3d(*start), Point3d(*end)))
                e.Display.DrawLines(lines, self._default_color, self._default_thickness)
        except Exception as e:
            print(e)


# ==============================================================================
# Main
# ============================================================================== 
Example #7
Source File: points.py    From compas with MIT License 5 votes vote down vote up
def DrawForeground(self, e):
        try:
            if self.color:
                draw = e.Display.DrawPoint
                if self.size:
                    for xyz, size, color in zip(self.points, self.size, self.color):
                        draw(Point3d(*xyz), Simple, size, color)
                else:
                    for xyz, color in zip(self.points, self.color):
                        draw(Point3d(*xyz), Simple, self._default_size, color)
            elif self.size:
                draw = e.Display.DrawPoint
                if self.color:
                    for xyz, size, color in zip(self.points, self.size, self.color):
                        draw(Point3d(*xyz), Simple, size, color)
                else:
                    for xyz, size in zip(self.points, self.size):
                        draw(Point3d(*xyz), Simple, size, self._default_color)
            else:
                points = List[Point3d](len(self.points))
                for xyz in self.points:
                    points.Add(Point3d(*xyz))
                e.Display.DrawPoints(points, Simple, self._default_size, self._default_color)
        except Exception as e:
            print(e)


# ==============================================================================
# Main
# ============================================================================== 
Example #8
Source File: Misc_IFailuresPreprocessor.py    From revitapidocs.code with MIT License 5 votes vote down vote up
def PreprocessFailures(self, failuresAccessor):
        fail_list = List[FailureMessageAccessor]()
        fail_acc_list = failuresAccessor.GetFailureMessages().GetEnumerator()
        for failure in fail_acc_list:
            failure_id = failure.GetFailureDefinitionId()
            failure_severity = failure.GetSeverity()
            failure_type = BuiltInFailures.RoomFailures.RoomNotEnclosed
            if failure_id == failure_type:
                print("{0} with id: {1} of type: RoomNotEnclosed removed!".format(failure_severity, failure_id.Guid))
                failuresAccessor.DeleteWarning(failure)
        return FailureProcessingResult.Continue


# "Start" the transaction 
Example #9
Source File: test_ipyc.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def CheckIncludeDebugInformation(fileName, assemblyName, include):
    sources = List[str]()
    sources.Add(fileName)
    pc = PythonCompiler(sources, assemblyName)
    pc.IncludeDebugInformation = include
    pc.Compile() 
Example #10
Source File: test_ipyc.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def UsingReference(fileName, typeName, assemblyName):
    sources = List[str]()
    sources.Add(fileName)
    pc = PythonCompiler(sources, assemblyName)
    pc.MainFile = fileName
    refAsms = List[str]()
    refAsms.Add(System.Type.GetType(typeName).Assembly.FullName)
    pc.ReferencedAssemblies = refAsms
    pc.Compile() 
Example #11
Source File: test_ipyc.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def CompileOneFileAsConsoleApp2(fileName, assemblyName):
    sources = List[str]()
    sources.Add(fileName)
    pc = PythonCompiler(sources, assemblyName)
    pc.MainFile = "NotExistFile"
    pc.Compile() 
Example #12
Source File: test_ipyc.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def CompileOneFileAsConsoleApp1(fileName, assemblyName, setMainFile) :
    sources = List[str]()
    sources.Add(fileName)
    pc = PythonCompiler(sources, assemblyName)
    if setMainFile:
        pc.MainFile = fileName
    pc.Compile() 
Example #13
Source File: test_regressions.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def test_ipy2_gh39(self):
        """https://github.com/IronLanguages/ironpython2/issues/39"""

        from System.Collections.Generic import List

        rng = range(10000)
        lst = List[object](rng)
        it = iter(lst)

        # Loop compilation occurs after 100 iterations, however it occurs in parallel.
        # Use a number >> 100 so that we actually hit the compiled code.
        for i in rng:
            self.assertEqual(i, next(it)) 
Example #14
Source File: test_list.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def test_generic_list(self):
        """https://github.com/IronLanguages/ironpython2/issues/109"""
        from System.Collections.Generic import List
        lst = List[str]()
        lst.Add('Hello')
        lst.Add('World')
        vals = []
        for v in lst[1:]:
            vals.append(v)
        self.assertEqual(vals, ['World'])
        lst.Add('Universe')
        self.assertEqual(list(lst[0::2]), ['Hello', 'Universe']) 
Example #15
Source File: ElementType.AdaptiveBySimpleGeometry.py    From SpringNodes with MIT License 5 votes vote down vote up
def PreprocessFailures(self, fa):
		failList = List[FailureMessageAccessor](fa.GetFailureMessages() )
		for failure in failList:
			failID = failure.GetFailureDefinitionId()
			if failID == BuiltInFailures.InaccurateFailures.InaccurateLine\
			or failID == BuiltInFailures.OverlapFailures.DuplicatePoints :
				fa.DeleteWarning(failure)
		return FailureProcessingResult.Continue 
Example #16
Source File: test_ipyc.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def CheckIncludeDebugInformation(fileName, assemblyName, include):
    sources = List[str]()
    sources.Add(fileName)
    pc = PythonCompiler(sources, assemblyName)
    pc.IncludeDebugInformation = include
    pc.Compile() 
Example #17
Source File: test_ipyc.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def UsingReference(fileName, typeName, assemblyName):
    sources = List[str]()
    sources.Add(fileName)
    pc = PythonCompiler(sources, assemblyName)
    pc.MainFile = fileName
    refAsms = List[str]()
    refAsms.Add(System.Type.GetType(typeName).Assembly.FullName)
    pc.ReferencedAssemblies = refAsms
    pc.Compile() 
Example #18
Source File: test_ipyc.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def CompileOneFileAsConsoleApp2(fileName, assemblyName):
    sources = List[str]()
    sources.Add(fileName)
    pc = PythonCompiler(sources, assemblyName)
    pc.MainFile = "NotExistFile"
    pc.Compile() 
Example #19
Source File: test_ipyc.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def CompileOneFileAsConsoleApp1(fileName, assemblyName, setMainFile) :
    sources = List[str]()
    sources.Add(fileName)
    pc = PythonCompiler(sources, assemblyName)
    if setMainFile:
        pc.MainFile = fileName
    pc.Compile() 
Example #20
Source File: test_ipyc.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def CompileAsDll(fileName, assemblyName):
    sources = List[str]()
    sources.Add(fileName)
    pc = PythonCompiler(sources, assemblyName)
    pc.TargetKind = System.Reflection.Emit.PEFileKinds.Dll
    pc.Compile() 
Example #21
Source File: test_regressions.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def test_ipy2_gh39(self):
        """https://github.com/IronLanguages/ironpython2/issues/39"""

        from System.Collections.Generic import List

        rng = range(10000)
        lst = List[object](rng)
        it = iter(lst)

        # Loop compilation occurs after 100 iterations, however it occurs in parallel.
        # Use a number >> 100 so that we actually hit the compiled code.
        for i in rng:
            self.assertEqual(i, next(it)) 
Example #22
Source File: bar.py    From pyrevitplus with GNU General Public License v3.0 4 votes vote down vote up
def make_loops(self):
        start_x = self.start_x
        start_y = self.start_y
        end_x = start_x + self.width
        end_y = start_y + self.height
        p1 = XYZ(start_x, start_y, 0.0)
        p2 = XYZ(end_x, start_y, 0.0)
        p3 = XYZ(end_x, end_y, 0.0)
        p4 = XYZ(start_x, end_y, 0.0)
        p5 = XYZ(start_x, start_y, 0.0)
        points = [p1, p2, p3, p4, p5]

        profileloop = CurveLoop()
        profileloops = List[CurveLoop]()

        for n, p in enumerate(points):
            try:
                line = Line.CreateBound(points[n], points[n + 1])
            except:
                continue
            else:
                profileloop.Append(line)
        try:
            profileloops.Add(profileloop)
        except Exception as errmsg:
            dialog('Something wrong processing points: {}'.format(self.points))
            # ADD LOGGER
            logger.error('width: {}'.format(self.width))
            logger.error('height: {}'.format(self.height))
            logger.error('start_x: {}'.format(start_x))
            logger.error('start_y: {}'.format(start_y))
            for n, point in enumerate(points):
                logger.error('Point {}:{}'.format(n, point))

        # Defines Location for Label and Value Label
        label_x = start_x - self.label_padding
        label_y = start_y + (self.height / 2)
        value_label_x = start_x + self.width + self.label_padding
        value_label_y = label_y
        self.label_pt = XYZ(label_x, label_y, 0)
        self.value_label_pt = XYZ(value_label_x, value_label_y, 0)

        return profileloops 
Example #23
Source File: drawing.py    From compas with MIT License 4 votes vote down vote up
def draw_breps(faces, srf=None, u=10, v=10, trim=True, tangency=True, spacing=0.1, flex=1.0, pull=1.0, **kwargs):
    """Draw polygonal faces as Breps, and optionally set individual name, color,
    and layer properties.
    """
    guids = []
    for f in iter(faces):
        points = f['points']
        name = f.get('name', '')
        color = f.get('color')
        layer = f.get('layer')
        corners = [Point3d(*point) for point in points]
        pcurve = PolylineCurve(corners)
        geo = List[GeometryBase](1)
        geo.Add(pcurve)
        p = len(points)
        if p == 4:
            brep = Brep.CreateFromCornerPoints(Point3d(*points[0]),
                                               Point3d(*points[1]),
                                               Point3d(*points[2]),
                                               TOL)
        elif p == 5:
            brep = Brep.CreateFromCornerPoints(Point3d(*points[0]),
                                               Point3d(*points[1]),
                                               Point3d(*points[2]),
                                               Point3d(*points[3]),
                                               TOL)
        else:
            brep = Brep.CreatePatch(geo, u, v, TOL)
        if not brep:
            continue
        guid = add_brep(brep)
        if not guid:
            continue
        obj = find_object(guid)
        if not obj:
            continue
        attr = obj.Attributes
        if color:
            attr.ObjectColor = FromArgb(*color)
            attr.ColorSource = ColorFromObject
        else:
            attr.ColorSource = ColorFromLayer
        if layer and find_layer_by_fullpath:
            index = find_layer_by_fullpath(layer, True)
            if index >= 0:
                attr.LayerIndex = index
        attr.Name = name
        attr.WireDensity = -1
        obj.CommitChanges()
        guids.append(guid)
    return guids