Merge pull request #4477 from sliptonic/bug/miscellaneous
[PATH] Bug fixes for several minor issues, lgtm flags and input sanitizing.
This commit is contained in:
@@ -24,7 +24,7 @@
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="propertyName">
|
||||
<property name="toolTip">
|
||||
<string><html><head/><body><p>Name of property.</p></body></html></string>
|
||||
<string><html><head/><body><p>Name of property. Can only contain letters, numbers, and underscores. MixedCase names will display with spaces &quot;Mixed Case&quot;</p></body></html></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
@@ -142,8 +142,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>366</width>
|
||||
<height>330</height>
|
||||
<width>424</width>
|
||||
<height>537</height>
|
||||
</rect>
|
||||
</property>
|
||||
<attribute name="label">
|
||||
@@ -348,8 +348,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>319</width>
|
||||
<height>528</height>
|
||||
<width>424</width>
|
||||
<height>537</height>
|
||||
</rect>
|
||||
</property>
|
||||
<attribute name="label">
|
||||
@@ -653,16 +653,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="toolsOpenLastLibrary">
|
||||
<property name="toolTip">
|
||||
<string><html><head/><body><p>Causes the toollibrary manager to remember last directory. This ONLY affects legacy tools. </p><p>This control is deprecated and will be removed in a future version</p></body></html></string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Remember last library (legacy)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_4">
|
||||
<property name="orientation">
|
||||
|
||||
@@ -224,7 +224,7 @@ class ObjectDressup:
|
||||
def toolRadius(self):
|
||||
return float(PathDressup.toolController(self.obj.Base).Tool.Diameter) / 2.0
|
||||
|
||||
def addTagsToDocuemnt(self):
|
||||
def addTagsToDocument(self):
|
||||
for i, solid in enumerate(self.solids):
|
||||
obj = FreeCAD.ActiveDocument.addObject('Part::Compound', "tag_%02d" % i)
|
||||
obj.Shape = solid
|
||||
@@ -256,7 +256,7 @@ def Create(baseObject, name='DressupTag'):
|
||||
obj = FreeCAD.ActiveDocument.addObject("Path::FeaturePython", name)
|
||||
dbo = ObjectDressup(obj, baseObject)
|
||||
job = PathUtils.findParentJob(baseObject)
|
||||
job.adddOperation(obj)
|
||||
job.addOperation(obj)
|
||||
dbo.assignDefaultValues()
|
||||
return obj
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ LastFileToolShape = "LastFileToolShape"
|
||||
|
||||
UseLegacyTools = "UseLegacyTools"
|
||||
UseAbsoluteToolPaths = "UseAbsoluteToolPaths"
|
||||
OpenLastLibrary = "OpenLastLibrary"
|
||||
# OpenLastLibrary = "OpenLastLibrary"
|
||||
|
||||
# Linear tolerance to use when generating Paths, eg when tessellating geometry
|
||||
GeometryTolerance = "GeometryTolerance"
|
||||
@@ -166,15 +166,15 @@ def toolsStoreAbsolutePaths():
|
||||
return preferences().GetBool(UseAbsoluteToolPaths, False)
|
||||
|
||||
|
||||
def toolsOpenLastLibrary():
|
||||
return preferences().GetBool(OpenLastLibrary, False)
|
||||
# def toolsOpenLastLibrary():
|
||||
# return preferences().GetBool(OpenLastLibrary, False)
|
||||
|
||||
|
||||
def setToolsSettings(legacy, relative, lastlibrary):
|
||||
def setToolsSettings(legacy, relative):
|
||||
pref = preferences()
|
||||
pref.SetBool(UseLegacyTools, legacy)
|
||||
pref.SetBool(UseAbsoluteToolPaths, relative)
|
||||
pref.SetBool(OpenLastLibrary, lastlibrary)
|
||||
# pref.SetBool(OpenLastLibrary, lastlibrary)
|
||||
|
||||
|
||||
def defaultJobTemplate():
|
||||
|
||||
@@ -108,8 +108,7 @@ class JobPreferencesPage:
|
||||
|
||||
def saveToolsSettings(self):
|
||||
PathPreferences.setToolsSettings(self.form.toolsUseLegacy.isChecked(),
|
||||
self.form.toolsAbsolutePaths.isChecked(),
|
||||
self.form.toolsOpenLastLibrary.isChecked())
|
||||
self.form.toolsAbsolutePaths.isChecked())
|
||||
|
||||
def selectComboEntry(self, widget, text):
|
||||
index = widget.findText(text, QtCore.Qt.MatchFixedString)
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
import FreeCAD
|
||||
import PySide
|
||||
import re
|
||||
|
||||
__title__ = 'Generic property container to store some values.'
|
||||
__author__ = 'sliptonic (Brad Collette)'
|
||||
@@ -67,6 +68,18 @@ class PropertyBag(object):
|
||||
def __setstate__(self, state):
|
||||
return None
|
||||
|
||||
def __sanitizePropertyName(self, name):
|
||||
if(len(name) == 0):
|
||||
return
|
||||
clean = name[0]
|
||||
for i in range(1, len(name)):
|
||||
if (name[i] == ' '):
|
||||
clean += name[i + 1].upper()
|
||||
i += 1
|
||||
elif(name[i - 1] != ' '):
|
||||
clean += name[i]
|
||||
return clean
|
||||
|
||||
def onDocumentRestored(self, obj):
|
||||
self.obj = obj
|
||||
obj.setEditorMode(self.CustomPropertyGroups, 2) # hide
|
||||
@@ -82,10 +95,16 @@ class PropertyBag(object):
|
||||
if group is None:
|
||||
group = self.CustomPropertyGroupDefault
|
||||
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)
|
||||
self.obj.CustomPropertyGroups = groups
|
||||
self.obj.addProperty(propertyType, name, group, desc)
|
||||
return name
|
||||
|
||||
def refreshCustomPropertyGroups(self):
|
||||
'''refreshCustomPropertyGroups() ... removes empty property groups, should be called after deleting properties.'''
|
||||
|
||||
@@ -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)
|
||||
@@ -299,10 +304,10 @@ class TaskPanel(object):
|
||||
typ = dialog.propertyType()
|
||||
grp = dialog.propertyGroup()
|
||||
info = dialog.propertyInfo()
|
||||
self.obj.Proxy.addCustomProperty(typ, name, grp, info)
|
||||
propname = self.obj.Proxy.addCustomProperty(typ, name, grp, info)
|
||||
if dialog.propertyIsEnumeration():
|
||||
setattr(self.obj, name, dialog.propertyEnumerations())
|
||||
return (name, info)
|
||||
return (propname, info)
|
||||
|
||||
def propertyAdd(self):
|
||||
PathLog.track()
|
||||
|
||||
@@ -47,13 +47,7 @@ class CommandToolBitSelectorOpen:
|
||||
def Activated(self):
|
||||
import PathScripts.PathToolBitLibraryGui as PathToolBitLibraryGui
|
||||
dock = PathToolBitLibraryGui.ToolBitSelector()
|
||||
|
||||
lastlib = PathPreferences.lastPathToolLibrary()
|
||||
|
||||
if PathPreferences.toolsOpenLastLibrary():
|
||||
dock.open(lastlib)
|
||||
else:
|
||||
dock.open()
|
||||
dock.open()
|
||||
|
||||
|
||||
class CommandToolBitLibraryOpen:
|
||||
@@ -77,57 +71,7 @@ class CommandToolBitLibraryOpen:
|
||||
import PathScripts.PathToolBitLibraryGui as PathToolBitLibraryGui
|
||||
library = PathToolBitLibraryGui.ToolBitLibrary()
|
||||
|
||||
lastlib = PathPreferences.lastPathToolLibrary()
|
||||
|
||||
if PathPreferences.toolsOpenLastLibrary():
|
||||
library.open(lastlib)
|
||||
else:
|
||||
library.open()
|
||||
|
||||
# class CommandToolBitLibraryLoad:
|
||||
# '''
|
||||
# Command used to load an entire ToolBitLibrary (or part of it) from a file into a job.
|
||||
# '''
|
||||
|
||||
# def __init__(self):
|
||||
# pass
|
||||
|
||||
# def GetResources(self):
|
||||
# return {'Pixmap': 'Path_ToolTable',
|
||||
# 'MenuText': QtCore.QT_TRANSLATE_NOOP("PathToolBitLibrary", "Load ToolBit Library"),
|
||||
# 'ToolTip': QtCore.QT_TRANSLATE_NOOP("PathToolBitLibrary", "Load an entire ToolBit library or part of it into a job")}
|
||||
|
||||
# def selectedJob(self):
|
||||
# if FreeCAD.ActiveDocument:
|
||||
# sel = FreeCADGui.Selection.getSelectionEx()
|
||||
# if sel and sel[0].Object.Name[:3] == 'Job':
|
||||
# return sel[0].Object
|
||||
# jobs = [o for o in FreeCAD.ActiveDocument.Objects if o.Name[:3] == 'Job']
|
||||
# if 1 == len(jobs):
|
||||
# return jobs[0]
|
||||
# return None
|
||||
|
||||
# def IsActive(self):
|
||||
# return not self.selectedJob() is None
|
||||
|
||||
# def Activated(self):
|
||||
# job = self.selectedJob()
|
||||
# self.Execute(job)
|
||||
|
||||
# @classmethod
|
||||
# def Execute(cls, job):
|
||||
# import PathScripts.PathToolBitLibraryGui as PathToolBitLibraryGui
|
||||
# import PathScripts.PathToolControllerGui as PathToolControllerGui
|
||||
|
||||
# library = PathToolBitLibraryGui.ToolBitLibrary()
|
||||
|
||||
# if 1 == library.open() and job:
|
||||
# for nr, tool in library.selectedOrAllTools():
|
||||
# tc = PathToolControllerGui.Create("TC: {}".format(tool.Label), tool, nr)
|
||||
# job.Proxy.addToolController(tc)
|
||||
# FreeCAD.ActiveDocument.recompute()
|
||||
# return True
|
||||
# return False
|
||||
library.open()
|
||||
|
||||
|
||||
if FreeCAD.GuiUp:
|
||||
|
||||
@@ -50,6 +50,7 @@ import re
|
||||
import PathScripts.PathCustom as PathCustom
|
||||
import PathScripts.PathCustomGui as PathCustomGui
|
||||
import PathScripts.PathOpGui as PathOpGui
|
||||
from PySide import QtCore
|
||||
|
||||
# LEVEL = PathLog.Level.DEBUG
|
||||
LEVEL = PathLog.Level.INFO
|
||||
@@ -112,11 +113,10 @@ def insert(filename, docname):
|
||||
|
||||
# Create a custom and viewobject
|
||||
obj = PathCustom.Create("Custom")
|
||||
res = PathOpGui.CommandResources('Custom',
|
||||
PathCustom.Create, PathCustomGui.TaskPanelOpPage,
|
||||
'Path_Custom',
|
||||
QtCore.QT_TRANSLATE_NOOP('Path_Custom', 'Custom'), '', ''
|
||||
)
|
||||
res = PathOpGui.CommandResources('Custom', PathCustom.Create,
|
||||
PathCustomGui.TaskPanelOpPage,
|
||||
'Path_Custom',
|
||||
QtCore.QT_TRANSLATE_NOOP('Path_Custom', 'Custom'), '', '')
|
||||
obj.ViewObject.Proxy = PathOpGui.ViewProvider(obj.ViewObject, res)
|
||||
obj.ViewObject.Proxy.setDeleteObjectsOnReject(False)
|
||||
|
||||
@@ -127,6 +127,7 @@ def insert(filename, docname):
|
||||
FreeCAD.ActiveDocument.recompute()
|
||||
|
||||
|
||||
|
||||
def parse(inputstring):
|
||||
"parse(inputstring): returns a parsed output string"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user