OSDN Git Service

colors.RGB.fromCOLORREF: support a standard python int, as well as a COLORREF ctypes...
authorMichael Curran <mick@kulgan.net>
Thu, 16 Sep 2010 05:57:57 +0000 (15:57 +1000)
committerMichael Curran <mick@kulgan.net>
Thu, 16 Sep 2010 05:57:57 +0000 (15:57 +1000)
source/colors.py

index b9f7c0f..7846bce 100644 (file)
@@ -15,8 +15,9 @@ class RGB(namedtuple('RGB',('red','green','blue'))):
        @classmethod\r
        def fromCOLORREF(cls,c):\r
                """factory method to create an RGB from a COLORREF ctypes instance"""\r
-               if not isinstance(c,COLORREF): raise ValueError("%s is not a COLORREF instance"%c)\r
-               return cls(c.value&0xff,(c.value<<8)&0xff,(c.value<<16)&0xff)\r
+               if isinstance(c,COLORREF):\r
+                       c=c.value\r
+               return cls(c&0xff,(c>>8)&0xff,(c>>16)&0xff)\r
 \r
        _re_RGBFunctionString=re.compile(r'rgb\(\s*(\d+%?)\s*,\s*(\d+%?)\s*,\s*(\d+%?)\s*\)',re.I)\r
        _re_RGBAFunctionString=re.compile(r'rgba\(\s*(\d+%?)\s*,\s*(\d+%?)\s*,\s*(\d+%?)\s*,\s*\d+(\.\d+)?\s*\)',re.I)\r