From 5f81d415a07a513d03b832f60b5798a6895c2ee7 Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Mon, 25 May 2020 03:37:34 +0300 Subject: [PATCH] - updated the GUI fields for the Scale and Offset in the Object UI to allow only numeric values and operators in the list [/,*,+,-], spaces, dots and comma --- AppGUI/GUIElements.py | 13 +++++++++++++ AppGUI/ObjectUI.py | 4 ++-- AppObjects/FlatCAMObj.py | 2 +- CHANGELOG.md | 4 ++++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/AppGUI/GUIElements.py b/AppGUI/GUIElements.py index 0264cf64..0af31311 100644 --- a/AppGUI/GUIElements.py +++ b/AppGUI/GUIElements.py @@ -667,6 +667,19 @@ class NumericalEvalEntry(EvalEntry): validator = QtGui.QRegExpValidator(regex, self) self.setValidator(validator) + +class NumericalEvalTupleEntry(EvalEntry): + """ + Will evaluate the input and return a value. Accepts only float numbers and formulas using the operators: /,*,+,-,% + """ + def __init__(self): + super().__init__() + + regex = QtCore.QRegExp("[0-9\/\*\+\-\%\.\s\,]*") + validator = QtGui.QRegExpValidator(regex, self) + self.setValidator(validator) + + class FCSpinner(QtWidgets.QSpinBox): returnPressed = QtCore.pyqtSignal() diff --git a/AppGUI/ObjectUI.py b/AppGUI/ObjectUI.py index f2d52a06..b96ab965 100644 --- a/AppGUI/ObjectUI.py +++ b/AppGUI/ObjectUI.py @@ -114,7 +114,7 @@ class ObjectUI(QtWidgets.QWidget): self.common_grid.addWidget(self.transform_label, 2, 0, 1, 2) # ### Scale #### - self.scale_entry = FCEntry() + self.scale_entry = NumericalEvalEntry() self.scale_entry.set_value(1.0) self.scale_entry.setToolTip( _("Factor by which to multiply\n" @@ -132,7 +132,7 @@ class ObjectUI(QtWidgets.QWidget): self.common_grid.addWidget(self.scale_button, 3, 1) # ### Offset #### - self.offsetvector_entry = EvalEntry2() + self.offsetvector_entry = NumericalEvalTupleEntry() self.offsetvector_entry.setText("(0.0, 0.0)") self.offsetvector_entry.setToolTip( _("Amount by which to move the object\n" diff --git a/AppObjects/FlatCAMObj.py b/AppObjects/FlatCAMObj.py index 282c2ced..3070ba69 100644 --- a/AppObjects/FlatCAMObj.py +++ b/AppObjects/FlatCAMObj.py @@ -252,7 +252,7 @@ class FlatCAMObj(QtCore.QObject): def on_scale_button_click(self): self.read_form() try: - factor = float(eval(self.ui.scale_entry.get_value())) + factor = float(self.ui.scale_entry.get_value()) except Exception as e: self.app.inform.emit('[ERROR_NOTCL] %s' % _("Scaling could not be executed.")) log.debug("FlatCAMObj.on_scale_button_click() -- %s" % str(e)) diff --git a/CHANGELOG.md b/CHANGELOG.md index fbbf7a44..a84d0ac5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ CHANGELOG for FlatCAM beta ================================================= +25.05.2020 + +- updated the GUI fields for the Scale and Offset in the Object UI to allow only numeric values and operators in the list [/,*,+,-], spaces, dots and comma + 24.05.2020 - changes some icons