class QColorGetTest(unittest.TestCase): def setUp(self): self.color = QColor(20, 40, 60, 80) def testGetRgb(self): self.assertEqual(self.color.getRgb(), (20, 40, 60, 80)) def testGetHslF(self): hls = colorsys.rgb_to_hls(20.0 / 255, 40.0 / 255, 60.0 / 255) hsla = hls[0], hls[2], hls[1], self.color.alphaF() for x, y in zip(self.color.getHslF(), hsla): # Due to rounding problems self.assertTrue(x - y < 1 / 100000.0) def testGetHsv(self): hsv = colorsys.rgb_to_hsv(20.0 / 255, 40.0 / 255, 60.0 / 255) hsva = int(hsv[0] * 360.0), int(hsv[1] * 255), int( hsv[2] * 256), self.color.alpha() self.assertEqual(self.color.getHsv(), hsva) def testGetCmyk(self): # not supported by colorsys self.assertEqual(self.color.getCmyk(), (170, 85, 0, 195, 80)) def testGetCmykF(self): # not supported by colorsys for x, y in zip(self.color.getCmykF(), (170 / 255.0, 85 / 255.0, 0, 195 / 255.0, 80 / 255.0)): self.assertTrue(x - y < 1 / 10000.0)
class QColorGetTest(unittest.TestCase): def setUp(self): self.color = QColor(20, 40, 60, 80) def testGetRgb(self): self.assertEqual(self.color.getRgb(), (20, 40, 60, 80)) def testGetHslF(self): hls = colorsys.rgb_to_hls(20.0/255, 40.0/255, 60.0/255) hsla = hls[0], hls[2], hls[1], self.color.alphaF() for x, y in zip(self.color.getHslF(), hsla): # Due to rounding problems self.assert_(x - y < 1/100000.0) def testGetHsv(self): hsv = colorsys.rgb_to_hsv(20.0/255, 40.0/255, 60.0/255) hsva = int(hsv[0]*360.0), int(hsv[1]*255), int(hsv[2]*256), self.color.alpha() self.assertEqual(self.color.getHsv(), hsva) def testGetCmyk(self): # not supported by colorsys self.assertEqual(self.color.getCmyk(), (170, 85, 0, 195, 80)) def testGetCmykF(self): # not supported by colorsys for x, y in zip(self.color.getCmykF(), (170/255.0, 85/255.0, 0, 195/255.0, 80/255.0)): self.assert_(x - y < 1/10000.0)
def generatedIconPixmap(self, iconMode, pixmap, option): """ Draws the icon button brighter when hovered over. """ if iconMode == QIcon.Normal: return pixmap elif iconMode == QIcon.Active: if self.brighterPixmap is None: img = pixmap.toImage().convertToFormat(QImage.Format_ARGB32) imgh = img.height() imgw = img.width() pixel = None for y in range(0, imgh): for x in range(0, imgw): pixel = img.pixel(x, y) color = QColor(pixel) h, s, v, a = color.getHsv() if v > self.LOW_LIMIT: # value below this limit will not be adjusted if v < self.HIGH_LIMIT: # value above this limit will just max up to 255 v = v + self.ADJUSTMNET else: v = self.MAX_VALUE color.setHsv(h,s,v) img.setPixel(x, y, qRgba(color.red(), color.green(), color.blue(), qAlpha(pixel))) self.brighterPixmap = QPixmap.fromImage(img) return self.brighterPixmap