- modified QValidator in FCDoubleSpinner() GUI element to allow entering the minus sign when the range maximum is set as 0.0; also for positive numbers allowed entering the symbol plus

This commit is contained in:
Marius Stanciu
2019-12-17 01:53:58 +02:00
committed by Marius
parent 74b3a38a71
commit b159548872
3 changed files with 49 additions and 40 deletions

View File

@@ -21,8 +21,16 @@ import re
import logging
import html
import gettext
import FlatCAMTranslation as fcTranslate
import builtins
log = logging.getLogger('base')
fcTranslate.apply_language('strings')
if '_' not in builtins.__dict__:
_ = gettext.gettext
EDIT_SIZE_HINT = 70
@@ -624,7 +632,7 @@ class FCDoubleSpinner(QtWidgets.QDoubleSpinBox):
# by default don't allow the minus sign to be entered as the default for QDoubleSpinBox is the positive range
# between 0.00 and 99.00 (2 decimals)
self.lineEdit().setValidator(
QtGui.QRegExpValidator(QtCore.QRegExp("[0-9]*[.,]?[0-9]{%d}" % self.decimals()), self))
QtGui.QRegExpValidator(QtCore.QRegExp("\+?[0-9]*[.,]?[0-9]{%d}" % self.decimals()), self))
if suffix:
self.setSuffix(' %s' % str(suffix))
@@ -710,15 +718,15 @@ class FCDoubleSpinner(QtWidgets.QDoubleSpinBox):
self.setDecimals(val)
# make sure that the user can't type more decimals than the set precision
if self.minimum() < 0 or self.maximum() < 0:
if self.minimum() < 0 or self.maximum() <= 0:
self.lineEdit().setValidator(
QtGui.QRegExpValidator(QtCore.QRegExp("-?[0-9]*[.,]?[0-9]{%d}" % self.decimals()), self))
else:
self.lineEdit().setValidator(
QtGui.QRegExpValidator(QtCore.QRegExp("[0-9]*[.,]?[0-9]{%d}" % self.decimals()), self))
QtGui.QRegExpValidator(QtCore.QRegExp("\+?[0-9]*[.,]?[0-9]{%d}" % self.decimals()), self))
def set_range(self, min_val, max_val):
if min_val < 0 or max_val < 0:
if min_val < 0 or max_val <= 0:
self.lineEdit().setValidator(
QtGui.QRegExpValidator(QtCore.QRegExp("-?[0-9]*[.,]?[0-9]{%d}" % self.decimals()), self))