0
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2025-07-14 03:31:50 +02:00

feat(color_button): can get colors in RGBA or HEX

This commit is contained in:
2024-07-05 20:14:40 +02:00
committed by wyzula_j
parent 96fd239608
commit 9594be2606

View File

@ -1,3 +1,7 @@
from __future__ import annotations
from typing import Literal
import pyqtgraph as pg
@ -15,3 +19,18 @@ class ColorButton(pg.ColorButton):
self.colorDialog.setCurrentColor(self.color())
self.colorDialog.open()
self.colorDialog.exec()
def get_color(self, format: Literal["RGBA", "HEX"] = "RGBA") -> tuple | str:
"""
Get the color of the button in the specified format.
Args:
format(Literal["RGBA", "HEX"]): The format of the returned color.
Returns:
tuple|str: The color in the specified format.
"""
if format == "RGBA":
return self.color().getRgb()
if format == "HEX":
return self.color().name()