From 4b636bceeaa821de3e5c84f10533b4756824a0d0 Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Wed, 9 Oct 2019 05:10:56 +0300 Subject: [PATCH] - made FCDoubleSpinner to use either comma or dot as a decimal separator --- README.md | 1 + flatcamGUI/GUIElements.py | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 8d3f00c2..7507746a 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ CAD program, and create G-Code for Isolation routing. 9.10.2019 - updated the Rules Check Tool - solved some issues +- made FCDoubleSpinner to use either comma or dot as a decimal separator 8.10.2019 diff --git a/flatcamGUI/GUIElements.py b/flatcamGUI/GUIElements.py index 07645f0f..adac2e89 100644 --- a/flatcamGUI/GUIElements.py +++ b/flatcamGUI/GUIElements.py @@ -565,17 +565,23 @@ class FCSpinner(QtWidgets.QSpinBox): class FCDoubleSpinner(QtWidgets.QDoubleSpinBox): - def __init__(self, parent=None, decimals=None): + def __init__(self, parent=None): super(FCDoubleSpinner, self).__init__(parent) self.readyToEdit = True - if decimals: - dec = int(decimals) - else: - dec = int(4) - self.editingFinished.connect(self.on_edit_finished) self.lineEdit().installEventFilter(self) + self.lineEdit().setValidator(QtGui.QRegExpValidator(QtCore.QRegExp("-?[0-9]*[.,]?[0-9]*"), self)) + + def valueFromText(self, p_str): + text = p_str.replace(',', '.') + try: + return float(text) + except ValueError: + return 0.0 + + def validate(self, p_str, p_int): + return QtGui.QValidator.Acceptable, p_str, p_int def eventFilter(self, object, event): if event.type() == QtCore.QEvent.MouseButtonPress: