def _updateButtonColor(self, color): """Generate color preview pixmap and place it on button""" pixmap = QPixmap(128, 18) qcolour = QColor(0, 0, 0) qcolour.setNamedColor(color) pixmap.fill(qcolour) self.setIcon(QIcon(pixmap)) self.setIconSize(QSize(128, 18)) self.color = color
def main(): # Query system colours. p = QPalette() textcolour = p.color(QPalette.Text) basecolour = p.color(QPalette.Base) # Inject background colour into the browser. def tree_colour_hook(self): p = self.form.tree.palette() p.setColor(QPalette.Base, basecolour) self.form.tree.setPalette(p) browser.Browser.setupTree = wrap(browser.Browser.setupTree, tree_colour_hook) # Change suspend and mark colours. coloursuspended = QColor() coloursuspended.setNamedColor(browser.COLOUR_SUSPENDED) colourmarked = QColor() colourmarked.setNamedColor(browser.COLOUR_MARKED) lightness_blacklist = [textcolour.lightness()] hue_blacklist = [basecolour.hue(), textcolour.hue()] lightness_preference = max(basecolour.lightness(), 40) for colour in [coloursuspended, colourmarked]: (h, s, l, a) = colour.getHsl() new_lightness = get_new_lightness(lightness_blacklist, lightness_preference) # print("Considering {0} with preference {2} choose lightness {1}\n".format( # lightness_blacklist, new_lightness, lightness_preference)) new_hue = get_new_hue(hue_blacklist, h) # print("Considering {0} with preference {2} choose hue {1}\n".format( # hue_blacklist, new_hue, h)) hue_blacklist.append(new_hue) colour.setHsl(new_hue, s, new_lightness, a) browser.COLOUR_SUSPENDED = coloursuspended.name() browser.COLOUR_MARKED = colourmarked.name() # Inject colouring into the web view. editor._html = re.sub( "(\\.fname\s*\\{)", "\\1 color: {0};".format(textcolour.name()), editor._html) # Fix the default text colour for type answer edit elements. reviewer.Reviewer._css = re.sub( "(#typeans\s*\\{)", "\\1 color: {0};".format(textcolour.name()), reviewer.Reviewer._css)