[path] make toolbit reject invalid filenames

help user create toolbit working location
This commit is contained in:
sliptonic
2020-11-30 15:26:29 -06:00
parent abf4c92280
commit daea1f53da
3 changed files with 77 additions and 6 deletions

View File

@@ -181,16 +181,31 @@ class ToolBitGuiFactory(PathToolBit.ToolBitFactory):
FreeCAD.ActiveDocument.commitTransaction()
return tool
def isValidFile(filename):
print(filename)
try:
with open(filename, "w") as tempfile:
return True
except:
return False
def GetNewToolFile(parent=None):
if parent is None:
parent = QtGui.QApplication.activeWindow()
foo = QtGui.QFileDialog.getSaveFileName(parent, 'Tool',
PathPreferences.lastPathToolBit(),
'*.fctb')
if foo and foo[0]:
PathPreferences.setLastPathToolBit(os.path.dirname(foo[0]))
return foo[0]
if not isValidFile(foo[0]):
msgBox = QtGui.QMessageBox()
msg = translate("Path", "Invalid Filename", None)
msgBox.setText(msg)
msgBox.exec_()
else:
PathPreferences.setLastPathToolBit(os.path.dirname(foo[0]))
return foo[0]
return None