[path] make toolbit reject invalid filenames
help user create toolbit working location
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user