MCPcopy Create free account
hub / github.com/NSLS2/PyXRF / get_background_css

Function get_background_css

pyxrf/gui_module/useful_widgets.py:369–388  ·  view source on GitHub ↗

Returns the string that contain CSS to set widget background to specified color

(rgb, widget="QWidget", editable=False)

Source from the content-addressed store, hash-verified

367
368
369def get_background_css(rgb, widget="QWidget", editable=False):
370 """Returns the string that contain CSS to set widget background to specified color"""
371
372 rgb = tuple(rgb)
373 if len(rgb) != 3:
374 raise ValueError(r"RGB must be represented by 3 elements: rgb = {rgb}")
375 if any([(_ > 255) or (_ < 0) for _ in rgb]):
376 raise ValueError(r"RGB values must be in the range 0..255: rgb={rgb}")
377
378 # Shaded widgets appear brighter, so the brightness needs to be reduced
379 shaded_widgets = ("QComboBox", "QPushButton")
380 if widget in shaded_widgets:
381 rgb = [max(int(255 - (255 - _) * 1.5), 0) for _ in rgb]
382
383 # Increase brightness of editable element
384 if editable:
385 rgb = [255 - int((255 - _) * 0.5) for _ in rgb]
386
387 color_css = f"rgb({rgb[0]}, {rgb[1]}, {rgb[2]})"
388 return f"{widget} {{ background-color: {color_css}; }}"
389
390
391class IntValidatorStrict(QIntValidator):

Callers 6

fill_eline_tableMethod · 0.85
_fill_tableMethod · 0.85
setBackgroundMethod · 0.85
_set_row_colorMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected