Python System.Drawing() Examples

The following are 14 code examples of System.Drawing(). 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 , or try the search function .
Example #1
Source File: test_regressions.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
def test_indexing_value_types_cp20370(self):
        import clr
        if is_netcoreapp:
            clr.AddReference("System.Drawing.Primitives")
        else:
            clr.AddReference("System.Drawing")
        from System.Drawing import Point

        p = Point(1,2)
        l = [None]
        l[0] = p
        self.assertEqual(id(l[0]), id(p))
        self.assertEqual(id(l[0]), id(p))

        x = {}
        x[p] = p
        self.assertEqual(id(list(x.iterkeys())[0]), id(p))
        self.assertEqual(id(list(x.itervalues())[0]), id(p))

        self.load_iron_python_test()

        from IronPythonTest import StructIndexable
        a = StructIndexable()
        a[0] = 1
        self.assertEqual(a[0], 1) 
Example #2
Source File: test_regressions.py    From ironpython3 with Apache License 2.0 6 votes vote down vote up
def test_indexing_value_types_cp20370(self):
        import clr
        if is_netcoreapp:
            clr.AddReference("System.Drawing.Primitives")
        else:
            clr.AddReference("System.Drawing")
        from System.Drawing import Point

        p = Point(1,2)
        l = [None]
        l[0] = p
        self.assertEqual(id(l[0]), id(p))
        self.assertEqual(id(l[0]), id(p))

        x = {}
        x[p] = p
        self.assertEqual(id(list(x.keys())[0]), id(p))
        self.assertEqual(id(list(x.values())[0]), id(p))

        self.load_iron_python_test()

        from IronPythonTest import StructIndexable
        a = StructIndexable()
        a[0] = 1
        self.assertEqual(a[0], 1) 
Example #3
Source File: test_methoddispatch.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def test_system_drawing(self):
        import clr
        if is_netcoreapp:
            clr.AddReference("System.Drawing.Primitives")
        else:
            clr.AddReference("System.Drawing")
        from System.Drawing import Rectangle
        r = Rectangle(0, 0, 3, 7)
        s = Rectangle(3, 0, 8, 14)
        
        # calling the static method
        i = Rectangle.Intersect(r, s)
        self.assertEqual(i, Rectangle(3, 0, 0, 7))
        self.assertEqual(r, Rectangle(0, 0, 3, 7))
        self.assertEqual(s, Rectangle(3, 0, 8, 14))
        
        # calling the instance
        i = r.Intersect(s)
        self.assertEqual(i, None)
        self.assertEqual(r, Rectangle(3, 0, 0, 7))
        self.assertEqual(s, Rectangle(3, 0, 8, 14))
        
        # calling instance w/ StrongBox
        r = Rectangle(0, 0, 3, 7)
        box = clr.StrongBox[Rectangle](r)
        i = box.Intersect(s)
        self.assertEqual(i, None)
        self.assertEqual(box.Value, Rectangle(3, 0, 0, 7))
        self.assertEqual(s, Rectangle(3, 0, 8, 14))
        
        # should be able to access properties through the box
        self.assertEqual(box.X, 3)
        
        # multiple sites should produce the same function
        i = box.Intersect
        j = box.Intersect 
Example #4
Source File: test_operator.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        super(OperaterTest, self).setUp()

        if is_cli:
            import clr
            self.load_iron_python_test()
            if is_netcoreapp:
                clr.AddReference("System.Drawing.Primitives")
            else:
                clr.AddReference("System.Drawing") 
Example #5
Source File: test_operator.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def test_cp3982(self):
        from System.Drawing import Color
        test_funcs = [  lambda x: x,
                        lambda x: [x],
                        lambda x: (x),
                        lambda x: [[x]],
                        lambda x: [(x)],
                        lambda x: ((x)),
                        lambda x: ([x]),
                        lambda x: [[[x]]],
                        lambda x: (((x))),
                        lambda x: [x, x],
                        lambda x: (x, x),
                        lambda x: [(x), [x, x]],
                        lambda x: ([x, x], (x)),
                    ]

        for test_func in test_funcs:
            self.assertTrue(test_func(Color.Red)==test_func(Color.Red))
            self.assertTrue(test_func(Color.Red)!=test_func(Color.Green))
            self.assertTrue(test_func(Color.Green)!=test_func(Color.Red))

        self.assertTrue( [Color.Green, Color.Red]  == [Color.Green, Color.Red])
        self.assertTrue([(Color.Green, Color.Red)] == [(Color.Green, Color.Red)])
        self.assertTrue( [Color.Green, Color.Red]  != (Color.Green, Color.Red))
        self.assertTrue( [Color.Green, Color.Red]  != [Color.Green, Color.Black]) 
Example #6
Source File: test_regressions.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def test_cp24802(self):
        import clr
        clr.AddReference('System.Drawing')
        import System
        p = System.Drawing.Pen(System.Drawing.Color.Blue)
        p.Width = System.Single(3.14)
        self.assertEqual(p.Width, System.Single(3.14))
        p.Width = 4.0
        self.assertEqual(p.Width, 4.0) 
Example #7
Source File: test_cliclass.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def test_repr(self):
        from IronPythonTest import UnaryClass, BaseClass, BaseClassStaticConstructor
        if is_netcoreapp:
            clr.AddReference('System.Drawing.Primitives')
        else:
            clr.AddReference('System.Drawing')

        from System.Drawing import Point

        self.assertEqual(repr(Point(1,2)).startswith('<System.Drawing.Point object'), True)
        self.assertEqual(repr(Point(1,2)).endswith('[{X=1,Y=2}]>'),True)
        
        # these 3 classes define the same repr w/ different \r, \r\n, \n versions
        a = UnaryClass(3)
        b = BaseClass()
        c = BaseClassStaticConstructor()
        
        ra = repr(a)
        rb = repr(b)
        rc = repr(c)
        
        sa = ra.find('HelloWorld')
        sb = rb.find('HelloWorld')
        sc = rc.find('HelloWorld')
        
        self.assertEqual(ra[sa:sa+13], rb[sb:sb+13])
        self.assertEqual(rb[sb:sb+13], rc[sc:sc+13])
        self.assertEqual(ra[sa:sa+13], 'HelloWorld...') # \r\n should be removed, replaced with ... 
Example #8
Source File: test_cliclass.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def test_property_get_set(self):
        if is_netcoreapp:
            clr.AddReference("System.Drawing.Primitives")
        else:
            clr.AddReference("System.Drawing")
        from System.Drawing import Size
        
        temp = Size()
        self.assertEqual(temp.Width, 0)
        temp.Width = 5
        self.assertEqual(temp.Width, 5)
            
        for i in xrange(5):
            temp.Width = i
            self.assertEqual(temp.Width, i) 
Example #9
Source File: test_methoddispatch.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def test_system_drawing(self):
        import clr
        if is_netcoreapp:
            clr.AddReference("System.Drawing.Primitives")
        else:
            clr.AddReference("System.Drawing")
        from System.Drawing import Rectangle
        r = Rectangle(0, 0, 3, 7)
        s = Rectangle(3, 0, 8, 14)
        
        # calling the static method
        i = Rectangle.Intersect(r, s)
        self.assertEqual(i, Rectangle(3, 0, 0, 7))
        self.assertEqual(r, Rectangle(0, 0, 3, 7))
        self.assertEqual(s, Rectangle(3, 0, 8, 14))
        
        # calling the instance
        i = r.Intersect(s)
        self.assertEqual(i, None)
        self.assertEqual(r, Rectangle(3, 0, 0, 7))
        self.assertEqual(s, Rectangle(3, 0, 8, 14))
        
        # calling instance w/ StrongBox
        r = Rectangle(0, 0, 3, 7)
        box = clr.StrongBox[Rectangle](r)
        i = box.Intersect(s)
        self.assertEqual(i, None)
        self.assertEqual(box.Value, Rectangle(3, 0, 0, 7))
        self.assertEqual(s, Rectangle(3, 0, 8, 14))
        
        # should be able to access properties through the box
        self.assertEqual(box.X, 3)
        
        # multiple sites should produce the same function
        i = box.Intersect
        j = box.Intersect 
Example #10
Source File: test_operator.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        super(OperaterTest, self).setUp()

        if is_cli:
            import clr
            self.load_iron_python_test()
            if is_netcoreapp:
                clr.AddReference("System.Drawing.Primitives")
            else:
                clr.AddReference("System.Drawing") 
Example #11
Source File: test_operator.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def test_cp3982(self):
        from System.Drawing import Color
        test_funcs = [  lambda x: x,
                        lambda x: [x],
                        lambda x: (x),
                        lambda x: [[x]],
                        lambda x: [(x)],
                        lambda x: ((x)),
                        lambda x: ([x]),
                        lambda x: [[[x]]],
                        lambda x: (((x))),
                        lambda x: [x, x],
                        lambda x: (x, x),
                        lambda x: [(x), [x, x]],
                        lambda x: ([x, x], (x)),
                    ]

        for test_func in test_funcs:
            self.assertTrue(test_func(Color.Red)==test_func(Color.Red))
            self.assertTrue(test_func(Color.Red)!=test_func(Color.Green))
            self.assertTrue(test_func(Color.Green)!=test_func(Color.Red))

        self.assertTrue( [Color.Green, Color.Red]  == [Color.Green, Color.Red])
        self.assertTrue([(Color.Green, Color.Red)] == [(Color.Green, Color.Red)])
        self.assertTrue( [Color.Green, Color.Red]  != (Color.Green, Color.Red))
        self.assertTrue( [Color.Green, Color.Red]  != [Color.Green, Color.Black]) 
Example #12
Source File: test_regressions.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def test_cp24802(self):
        import clr
        clr.AddReference('System.Drawing')
        import System
        p = System.Drawing.Pen(System.Drawing.Color.Blue)
        p.Width = System.Single(3.14)
        self.assertEqual(p.Width, System.Single(3.14))
        p.Width = 4.0
        self.assertEqual(p.Width, 4.0) 
Example #13
Source File: test_cliclass.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def test_repr(self):
        from IronPythonTest import UnaryClass, BaseClass, BaseClassStaticConstructor
        if is_netcoreapp:
            clr.AddReference('System.Drawing.Primitives')
        else:
            clr.AddReference('System.Drawing')

        from System.Drawing import Point

        self.assertEqual(repr(Point(1,2)).startswith('<System.Drawing.Point object'), True)
        self.assertEqual(repr(Point(1,2)).endswith('[{X=1,Y=2}]>'),True)
        
        # these 3 classes define the same repr w/ different \r, \r\n, \n versions
        a = UnaryClass(3)
        b = BaseClass()
        c = BaseClassStaticConstructor()
        
        ra = repr(a)
        rb = repr(b)
        rc = repr(c)
        
        sa = ra.find('HelloWorld')
        sb = rb.find('HelloWorld')
        sc = rc.find('HelloWorld')
        
        self.assertEqual(ra[sa:sa+13], rb[sb:sb+13])
        self.assertEqual(rb[sb:sb+13], rc[sc:sc+13])
        self.assertEqual(ra[sa:sa+13], 'HelloWorld...') # \r\n should be removed, replaced with ... 
Example #14
Source File: test_cliclass.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def test_property_get_set(self):
        if is_netcoreapp:
            clr.AddReference("System.Drawing.Primitives")
        else:
            clr.AddReference("System.Drawing")
        from System.Drawing import Size
        
        temp = Size()
        self.assertEqual(temp.Width, 0)
        temp.Width = 5
        self.assertEqual(temp.Width, 5)
            
        for i in range(5):
            temp.Width = i
            self.assertEqual(temp.Width, i)