From 285a28dff6fe34245aa6b98a1e9f52fab25d7516 Mon Sep 17 00:00:00 2001 From: KV Date: Wed, 19 Aug 2020 09:36:33 +0200 Subject: [PATCH] Avoid some bad combinations of default values - Avoid setting image.fixedsize default True when image.scale is specified different than "true" or "both" by the user. - Avoid calculating the missing dimension unless image.fixedsize is actually True. It might have been specified False by the user. --- src/wireviz/DataClasses.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/wireviz/DataClasses.py b/src/wireviz/DataClasses.py index bde12f5..a27e082 100644 --- a/src/wireviz/DataClasses.py +++ b/src/wireviz/DataClasses.py @@ -28,14 +28,17 @@ class Image: else "true" # When only one dimension is specified. if self.fixedsize is None: - self.fixedsize = self.width or self.height + # Normally equal to (self.width or self.height), but the user might override self.scale. + self.fixedsize = str(self.scale).lower() in ["true", "both"] - if self.height: - if not self.width: - self.width = self.height # Assuming 1:1 aspect ratio for now. - else: - if self.width: - self.height = self.width # Assuming 1:1 aspect ratio for now. + if self.fixedsize: + # If only one dimension is specified, compute the other because both are required. + if self.height: + if not self.width: + self.width = self.height # Assuming 1:1 aspect ratio for now. + else: + if self.width: + self.height = self.width # Assuming 1:1 aspect ratio for now. @dataclass