Example #1
0
 def test_round_trip_maximum(self):
     """ Test to assert stability of values through round-trips """
     for value in range(65536):
         with self.subTest(int=value):
             result = channels_to_ints(
                 ints_to_channels(
                     [value],
                     maximum=65535,
                 ),
                 maximum=65535,
             )
             self.assertEqual(result, (value, ))
Example #2
0
def toolkit_color_to_rgba(color):
    """ Convert a hex tuple to an RGBA tuple.

    Parameters
    ----------
    color : tuple
        A tuple of integer values from 0 to 255 inclusive.

    Returns
    -------
    rgba : tuple
        A tuple of 4 floating point values between 0.0 and 1.0 inclusive.
    """
    return ints_to_channels(color)
Example #3
0
def toolkit_color_to_rgba(wx_colour):
    """ Convert a wx.Colour to an RGBA tuple.

    Parameters
    ----------
    wx_color : wx.Colour
        A wx.Colour object.

    Returns
    -------
    rgba : tuple
        A tuple of 4 floating point values between 0.0 and 1.0 inclusive.
    """
    values = (
        wx_colour.Red(),
        wx_colour.Green(),
        wx_colour.Blue(),
        wx_colour.Alpha(),
    )
    return ints_to_channels(values)
Example #4
0
def toolkit_color_to_rgba(qcolor):
    """ Convert a QColor to an RGBA tuple.

    Parameters
    ----------
    qcolor : QColor
        A QColor object.

    Returns
    -------
    rgba_tuple : tuple
        A tuple of 4 floating point values between 0.0 and 1.0 inclusive.
    """
    values = (
        qcolor.red(),
        qcolor.green(),
        qcolor.blue(),
        qcolor.alpha(),
    )
    return ints_to_channels(values)
Example #5
0
 def test_ints_to_channels_maximum(self):
     values = (6, 6, 0, 15)
     channels = ints_to_channels(values, maximum=15)
     self.assertEqual(channels, (0.4, 0.4, 0.0, 1.0))
Example #6
0
 def test_ints_to_channels(self):
     values = (102, 102, 0, 255)
     channels = ints_to_channels(values)
     self.assertEqual(channels, (0.4, 0.4, 0.0, 1.0))