From 8f1456bdbf14e6897bdbf0cc14def3f7ad5f3c8e Mon Sep 17 00:00:00 2001 From: Thomas Wilshaw Date: Sat, 28 Sep 2024 16:53:47 +0100 Subject: [PATCH] Add print functions --- tcolour/Colourimetry.py | 3 +++ tcolour/TransferCharacteristic.py | 2 +- tcolour/tcolour.py | 25 ++++++++++++++++++------- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/tcolour/Colourimetry.py b/tcolour/Colourimetry.py index 0d70731..4b44ffe 100644 --- a/tcolour/Colourimetry.py +++ b/tcolour/Colourimetry.py @@ -17,6 +17,9 @@ def valid(self) -> bool: def __repr__(self) -> str: return "RGBPrimaries(r=%r, g=%r, b=%r)" % (self.r, self.g, self.b) + def __str__(self) -> str: + return "%r, %r, %r" % (self.r, self.g, self.b) + class CIEVersion(Enum): CIE_1931_2_DEGREE = 1 CIE_2015_2_DEGREE = 2 diff --git a/tcolour/TransferCharacteristic.py b/tcolour/TransferCharacteristic.py index 77ebd6b..940038a 100644 --- a/tcolour/TransferCharacteristic.py +++ b/tcolour/TransferCharacteristic.py @@ -66,7 +66,7 @@ def valid(self) -> bool: def __repr__(self) -> str: return "TransferCharacteristicPower(parameters=%r)" % (self.parameters) - + class TransferCharacteristicPowerWithBreak(TransferCharacteristicParametric): """A power function with a linear segment near zero transfer characteristic""" diff --git a/tcolour/tcolour.py b/tcolour/tcolour.py index 3c2b050..8247674 100644 --- a/tcolour/tcolour.py +++ b/tcolour/tcolour.py @@ -104,14 +104,29 @@ def parse_data(self, data:list): print(e, "Skipping this Colourimetry chunk") - - def add_colour_space(self, colour_space): """Add a colour space to the config as either a file or a string""" with open(colour_space, 'r') as file: data = yaml.safe_load(file) self.parse_data(data) + + def print_colourimetry(self, descriptor): + """Pretty prints the colourimetry data set for the given descriptor""" + + item:Colourimetry = config.config[descriptor] + print("-", item.descriptor) + print("\tRGB Primaries: " + item.primaries.__str__()) + print("\tAchromatic Centroid: ", item.achromatic) + print("\tTransfer Characteristic:", item.transfer_characteristic) + print("\tHints: ", item.hints) + print("\tAlias: ", item.alias) + print("\tCIE Version:", item.cie_version) + print() + + def print_all_colourimetry(self): + for key, value in self.config.items(): + self.print_colourimetry(key) @@ -119,8 +134,4 @@ def add_colour_space(self, colour_space): config = TColor() config.add_colour_space("..\\tests\\files\\tcolor_test.yaml") - - for key, value in config.config.items(): - print(key, value) - print() - pass \ No newline at end of file + config.print_all_colourimetry()