Exemple #1
0
 def test_from_string(self):
     self.assertEqual(tuple(Color("1,1,1,1")), (1, 1, 1, 1))
     self.assertEqual(tuple(Color(".1,.1,.1,.1")),
                      (0.10000000000000001, 0.10000000000000001,
                       0.10000000000000001, 0.10000000000000001))
     self.assertEqual(tuple(Color("1, 1, 1, 1")), (1, 1, 1, 1))
     self.assertEqual(tuple(Color("0.1, 0.1, 0.1, 0.1")),
                      (0.10000000000000001, 0.10000000000000001,
                       0.10000000000000001, 0.10000000000000001))
Exemple #2
0
 def test_invalid_values_too_large(self):
     with self.assertRaises(
             ValueError, msg="The color for r (2) is not between 0 and 1."):
         Color((2, 0, 0, 0))
     with self.assertRaises(
             ValueError, msg="The color for g (2) is not between 0 and 1."):
         Color((0, 2, 0, 0))
     with self.assertRaises(
             ValueError, msg="The color for b (2) is not between 0 and 1."):
         Color((0, 0, 2, 0))
     with self.assertRaises(
             ValueError, msg="The color for a (2) is not between 0 and 1."):
         Color((0, 0, 0, 2))
Exemple #3
0
 def test_invalid_values_negative(self):
     with self.assertRaises(
             ValueError,
             msg="The color for r (-1) is not between 0 and 1."):
         Color((-1, 0, 0, 0))
     with self.assertRaises(
             ValueError,
             msg="The color for g (-1) is not between 0 and 1."):
         Color((0, -1, 0, 0))
     with self.assertRaises(
             ValueError,
             msg="The color for b (-1) is not between 0 and 1."):
         Color((0, 0, -1, 0))
     with self.assertRaises(
             ValueError,
             msg="The color for a (-1) is not between 0 and 1."):
         Color((0, 0, 0, -1))
Exemple #4
0
 def _set_markColor(self, value):
     # convert to a color object
     if value is not None:
         value = Color(value)
     # don't write if there is no change
     oldValue = self.lib.get("public.markColor")
     if oldValue is not None:
         oldValue = Color(oldValue)
     if value == oldValue:
         return
     # remove
     if value is None:
         if "public.markColor" in self.lib:
             del self.lib["public.markColor"]
     # store
     else:
         self.lib["public.markColor"] = value
     self.postNotification(notification="Glyph.MarkColorChanged",
                           data=dict(oldValue=oldValue, newValue=value))
Exemple #5
0
 def _set_color(self, color):
     if color is None:
         newColor = None
     else:
         newColor = Color(color)
     oldColor = self.get("color")
     if newColor == oldColor:
         return
     self["color"] = newColor
     self.postNotification("Image.ColorChanged", data=dict(oldValue=oldColor, newValue=newColor))
Exemple #6
0
 def _set_color(self, color):
     if color is None:
         newColor = None
     else:
         newColor = Color(color)
     oldColor = self._color
     if oldColor != newColor:
         self._color = newColor
         data = dict(oldColor=oldColor, newColor=newColor)
         self.postNotification(notification="Layer.ColorChanged", data=data)
         self.dirty = True
Exemple #7
0
 def test_iterate_component_attributes(self):
     color = Color((0.1, 0.2, 0.3, 0.4))
     expected_values = (0.10000000000000001, 0.20000000000000001,
                        0.29999999999999999, 0.40000000000000002)
     for index, component_attribute in enumerate(color):
         self.assertEqual(component_attribute, expected_values[index])
Exemple #8
0
 def test_compare(self):
     self.assertTrue(Color((0, 0, 0, 0)) < Color((1, 1, 1, 1)))
     self.assertTrue(Color((0, 0, 0, 0)) < Color((0, 1, 1, 1)))
     self.assertTrue(Color((0, 0, 0, 0)) < Color((1, 0, 0, 0)))
     self.assertTrue(Color((0, 1, 1, 1)) < Color((1, 0, 0, 0)))
Exemple #9
0
 def test_component_attributes(self):
     c = Color((.1, .2, .3, .4))
     self.assertEqual(c.r, 0.10000000000000001)
     self.assertEqual(c.g, 0.20000000000000001)
     self.assertEqual(c.b, 0.29999999999999999)
     self.assertEqual(c.a, 0.40000000000000002)
Exemple #10
0
 def test_to_sequence(self):
     self.assertEqual(tuple(Color((1, 1, 1, 1))), (1, 1, 1, 1))
Exemple #11
0
 def test_to_string(self):
     self.assertEqual(Color((0, 0, 0, 0)), "0,0,0,0")
     self.assertEqual(Color((1, .1, .01, .001)), "1,0.1,0.01,0.001")
     self.assertEqual(Color((.0001, .00001, .000001, .000005)),
                      "0.0001,0.00001,0,0.00001")
Exemple #12
0
 def test_from_tuple(self):
     self.assertEqual(tuple(Color((1, 1, 1, 1))), (1, 1, 1, 1))
Exemple #13
0
 def _get_markColor(self):
     value = self.lib.get("public.markColor")
     if value is not None:
         value = Color(value)
     return value