From 853da5c405563ed445d4330223fd882dca053ae2 Mon Sep 17 00:00:00 2001 From: "A.M. Rowsell" Date: Sun, 19 Sep 2021 15:53:11 -0400 Subject: [PATCH] Wrapped entry box changed callback in try/except to handle ValueError --- spirographs.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/spirographs.py b/spirographs.py index f503fa0..21fd4a1 100644 --- a/spirographs.py +++ b/spirographs.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- +# Copyright 2021 Alexander Rowsell. Licenced under MPLv2.0 # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. @@ -69,7 +70,11 @@ class spirographs: self.updatePlot() def bigRadiusEntry_changed_cb(self, widget): - self.bigRadius = float(widget.get_text()) + try: + self.bigRadius = float(widget.get_text()) + except ValueError: + print("Couldn't get a float for R, ignoring...\n") + return self.bigRadiusAdjustment.set_value(self.bigRadius) def smallRadiusAdjustment_value_changed_cb(self, widget): @@ -79,7 +84,11 @@ class spirographs: self.updatePlot() def smallRadiusEntry_changed_cb(self, widget): - self.smallRadius = float(widget.get_text()) + try: + self.smallRadius = float(widget.get_text()) + except ValueError: + print("Couldn't get a float for r, ignoring...\n") + return self.smallRadiusAdjustment.set_value(self.smallRadius) def distanceAdjustment_value_changed_cb(self, widget): @@ -89,7 +98,11 @@ class spirographs: self.updatePlot() def distanceEntry_changed_cb(self, widget): - self.distance = float(widget.get_text()) + try: + self.distance = float(widget.get_text()) + except ValueError: + print("Couldn't get a float for d, ignoring...\n") + return self.distanceAdjustment.set_value(self.distance) def recalcPoints(self):