Fix unit test with property name sanitize.

This commit is contained in:
sliptonic
2021-02-17 17:59:25 -06:00
parent 097b2c982e
commit 7c2962e119
3 changed files with 12 additions and 4 deletions

View File

@@ -24,7 +24,7 @@
<item row="0" column="1">
<widget class="QLineEdit" name="propertyName">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Name of property.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Name of property. Can only contain letters, numbers, and underscores. MixedCase names will display with spaces &amp;quot;Mixed Case&amp;quot;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>

View File

@@ -22,6 +22,7 @@
import FreeCAD
import PySide
import re
__title__ = 'Generic property container to store some values.'
__author__ = 'sliptonic (Brad Collette)'
@@ -70,7 +71,7 @@ class PropertyBag(object):
def __sanitizePropertyName(self, name):
if(len(name) == 0):
return
clean = name[0].lower()
clean = name[0]
for i in range(1, len(name)):
if (name[i] == ' '):
clean += name[i + 1].upper()
@@ -96,6 +97,8 @@ class PropertyBag(object):
groups = self.obj.CustomPropertyGroups
name = self.__sanitizePropertyName(name)
if not re.match("^[A-Za-z0-9_]*$", name):
raise ValueError('Property Name can only contain letters and numbers')
if not group in groups:
groups.append(group)

View File

@@ -22,12 +22,13 @@
import FreeCAD
import FreeCADGui
import PathGui
#import PathGui
import PathScripts.PathIconViewProvider as PathIconViewProvider
import PathScripts.PathLog as PathLog
import PathScripts.PathPropertyBag as PathPropertyBag
import PathScripts.PathPropertyEditor as PathPropertyEditor
import PathScripts.PathUtil as PathUtil
import re
from PySide import QtCore, QtGui
@@ -153,6 +154,7 @@ class PropertyCreate(object):
self.form.propertyEnum.textChanged.connect(self.updateUI)
def updateUI(self):
typeSet = True
if self.propertyIsEnumeration():
self.form.labelEnum.setEnabled(True)
@@ -166,7 +168,10 @@ class PropertyCreate(object):
ok = self.form.buttonBox.button(QtGui.QDialogButtonBox.Ok)
if typeSet and self.propertyName() and self.propertyGroup():
if not re.match("^[A-Za-z0-9_]*$", self.form.propertyName.text()):
typeSet = False
if typeSet and self.propertyGroup():
ok.setEnabled(True)
else:
ok.setEnabled(False)