From 19e652fff312b72a622f62c9e3fe4d78a73e25fe Mon Sep 17 00:00:00 2001 From: Martin K Date: Fri, 19 Aug 2022 15:34:16 +0300 Subject: [PATCH 1/4] Function outline --- colour.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/colour.py b/colour.py index 1bd48e8..ebb192c 100644 --- a/colour.py +++ b/colour.py @@ -1093,6 +1093,13 @@ def range_to(self, value, steps): ## Convenience ## + def preview(self, geometry=(100, 100)): + pass + + ## + ## Dunder + ## + def __str__(self): return "%s" % self.web From 06f9d97560f4a40dba9b385346e7d7a0ac1d6c05 Mon Sep 17 00:00:00 2001 From: Martin K Date: Fri, 19 Aug 2022 15:34:46 +0300 Subject: [PATCH 2/4] Tkinter import --- colour.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/colour.py b/colour.py index ebb192c..f3128ab 100644 --- a/colour.py +++ b/colour.py @@ -34,12 +34,12 @@ """ -from __future__ import with_statement, print_function +from __future__ import print_function, with_statement import hashlib import re import sys - +import tkinter ## ## Some Constants From 92251fe2f375963c10bb2b323773a16979124ac8 Mon Sep 17 00:00:00 2001 From: Martin K Date: Fri, 19 Aug 2022 15:42:22 +0300 Subject: [PATCH 3/4] Color preview proof of concept --- colour.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/colour.py b/colour.py index f3128ab..a707a79 100644 --- a/colour.py +++ b/colour.py @@ -1093,8 +1093,14 @@ def range_to(self, value, steps): ## Convenience ## - def preview(self, geometry=(100, 100)): - pass + def preview(self, geometry=(200, 200)): + root = tkinter.Tk() + + root.geometry(f"{geometry[0]}x{geometry[1]}") + root.config(background=self.get_hex_l()) + root.title("Colour preview") + + root.mainloop() ## ## Dunder From cc8cb31faf9fd0d74782b723dd621b5186188f9d Mon Sep 17 00:00:00 2001 From: Martin K Date: Fri, 19 Aug 2022 15:49:17 +0300 Subject: [PATCH 4/4] Disallow invalid values in preview function --- colour.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/colour.py b/colour.py index a707a79..37b21b0 100644 --- a/colour.py +++ b/colour.py @@ -1094,6 +1094,13 @@ def range_to(self, value, steps): ## def preview(self, geometry=(200, 200)): + if len(geometry) != 2: + raise ValueError("Geometry must have a length of 2") + + for i in geometry: + if not isinstance(i, int): + raise TypeError("Geometry must be a collection of integers") + root = tkinter.Tk() root.geometry(f"{geometry[0]}x{geometry[1]}")