diff --git a/src/Mod/Path/Gui/Resources/preferences/PathJob.ui b/src/Mod/Path/Gui/Resources/preferences/PathJob.ui
index 9e1b6f7fcc..bd29f158c0 100644
--- a/src/Mod/Path/Gui/Resources/preferences/PathJob.ui
+++ b/src/Mod/Path/Gui/Resources/preferences/PathJob.ui
@@ -142,8 +142,8 @@
0
0
- 424
- 537
+ 366
+ 330
@@ -348,8 +348,8 @@
0
0
- 407
- 570
+ 319
+ 528
@@ -655,6 +655,9 @@
-
+
+ <html><head/><body><p>Causes the toollibrary manager to remember last directory. This ONLY affects legacy tools. </p><p>This control will be deprecated and removed in future version</p></body></html>
+
Remember last library
diff --git a/src/Mod/Path/PathScripts/PathToolBitGui.py b/src/Mod/Path/PathScripts/PathToolBitGui.py
index 21a755f2ce..6daac0e5e0 100644
--- a/src/Mod/Path/PathScripts/PathToolBitGui.py
+++ b/src/Mod/Path/PathScripts/PathToolBitGui.py
@@ -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
diff --git a/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py b/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py
index a0a52f0de3..83417baec7 100644
--- a/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py
+++ b/src/Mod/Path/PathScripts/PathToolBitLibraryGui.py
@@ -38,6 +38,7 @@ import os
import glob
import uuid as UUID
from functools import partial
+import shutil
# PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule())
# PathLog.trackModule(PathLog.thisModule())
@@ -360,6 +361,9 @@ class ToolBitLibrary(object):
def __init__(self):
PathLog.track()
+ if not self.checkWorkingDir():
+ return
+
self.factory = ModelFactory()
self.temptool = None
self.toolModel = PySide.QtGui.QStandardItemModel(0, len(self.columnNames()))
@@ -371,6 +375,55 @@ class ToolBitLibrary(object):
self.setupUI()
self.title = self.form.windowTitle()
+ def checkWorkingDir(self):
+ # users shouldn't use the example toolbits and libraries.
+ # working directory should be writable
+ PathLog.track()
+
+ workingdir = os.path.dirname(PathPreferences.lastPathToolLibrary())
+ defaultdir = os.path.dirname(PathPreferences.pathDefaultToolsPath())
+
+ dirOK = lambda : workingdir != defaultdir and (os.access(workingdir, os.W_OK))
+
+ if dirOK():
+ return True
+
+ qm = PySide.QtGui.QMessageBox
+ ret = qm.question(None,'', "Please set up Toolbit Working Directory", qm.Ok | qm.Cancel)
+
+ if ret == qm.Cancel:
+ return False
+
+ msg = translate("Path", "Choose a writable location for your toolbits", None)
+ while not dirOK():
+ workingdir = PySide.QtGui.QFileDialog.getExistingDirectory(None, msg,
+ PathPreferences.filePath())
+
+ PathPreferences.setLastPathToolLibrary("{}/Library".format(workingdir))
+
+ subdirlist = ['Bit', 'Library', 'Shape']
+ mode = 0o777
+ for dir in subdirlist:
+ subdir = "{}/{}".format(workingdir, dir)
+ if not os.path.exists(subdir):
+ qm = PySide.QtGui.QMessageBox
+ ret = qm.question(None,'', "Toolbit Working directory {} should contain a '{}' subdirectory. Create it?".format(workingdir, dir), qm.Yes | qm.No)
+
+ if ret == qm.Yes:
+ os.mkdir(subdir, mode)
+ qm = PySide.QtGui.QMessageBox
+ ret = qm.question(None,'', "Copy example files to new {} directory?".format(dir), qm.Yes | qm.No)
+ if ret == qm.Yes:
+ src="{}/{}".format(defaultdir, dir)
+ src_files = os.listdir(src)
+ for file_name in src_files:
+ full_file_name = os.path.join(src, file_name)
+ if os.path.isfile(full_file_name):
+ shutil.copy(full_file_name, subdir)
+
+ return True
+
+
def toolBitNew(self):
PathLog.track()