DRIVER=psmouse
SERIO_TYPE=01
SERIO_PROTO=00
SERIO_ID=00
SERIO_EXTRA=00
MODALIAS=serio:ty01pr00id00ex00
SERIO_FIRMWARE_ID=PNP: PNP0f13
  #   ˆl–ßi~”TÒ~êu@ŠãM\*bÑ¿Á„bÀ¿ ;y    # -*- Mode: Python; py-indent-offset: 4 -*-
# vim: tabstop=4 shiftwidth=4 expandtab
#
# Copyright (C) 2009 Johan Dahlin <johan@gnome.org>
#               2010 Simon van der Linden <svdlinden@src.gnome.org>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
# USA

import sys
import warnings

from ..overrides import override, strip_boolean_result
from ..module import get_introspection_module
from gi import PyGIDeprecationWarning, require_version

Gdk = get_introspection_module('Gdk')

__all__ = []


# https://bugzilla.gnome.org/show_bug.cgi?id=673396
try:
    require_version("GdkX11", Gdk._version)
    from gi.repository import GdkX11
    GdkX11  # pyflakes
except (ValueError, ImportError):
    pass


class Color(Gdk.Color):
    MAX_VALUE = 65535

    def __init__(self, red, green, blue):
        Gdk.Color.__init__(self)
        self.red = red
        self.green = green
        self.blue = blue

    def __eq__(self, other):
        return self.equal(other)

    def __repr__(self):
        return 'Gdk.Color(red=%d, green=%d, blue=%d)' % (self.red, self.green, self.blue)

    red_float = property(fget=lambda self: self.red / float(self.MAX_VALUE),
                         fset=lambda self, v: setattr(self, 'red', int(v * self.MAX_VALUE)))

    green_float = property(fget=lambda self: self.green / float(self.MAX_VALUE),
                           fset=lambda self, v: setattr(self, 'green', int(v * self.MAX_VALUE)))

    blue_float = property(fget=lambda self: self.blue / float(self.MAX_VALUE),
                          fset=lambda self, v: setattr(self, 'blue', int(v * self.MAX_VALUE)))

    def to_floats(self):
        """Return (red_float, green_float, blue_float) triple."""

        return (self.red_float, self.green_float, self.blue_float)

    @staticmethod
    def from_floats(red, green, blue):
        """Return a new Color object from red/green/blue values from 0.0 to 1.0."""

        return Color(int(red * Color.MAX_VALUE),
                     int(green * Color.MAX_VALUE),
                     int(blue * Color.MAX_VALUE))

Color = override(Color)
__all__.append('Color')

if Gdk._version == '3.0':
    class RGBA(Gdk.RGBA):
        def __init__(self, red=1.0, green=1.0, blue=1.0, alpha=1.0):
            Gdk.RGBA.__init__(self)
            self.red = red
            self.green = green
            self.blue = blue
            self.alpha = alpha

        def __eq__(self, other):
            return self.equal(other)

        def __repr__(self):
            return 'Gdk.RGBA(red=%f, green=%f, blue=%f, alpha=%f)' % (self.red, self.green, self.blue, self.alpha)

        def __iter__(self):
            """Iterator which allows easy conversion to tuple and list types."""

            yield self.red
            yield self.green
            yield self.blue
            yield self.alpha

        def to_color(self):
            """Converts this RGBA into a Color instance which excludes alpha."""

            return Color(int(self.red * Color.MAX_VALUE),
                         int(self.green * Color.MAX_VALUE),
                         int(self.blue * Color.MAX_VALUE))

        @classmethod
        def from_color(cls, color):
            """Returns a new RGBA instance given a Color instance."